Chat Completions API
Endpoint: POST /v1/chat/completions
テキストモデルには Chat Completions エンドポイントを使用します。非ストリーミングリクエストは 1 つの JSON レスポンスを返し、stream: true を指定すると [DONE] で終わる Server-Sent Events を返します。
Authentication
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
同じ HiAPI API キーで、アカウントで有効になっているすべてのモデルを呼び出せます。テキストモデルは /v1/chat/completions を使用し、画像、動画、音声モデルは input オブジェクトと非同期タスクライフサイクルを伴う /v1/tasks を使用します。
Request
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Explain sparse attention."}],
"stream": false
}'
必須フィールドは model と messages です。一般的な任意フィールドには stream、max_tokens、thinking、reasoning_effort、response_format、tools がありますが、サポート状況はモデルによって異なる場合があります。
Response and usage
最終的な回答は choices[0].message.content から読み取ります。Thinking モデルは choices[0].message.reasoning_content も返すことがあります。usage オブジェクトは、課金に使用されるプロンプト、補完、キャッシュ済み入力、合計の Token 数を報告します。
Streaming
stream: true を設定し、各 data: イベントを JSON としてパースし、data: [DONE] の後に停止します。choices[0].delta.content を蓄積します。Thinking モデルは choices[0].delta.reasoning_content を出力することがあります。
Errors
401: API キーが欠落しているか無効です。402: 残高が不足しています。400: サポートされていないモデルまたは無効なパラメータです。429: レート制限に達しました。503: モデルが一時的に利用できません。上限付きの指数バックオフで再試行してください。
モデル固有のフィールドについては Claude Sonnet 4.6、Kimi K3、DeepSeek V4 Flash を、現在の Token 料金については live pricing を参照してください。
Responses と Chat Completions の契約、low/high/max の Chat reasoning、ステートレスな Responses 会話については DeepSeek V4.1 Flash を参照してください。