🎉 Kimi K2.6 has been released with improved long-context coding stability.
curl --request POST \
--url https://api.moonshot.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "system",
"content": "<string>",
"name": null,
"partial": false
}
],
"model": "kimi-k2.6"
}
'{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Creates a completion for the chat message. Supports standard chat, Partial Mode, and Tool Use (Function Calling).
curl --request POST \
--url https://api.moonshot.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "system",
"content": "<string>",
"name": null,
"partial": false
}
],
"model": "kimi-k2.6"
}
'{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Create a chat completion request. The model generates a response based on the provided message list.Documentation Index
Fetch the complete documentation index at: https://platform.kimi.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Content Field Description
content field supports the following two forms:Plain text string"content": "Hello"
type field:"content": [
{ "type": "text", "text": "Describe this image" },
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,..." } },
{ "type": "video_url", "video_url": { "url": "data:video/mp4;base64,..." } }
]
image_url and video_url also support passing a string directly, equivalent to the url field in object form:{ "type": "image_url", "image_url": "data:image/png;base64,..." }
| Parameter | Required | Description | Type |
|---|---|---|---|
type | required | Content type | "text" | "image_url" | "video_url" |
text | required when type=text | Text content | string |
image_url | required when type=image_url | For transmitting images. Supports object form {"url": "..."} or a URL string directly | object | string |
video_url | required when type=video_url | For transmitting videos. Supports object form {"url": "..."} or a URL string directly | object | string |
image_url is passed as an object, its fields are:| Parameter | Required | Description | Type |
|---|---|---|---|
url | required | Image content specified via base64 encoding or file id | string |
video_url is passed as an object, its fields are:| Parameter | Required | Description | Type |
|---|---|---|---|
url | required | Video content specified via base64 encoding or file id, for example data:video/mp4;base64,... | string |
url field) and the string shorthand support the following formats:data:image/png;base64,... or data:video/mp4;base64,...ms://<file_id>import os
import base64
from openai import OpenAI
from openai.types.chat import ChatCompletion
client: OpenAI = OpenAI(
api_key=os.environ.get("MOONSHOT_API_KEY"),
base_url="https://api.moonshot.ai/v1",
)
# Encode the image to base64
with open("your_image_path", "rb") as f:
img_base: str = base64.b64encode(f.read()).decode("utf-8")
response: ChatCompletion = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{img_base}",
},
},
{
"type": "text",
"text": "Describe this image",
},
],
}
],
)
print(response.choices[0].message.content)
Response Format
{
"id": "cmpl-04ea926191a14749b7f2c7a48a68abc6",
"object": "chat.completion",
"created": 1698999496,
"model": "kimi-k2.6",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello, Li Lei! 1+1 equals 2. If you have any other questions, feel free to ask!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 21,
"total_tokens": 40,
"cached_tokens": 10
}
}
data: {"id":"cmpl-xxx","object":"chat.completion.chunk","created":1698999575,"model":"kimi-k2.6","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"cmpl-xxx","object":"chat.completion.chunk","created":1698999575,"model":"kimi-k2.6","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
...
data: {"id":"cmpl-xxx","object":"chat.completion.chunk","created":1698999575,"model":"kimi-k2.6","choices":[{"index":0,"delta":{},"finish_reason":"stop","usage":{"prompt_tokens":19,"completion_tokens":13,"total_tokens":32}}]}
data: [DONE]
kimi-k2.6 model, the "model" field in the response will show "kimi-k2.6".The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.
A list of messages in the conversation so far. Each element has the format {"role": "user", "content": "Hello"}. role supports system, user, or assistant. content must not be empty. The content field can be a string or an array[object] (for multimodal input).
Show child attributes
Model ID
kimi-k2.6 Deprecated, please refer to max_completion_tokens
The maximum number of tokens to generate for the chat completion. If not specified, defaults to a reasonable integer such as 1024. If the result reaches the maximum number of tokens without ending, the finish reason will be "length"; otherwise, it will be "stop". This refers to the length of tokens you expect us to return, not the total length of input plus output. If input plus max_completion_tokens exceeds the model context window, the API returns invalid_request_error.
Controls the model output format. Default is {"type": "text"} for plain text output. Set to {"type": "json_object"} to enable JSON mode, ensuring output is a valid JSON object (you must guide the model to output JSON in the prompt). Set to {"type": "json_schema"} to enable Structured Output, constraining output to match a specified JSON Schema (recommended, requires the json_schema field). If you encounter schema validation issues, please submit feedback at walle GitHub Issues (https://github.com/MoonshotAI/walle/issues).
Show child attributes
Stop words, which will halt the output when a full match is found. The matched words themselves will not be output. A maximum of 5 strings is allowed, and each string must not exceed 32 bytes
Whether to return the response in a streaming fashion. Default is false.
Options for streaming responses
Show child attributes
A list of tools the model may call
128Show child attributes
Used to cache responses for similar requests to optimize cache hit rates. For Coding Agents, this is typically a session id or task id representing a single session; if the session is exited and later resumed, this value should remain the same. For Kimi Code Plan, this field is required to improve cache hit rates. For other agents involving multi-turn conversations, it is also recommended to implement this field
A stable identifier used to help detect users of your application that may be violating usage policies. The ID should be a string that uniquely identifies each user. It is recommended to hash the username or email address to avoid sending any identifying information
Controls whether thinking is enabled for the kimi-k2.6 model, and whether to fully preserve reasoning_content across multi-turn conversations. Optional parameter. Default value is {"type": "enabled"}.
Show child attributes
Chat completion response
Unique identifier for the completion
Object type
"chat.completion"
Unix timestamp of when the completion was created
Model used for the completion
List of completion choices
Show child attributes
Show child attributes
Was this page helpful?