チャット補完
POST /v1/chat/completions指定した会話に対してモデル応答を生成します。OpenAI Chat Completions API と完全互換です。
リクエストボディ
Section titled “リクエストボディ”| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル ID (モデル を参照) |
messages | array | はい | 会話メッセージ (メッセージタイプ を参照) |
stream | boolean | いいえ | SSE で部分デルタをストリーミング。デフォルト: false |
stream_options | object | いいえ | { "include_usage": true } で最終ストリームイベントにトークン数を含める |
temperature | number | いいえ | サンプリング温度 (0〜2)。デフォルトはモデル依存 |
top_p | number | いいえ | Nucleus サンプリングの閾値 (0〜1) |
n | integer | いいえ | 生成する選択肢の数 (1〜128) |
max_tokens | integer | いいえ | 生成する最大トークン数 (非推奨 — max_completion_tokens を使用) |
max_completion_tokens | integer | いいえ | 推論トークンを含む生成トークン数の上限 |
stop | string | string[] | いいえ | 最大 4 つの停止シーケンス |
frequency_penalty | number | いいえ | 頻度ペナルティ (-2〜2) |
presence_penalty | number | いいえ | 出現ペナルティ (-2〜2) |
logprobs | boolean | いいえ | 出力トークンの対数確率を返す |
top_logprobs | integer | いいえ | 位置ごとに最も可能性の高いトークン数 (0〜20) |
logit_bias | object | いいえ | トークン ID からバイアス値 (-100〜100) へのマップ |
response_format | object | いいえ | { "type": "text" }、{ "type": "json_object" }、または { "type": "json_schema", "json_schema": {...} } |
seed | integer | いいえ | 決定論的サンプリングのためのシード |
tools | array | いいえ | モデルが呼び出し可能な関数ツール |
tool_choice | string | object | いいえ | "none"、"auto"、"required"、または特定のツール |
parallel_tool_calls | boolean | いいえ | 並列関数呼び出しを許可 |
reasoning_effort | string | いいえ | モデルごとに異なります。GET /v1/models の reasoning_efforts を参照してください。モデルが受け付けない値は拒否されます |
top_k | integer | いいえ | Top-k サンプリング (プロバイダ依存) |
min_p | number | いいえ | Min-p サンプリングの閾値 (0〜1、プロバイダ依存) |
repetition_penalty | number | いいえ | 繰り返しペナルティ (プロバイダ依存) |
user | string | いいえ | 不正利用追跡用のエンドユーザー識別子 |
メッセージタイプ
Section titled “メッセージタイプ”システムメッセージ
Section titled “システムメッセージ”{ "role": "system", "content": "You are a helpful assistant." }ユーザーメッセージ
Section titled “ユーザーメッセージ”{ "role": "user", "content": "What is the capital of France?" }ユーザーメッセージはマルチモーダルなコンテンツ配列も受け付けます:
{ "role": "user", "content": [ { "type": "text", "text": "What's in this image?" }, { "type": "image_url", "image_url": { "url": "https://...", "detail": "auto" } } ]}対応するコンテンツタイプ: text、image_url、video_url、audio_url、input_audio、file。
画像については、インラインの base64 ではなく Files API でアップロードして file_id で参照することを推奨します。マルチターンの会話やリトライ時に、クライアントからバイト列を再送する必要がなくなります:
{ "role": "user", "content": [ { "type": "text", "text": "What's in this image?" }, { "type": "file", "file": { "file_id": "file-abc123" } } ]}モデルは対応する capability (例: vision) を持つ必要があります。持たない場合、リクエストは 400 model_capability_mismatch で拒否されます。
アシスタントメッセージ
Section titled “アシスタントメッセージ”{ "role": "assistant", "content": "The capital of France is Paris." }ツールメッセージ
Section titled “ツールメッセージ”{ "role": "tool", "tool_call_id": "call_abc123", "content": "{\"result\": 42}" }{ "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1700000000, "model": "deepseek-ai/deepseek-v4-flash", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello! How can I help you today?" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 9, "total_tokens": 19 }}使用量 (usage)
Section titled “使用量 (usage)”| フィールド | 型 | 説明 |
|---|---|---|
prompt_tokens | integer | 入力で消費したトークン数 |
completion_tokens | integer | 生成された出力トークン数 |
total_tokens | integer | 入力と出力の合計 |
prompt_tokens_details | object | 任意。{ cached_tokens, audio_tokens } |
completion_tokens_details | object | 任意。{ reasoning_tokens, audio_tokens } |
ストリーミング
Section titled “ストリーミング”stream: true を指定すると、Server-Sent Events として部分的な応答を受け取れます。
curl https://api.aiand.com/v1/chat/completions \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-ai/deepseek-v4-flash", "stream": true, "messages": [{"role": "user", "content": "Count to 5"}] }'各イベントは JSON チャンクを含む data: 行で構成されます。ストリームは data: [DONE] で終了します。
最終イベントにトークン使用量を含めるには:
{ "stream": true, "stream_options": { "include_usage": true }}ツール呼び出し
Section titled “ツール呼び出し”リクエストでツールを定義すると、モデルがそれらを呼び出すかを選択できます:
{ "model": "deepseek-ai/deepseek-v4-flash", "messages": [{ "role": "user", "content": "What's the weather in Tokyo?" }], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string" } }, "required": ["location"] } } } ]}モデルがツールを呼び出すと、レスポンスには tool_calls が含まれます:
{ "choices": [ { "message": { "role": "assistant", "tool_calls": [ { "id": "call_abc123", "type": "function", "function": { "name": "get_weather", "arguments": "{\"location\": \"Tokyo\"}" } } ] }, "finish_reason": "tool_calls" } ]}実行結果は tool メッセージとして返送し、会話を継続します。