チャット補完
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
POST
https://test.kailin.com.cn/v1/chat/completionsResponseRESPONSE
Fill in the request and hit Send — the response shows up here
リクエストボディ
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル名。List Models を参照 |
messages | array | はい | 会話メッセージ。下記のメッセージ構造を参照 |
stream | boolean | いいえ | ストリーム出力(SSE)、デフォルトは false |
temperature | number | いいえ | サンプリング温度 0–2、デフォルトは 1 — 低いほど決定的 |
top_p | number | いいえ | Nucleus サンプリング。temperature とどちらか一方だけ調整する |
max_tokens | number | いいえ | 生成する最大トークン数(新しいモデルでは max_completion_tokens を使用) |
stop | string / array | いいえ | 終了シーケンス、最大 4 つ |
tools | array | いいえ | ツール(関数)の定義。ツール呼び出しを参照 |
tool_choice | string / object | いいえ | auto / none / required / 特定のツール |
response_format | object | いいえ | {"type": "json_object"} または {"type": "json_schema", ...} |
seed | integer | いいえ | 再現性のためのランダムシード |
frequency_penalty | number | いいえ | -2.0–2.0、繰り返しを抑制 |
presence_penalty | number | いいえ | -2.0–2.0、新しい話題を促進 |
reasoning_effort | string | いいえ | 推論モデルの推論力度:low / medium / high |
user | string | いいえ | エンドユーザーの識別子。不正利用の監視に便利 |
メッセージ構造
| フィールド | 型 | 説明 |
|---|---|---|
role | string | system / user / assistant / tool |
content | string / array | 文字列、またはマルチモーダルパートの配列(マルチモーダル入力を参照) |
name | string | 任意の参加者名 |
tool_calls | array | モデルが開始したツール呼び出し。assistant メッセージに付く |
tool_call_id | string | tool メッセージでは必須 — 応答対象の呼び出し |
レスポンス(非ストリーミング)
{
"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_reason | stop 完了 / 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"
}
}
]
}
]
}
| コンテンツパート | フィールド | 説明 |
|---|---|---|
text | text | テキスト |
image_url | image_url.url | 画像 URL または data:image/jpeg;base64,... |
input_audio | input_audio.data / input_audio.format | Base64 音声(wav / mp3)、モデルの対応が必要 |
ツール呼び出し
toolsでツールを宣言すると、モデルがtool_callsで応答します。- ツールを実行し、その結果を
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 に思考プロセスを返す場合があります。