コンテンツにスキップ

補完 (レガシー)

POST /v1/completions

指定したプロンプトに対してテキスト補完を生成します。OpenAI Completions API と互換です。

パラメータ型必須説明
modelstringはいモデル ID (モデル を参照)
promptstring | string[]はい補完を生成する対象のプロンプト
streambooleanいいえSSE で部分デルタをストリーミング。デフォルト: false
stream_optionsobjectいいえ{ "include_usage": true } で最終ストリームイベントにトークン数を含める
temperaturenumberいいえサンプリング温度 (0〜2)
top_pnumberいいえNucleus サンプリングの閾値 (0〜1)
nintegerいいえ生成する補完の数 (1〜128)
max_tokensintegerいいえ生成する最大トークン数
stopstring | string[]いいえ最大 4 つの停止シーケンス
frequency_penaltynumberいいえ頻度ペナルティ (-2〜2)
presence_penaltynumberいいえ出現ペナルティ (-2〜2)
logprobsintegerいいえ最も可能性の高いトークンの対数確率を含める (0〜5)
echobooleanいいえ補完に加えてプロンプトも返す
best_ofintegerいいえbest_of 個の補完を生成し、最良のものを返す。stream と併用不可
suffixstringいいえ補完の後ろに続くサフィックス
seedintegerいいえ決定論的サンプリングのためのシード
userstringいいえ不正利用追跡用のエンドユーザー識別子
{
"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
}
}
フィールド型説明
idstring補完の一意 ID
objectstring常に "text_completion"
createdintegerUnix タイムスタンプ
modelstring使用されたモデル
choicesarray補完候補
choices[].textstring生成されたテキスト
choices[].indexinteger候補のインデックス
choices[].logprobsobject | nullリクエストした場合の対数確率情報
choices[].finish_reasonstring"stop" または "length"
usageobjectトークン使用量の統計
Terminal window
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
}'

stream: true を指定すると、Server-Sent Events として部分的な補完を受け取れます。

Terminal window
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] で終了します。