# Grok 4.6 API xAI が提供する Grok 4.6 LLM モデルの完全な API リファレンスです。 ## モデルバリエーション この API は、2 つの Grok 4.6 モデルバリエーションをサポートしています。 | モデル | ID | 説明 | |-------|----|-------------| | **Grok 4.6 Text to Text** | `grok-4.6-text-to-text` | 最新の Grok テキスト推論と生成 | | **Grok 4.6 Image to Text** | `grok-4.6-image-to-text` | 最新の Grok 画像理解と分析 | ## クイック比較 | 機能 | テキストからテキスト | 画像からテキスト | |---------|--------------|---------------| | テキスト入力 | 必須 ✅ | 任意 | | 画像入力 | 非対応 ❌ | 任意 | | ファイル入力 | 非対応 ❌ | 非対応 ❌ | | ストリーミングレスポンス | SSE | SSE | | `max_tokens` | 任意 | 任意 | ## Grok 4.6 Text to Text ### エンドポイント ```http POST /api/v1/chat/completions ``` ### リクエストパラメータ #### 必須 | パラメータ | 型 | 説明 | |-----------|------|-------------| | `model` | string | `"grok-4.6-text-to-text"` である必要があります | | `messages` | array | 順序付きメッセージ。メッセージ構造については LLM API を参照してください。 | | `stream` | boolean | SSE の場合は `true`、単一の JSON レスポンスの場合は `false`。 | #### メッセージ対応 | フィールド | テキスト | ファイル | 画像 | |-------|------|------|-------| | `messages` | 必須 ✅ | 非対応 ❌ | 非対応 ❌ | #### 任意 | パラメータ | 型 | 範囲 | 説明 | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 1` | 最大出力トークン数。 | ### リクエスト例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'grok-4.6-text-to-text', messages: [ { role: 'user', content: 'Explain the key differences between REST and GraphQL APIs.' } ], stream: true, max_tokens: 2048 }) }); ``` ## Grok 4.6 Image to Text ### エンドポイント ```http POST /api/v1/chat/completions ``` ### リクエストパラメータ #### 必須 | パラメータ | 型 | 説明 | |-----------|------|-------------| | `model` | string | `"grok-4.6-image-to-text"` である必要があります | | `messages` | array | 順序付きメッセージ。LLM API とメッセージ添付を参照してください。 | | `stream` | boolean | SSE の場合は `true`、単一の JSON レスポンスの場合は `false`。 | #### メッセージ対応 | フィールド | テキスト | ファイル | 画像 | |-------|------|------|-------| | `messages` | 任意 | 非対応 ❌ | 任意 | #### 任意 | パラメータ | 型 | 範囲 | 説明 | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 1` | 最大出力トークン数。 | ### リクエスト例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'grok-4.6-image-to-text', messages: [ { role: 'user', content: [ { type: 'text', text: 'Describe the image and extract any visible text.' }, { type: 'image_url', image_url: { url: 'https://example.com/sample-image.jpg' } } ] } ], stream: true, max_tokens: 2048 }) }); ``` ## レスポンス形式 Grok 4.6 LLM モデルは、OpenAI 互換の補完レスポンスを返します。`stream: true` の場合、レスポンスは Server-Sent Events となり、`stream: false` の場合は単一の JSON オブジェクトとなります。 ### 成功レスポンス ```text data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.6-text-to-text","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.6-text-to-text","choices":[{"index":0,"delta":{"content":"Here is a concise explanation"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.6-text-to-text","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.6-text-to-text","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}} data: [DONE] ``` ### エラーレスポンス ```text event: error data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}} ``` ## ベストプラクティス 1. **構造化メッセージを使用する:** コンテキストを 1 つのプロンプトにまとめるのではなく、`messages[]` を通じて会話履歴を送信します。 2. **適切なモデルバリエーションを選択する:** テキストのみの推論には Text to Text を、画像理解が必要な場合は Image to Text を使用します。 3. **SSE イベントを処理する:** ストリーミング表示では `choices[0].delta.content` を追加し、`data: [DONE]` を正常完了として扱います。 4. **対応する入力のみを送信する:** Text to Text は画像またはファイルの添付をサポートしていません。