補完 (レガシー)
POST /v1/completions指定したプロンプトに対してテキスト補完を生成します。OpenAI Completions API と互換です。
リクエストボディ
Section titled “リクエストボディ”| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル ID (モデル を参照) |
prompt | string | string[] | はい | 補完を生成する対象のプロンプト |
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 | いいえ | 生成する最大トークン数 |
stop | string | string[] | いいえ | 最大 4 つの停止シーケンス |
frequency_penalty | number | いいえ | 頻度ペナルティ (-2〜2) |
presence_penalty | number | いいえ | 出現ペナルティ (-2〜2) |
logprobs | integer | いいえ | 最も可能性の高いトークンの対数確率を含める (0〜5) |
echo | boolean | いいえ | 補完に加えてプロンプトも返す |
best_of | integer | いいえ | best_of 個の補完を生成し、最良のものを返す。stream と併用不可 |
suffix | string | いいえ | 補完の後ろに続くサフィックス |
seed | integer | いいえ | 決定論的サンプリングのためのシード |
user | string | いいえ | 不正利用追跡用のエンドユーザー識別子 |
{ "id": "cmpl-abc123", "object": "text_completion", "created": 1700000000, "model": "deepseek-ai/deepseek-v4-flash", "choices": [ { "text": "Hello! How can I help you?", "index": 0, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 5, "completion_tokens": 7, "total_tokens": 12 }}| フィールド | 型 | 説明 |
|---|---|---|
id | string | 補完の一意 ID |
object | string | 常に "text_completion" |
created | integer | Unix タイムスタンプ |
model | string | 使用されたモデル |
choices | array | 補完候補 |
choices[].text | string | 生成されたテキスト |
choices[].index | integer | 候補のインデックス |
choices[].logprobs | object | null | リクエストした場合の対数確率情報 |
choices[].finish_reason | string | "stop" または "length" |
usage | object | トークン使用量の統計 |
curl https://api.aiand.com/v1/completions \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-ai/deepseek-v4-flash", "prompt": "Write a haiku about programming:", "max_tokens": 30 }'ストリーミング
Section titled “ストリーミング”stream: true を指定すると、Server-Sent Events として部分的な補完を受け取れます。
curl https://api.aiand.com/v1/completions \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-ai/deepseek-v4-flash", "prompt": "Once upon a time", "max_tokens": 50, "stream": true }'各イベントは JSON チャンクを含む data: 行で構成されます。ストリームは data: [DONE] で終了します。