メインコンテンツへスキップ

チャット補完

POST /v1/chat/completions

OpenAI Chat Completions 形式と互換のコアな会話エンドポイントです。マルチモーダル入力、ストリーミング、ツール呼び出し、推論モデルに対応しています。

リクエスト​

curl https://test.kailin.com.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "deepseek-v4-1-flash-261017",
"messages": [
{ "role": "system", "content": "You are a concise assistant" },
{ "role": "user", "content": "Hello" }
],
"stream": false
}'
RequestREQUEST
POSThttps://test.kailin.com.cn/v1/chat/completions
ResponseRESPONSE
Fill in the request and hit Send — the response shows up here

リクエストボディ​

パラメーター型必須説明
modelstringはいモデル名。List Models を参照
messagesarrayはい会話メッセージ。下記のメッセージ構造を参照
streambooleanいいえストリーム出力(SSE)、デフォルトは false
temperaturenumberいいえサンプリング温度 0–2、デフォルトは 1 — 低いほど決定的
top_pnumberいいえNucleus サンプリング。temperature とどちらか一方だけ調整する
max_tokensnumberいいえ生成する最大トークン数(新しいモデルでは max_completion_tokens を使用)
stopstring / arrayいいえ終了シーケンス、最大 4 つ
toolsarrayいいえツール(関数)の定義。ツール呼び出しを参照
tool_choicestring / objectいいえauto / none / required / 特定のツール
response_formatobjectいいえ{"type": "json_object"} または {"type": "json_schema", ...}
seedintegerいいえ再現性のためのランダムシード
frequency_penaltynumberいいえ-2.0–2.0、繰り返しを抑制
presence_penaltynumberいいえ-2.0–2.0、新しい話題を促進
reasoning_effortstringいいえ推論モデルの推論力度:low / medium / high
userstringいいえエンドユーザーの識別子。不正利用の監視に便利

メッセージ構造​

フィールド型説明
rolestringsystem / user / assistant / tool
contentstring / array文字列、またはマルチモーダルパートの配列(マルチモーダル入力を参照)
namestring任意の参加者名
tool_callsarrayモデルが開始したツール呼び出し。assistant メッセージに付く
tool_call_idstringtool メッセージでは必須 — 応答対象の呼び出し

レスポンス(非ストリーミング)​

{
"id": "chatcmpl-B3xK1abc123",
"object": "chat.completion",
"created": 1730000000,
"model": "deepseek-v4-1-flash-261017",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 12,
"total_tokens": 32
}
}
フィールド説明
choices[].message.contentモデルの応答
choices[].finish_reasonstop 完了 / length トークン上限に到達 / tool_calls ツール実行が必要
usageトークン使用量 — 課金の基準
usage.completion_tokens_details.reasoning_tokens推論モデルが返す思考トークン

ストリーミングレスポンス​

"stream": true を指定すると、レスポンスは SSE イベントストリームになります:

data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

増分コンテンツは choices[].delta.content に届き、data: [DONE] で終了します。最後のチャンクには、上流に応じて usage が含まれる場合があります。

マルチモーダル入力​

content を配列として渡すと、テキストに画像/音声を混在できます。画像は URL または Base64 データ URL を受け付けます:

{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What's in this image?" },
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg"
}
}
]
}
]
}
コンテンツパートフィールド説明
texttextテキスト
image_urlimage_url.url画像 URL または data:image/jpeg;base64,...
input_audioinput_audio.data / input_audio.formatBase64 音声(wav / mp3)、モデルの対応が必要

ツール呼び出し​

  1. tools でツールを宣言すると、モデルが tool_calls で応答します。
  2. ツールを実行し、その結果を role: "tool" メッセージとして追加して、再度呼び出します。
{
"model": "deepseek-v4-1-flash-261017",
"messages": [{ "role": "user", "content": "What's the weather in Shanghai today?" }],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name" }
},
"required": ["city"]
}
}
}
]
}

モデルの応答:

{
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Shanghai\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}

実行後、結果を送り返します:

{
"model": "deepseek-v4-1-flash-261017",
"messages": [
{ "role": "user", "content": "What's the weather in Shanghai today?" },
{
"role": "assistant",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\": \"Shanghai\"}" }
}
]
},
{ "role": "tool", "tool_call_id": "call_abc123", "content": "Sunny, 26°C" }
]
}

SDK の利用​

from openai import OpenAI

client = OpenAI(
api_key="sk-your-token",
base_url="https://test.kailin.com.cn/v1",
)

stream = client.chat.completions.create(
model="deepseek-v4-1-flash-261017",
messages=[{"role": "user", "content": "Write a short poem about autumn"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="", flush=True)
import OpenAI from 'openai';

const client = new OpenAI({
apiKey: 'sk-your-token',
baseURL: 'https://test.kailin.com.cn/v1',
});

const stream = await client.chat.completions.create({
model: 'deepseek-v4-1-flash-261017',
messages: [{ role: 'user', content: 'Write a short poem about autumn' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
備考

推論モデル(o シリーズ、DeepSeek-R1 など)は、上流チャネルに応じて reasoning_content または delta.reasoning_content に思考プロセスを返す場合があります。