Chat Completions
The core conversation endpoint, compatible with the OpenAI Chat Completions format. Supports multimodal input, streaming, tool calling, and reasoning models.
Request
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
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name, see List Models |
messages | array | Yes | Conversation messages, see message structure below |
stream | boolean | No | Stream output (SSE), default false |
temperature | number | No | Sampling temperature 0–2, default 1 — lower is more deterministic |
top_p | number | No | Nucleus sampling; tune this or temperature, not both |
max_tokens | number | No | Max tokens to generate (newer models use max_completion_tokens) |
stop | string / array | No | Stop sequences, up to 4 |
tools | array | No | Tool (function) definitions, see tool calling |
tool_choice | string / object | No | auto / none / required / a specific tool |
response_format | object | No | {"type": "json_object"} or {"type": "json_schema", ...} |
seed | integer | No | Random seed for reproducibility |
frequency_penalty | number | No | -2.0–2.0, reduces repetition |
presence_penalty | number | No | -2.0–2.0, encourages new topics |
reasoning_effort | string | No | Reasoning effort for reasoning models: low / medium / high |
user | string | No | End-user identifier, useful for abuse monitoring |
Message Structure
| Field | Type | Description |
|---|---|---|
role | string | system / user / assistant / tool |
content | string / array | A string, or an array of multimodal parts (see multimodal input) |
name | string | Optional participant name |
tool_calls | array | Tool calls initiated by the model, on assistant messages |
tool_call_id | string | Required on tool messages — the call being responded to |
Response (Non-streaming)
{
"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
}
}
| Field | Description |
|---|---|
choices[].message.content | The model's reply |
choices[].finish_reason | stop completed / length hit token limit / tool_calls needs tool execution |
usage | Token usage — the billing basis |
usage.completion_tokens_details.reasoning_tokens | Thinking tokens returned by reasoning models |
Streaming Response
With "stream": true the response is an SSE event stream:
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]
Incremental content arrives in choices[].delta.content, ending with data: [DONE]. The final chunk may carry usage depending on the upstream.
Multimodal Input
Pass content as an array to mix text with images/audio. Images accept a URL or a Base64 data 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"
}
}
]
}
]
}
| Content Part | Fields | Description |
|---|---|---|
text | text | Text |
image_url | image_url.url | Image URL or data:image/jpeg;base64,... |
input_audio | input_audio.data / input_audio.format | Base64 audio (wav / mp3), model support required |
Tool Calling
- Declare tools via
tools; the model responds withtool_calls. - Execute the tools, append results as
role: "tool"messages, and call again.
{
"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"]
}
}
}
]
}
Model response:
{
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Shanghai\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}
After executing, send the result back:
{
"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" }
]
}
Using the 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 ?? '');
}
note
Reasoning models (o-series, DeepSeek-R1, etc.) may return the thinking process in reasoning_content or delta.reasoning_content, depending on the upstream channel.