Kimi K3
Kimi K3 is available through the OpenAI-compatible Chat Completions API. It supports text and image input, reasoning content, streaming, and function calling.
Endpoint
POST /v1/chat/completionsModel
kimi-k3Actual availability and quota depend on your account permissions.
Basic Request
curl https://cubicspaces.cloud/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3",
"messages": [
{ "role": "system", "content": "You are a precise and concise technical assistant." },
{ "role": "user", "content": "List three principles for designing an idempotent API." }
],
"reasoning_effort": "high",
"max_tokens": 4096,
"stream": false
}'In a non-streaming response, the final answer is returned in choices[0].message.content. When reasoning content is present, it is returned in choices[0].message.reasoning_content.
Reasoning Effort
reasoning_effort accepts these values:
| Value | Description |
|---|---|
low | Shorter reasoning for simple tasks |
high | Deeper reasoning for complex analysis and coding |
max | Maximum reasoning effort and potentially longer output |
Do not use medium or any unlisted value. Unsupported values return HTTP 400.
Image Input
Place images in the user message's content array using the OpenAI image_url format. A publicly accessible HTTPS URL is recommended.
{
"model": "kimi-k3",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
},
{
"type": "text",
"text": "Describe this image and list its three most important details."
}
]
}
],
"reasoning_effort": "high",
"max_tokens": 4096
}Streaming
curl https://cubicspaces.cloud/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3",
"messages": [
{ "role": "user", "content": "Analyze the risks in this database migration plan." }
],
"reasoning_effort": "high",
"stream": true,
"stream_options": {
"include_usage": true
}
}'Streaming responses use SSE. Parse these fields separately:
choices[0].delta.reasoning_content: reasoning chunks.choices[0].delta.content: final-answer chunks.usage: returned near the end whenstream_options.include_usageis enabled.data: [DONE]: end-of-stream marker.
Function Calling
Tools must use the OpenAI Function Calling format. tools must be an array, and every tool must contain type: "function" and a complete function object.
{
"model": "kimi-k3",
"messages": [
{ "role": "user", "content": "Check the current weather in Tokyo." }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto",
"reasoning_effort": "high"
}Function names must follow these rules:
- No more than 64 characters.
- Only ASCII letters, numbers, underscores, and hyphens.
function.parametersmust be a JSON object.
After the model returns tool_calls, execute the tools and append their results to the message history:
{
"model": "kimi-k3",
"messages": [
{ "role": "user", "content": "Check the current weather in Tokyo." },
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Tokyo\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_1",
"content": "Sunny, 26°C"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
}
]
}Every role: "tool" message must use the exact tool_calls[].id returned by the preceding assistant message. Return a result for every tool call before sending the next regular message.
Python SDK
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1",
)
response = client.chat.completions.create(
model="kimi-k3",
messages=[
{"role": "user", "content": "Explain optimistic locking."}
],
reasoning_effort="high",
max_tokens=4096,
)
print(response.choices[0].message.content)Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Must be kimi-k3 |
messages | array | OpenAI Chat message array |
reasoning_effort | string | low, high, or max |
max_tokens | integer | Maximum output tokens; recommended for this model |
max_completion_tokens | integer | Maximum output tokens; accepted by some clients |
stream | boolean | Whether to stream the response |
stream_options | object | Streaming options such as include_usage |
tools | array | Function Calling tool definitions |
tool_choice | string/object | Tool selection policy |
The platform currently limits the requested output maximum to 65,536 tokens. Use a smaller practical value whenever possible.
Parameters to Omit
To avoid compatibility errors, do not add these fields to Kimi K3 requests:
temperaturetop_ptop_kpresence_penaltyfrequency_penaltyprompt_cache_keyprompt_cache_retention- A literal
extra_bodyfield in raw HTTP JSON - Legacy
functionsorfunction_call
The Python SDK does not require extra_body for Kimi K3. If another client provides an advanced field named Extra Body, do not place unknown extensions in it.
Common HTTP 400 Errors
| Symptom | Common cause | Resolution |
|---|---|---|
Unsupported reasoning_effort | medium or a custom value was used | Use low, high, or max |
tools[n].function.name error | Missing, overlong, or invalid function name | Follow the function-name rules above |
function.parameters must be a JSON object | The schema was sent as a string or array | Send a valid JSON object |
tool_call_id does not match | A tool result has no matching prior call | Reuse the original tool_calls[].id |
| All tool results must be returned first | Only some parallel tool calls received results | Append one role: "tool" message for every call |
Invalid messages or tools structure | Objects and arrays were mixed, or an item is incomplete | Compare the final JSON hierarchy with the examples above |
| JSON parsing error | Truncated payload or incorrect quote/backslash escaping | Validate the final HTTP request body with a JSON parser |
When troubleshooting, inspect the final HTTP JSON sent by the client, not only the SDK call. Proxies, plugins, and advanced client settings may add fields to the final payload.