This document describes how to call the Kimi model inference service deployed on Alibaba Cloud Model Studio.
kimi-k3.1-pro supports OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and the DashScope native API.
The service endpoint varies by region. Configure the Base URL based on the region you select.
- OpenAI compatible
- DashScope
- Anthropic-compatible
base_url for each region below also applies to OpenAI Responses; the HTTP request URL appends /responses to the base_url, that is, POST {base_url}/responses.- Singapore
- United States (Virginia)
- Germany (Frankfurt)
- North China 2 (Beijing)
- Japan (Tokyo)
- Hong Kong (China)
base_url configured for SDK calls: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1HTTP request URL: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions{WorkspaceId} with your actual Workspace ID.
You must have obtained and configured an API Key and configured the API Key as an environment variable. If you call through an SDK, you need to install the SDK.
QuickStart
The following is a plain-text input example. For multimodal examples, see multimodal invocation examples.
- OpenAI compatible
- DashScope
- Anthropic-compatible
- Python
- Node.js
- HTTP
Response
Multimodal invocation examples
kimi-k3.1-pro, kimi-k3, kimi-k2.7-code, kimi-k2.6, and kimi-k2.5 support multimodal input and text output. Among them, kimi-k3.1-pro and kimi-k3 only support text and image input and do not support video input; kimi-k2.7-code, kimi-k2.6, and kimi-k2.5 can process text, image, or video input at the same time. You can enable thinking mode through the enable_thinking parameter. The following examples show how to invoke multimodal capabilities.
Enable or disable thinking mode
kimi-k2.6 and kimi-k2.5 are hybrid thinking models: they can respond after thinking or respond directly. Use the enable_thinking parameter to control whether thinking mode is enabled:
true: enable thinking modefalse(default): disable thinking mode
enable_thinking defaults to true and cannot be disabled); preserve_thinking defaults to true.
kimi-k3.1-pro and kimi-k3 enable thinking by default (enable_thinking=true). You can set it to false to disable thinking, but keeping it enabled is recommended. Disabling thinking on kimi-k3.1-pro significantly degrades output quality, so keeping it enabled is strongly recommended. Both models retain the historical reasoning_content passed in by the client by default; in multi-turn requests, it is recommended to pass back the full reasoning_content of historical assistant messages.
kimi-k2.6 supports passing the thinking process across multi-turn conversations through the preserve_thinking parameter. For details, see Passing the thinking process.
The following example shows how to use an image URL and enable thinking mode, supporting single-image input (the main example) and multi-image input (the commented-out code).
- OpenAI compatible
- DashScope
Video Understanding
- Video file
- Image list
-
fps: controls the frame extraction frequency, extracting one frame every
1/fpsseconds. The value range is [0.1, 10], and the default value is 2.0.- High-speed motion scenarios: a higher fps value is recommended to capture more details
- Static scenes or long videos: a lower fps value is recommended to improve processing efficiency
- max_frames: limits the maximum number of frames extracted from a video; the default and maximum values are both 2000. When the total number of frames calculated by fps exceeds this limit, the system automatically samples frames evenly within max_frames. This parameter is available only when using the DashScope SDK.
- OpenAI compatible
- DashScope
When you directly input a video file to the model using the OpenAI SDK or HTTP, set the"type"parameter in the user message to"video_url".
Pass in local files
The following examples show how to pass in local files. The OpenAI-compatible interface supports only Base64 encoding, while DashScope supports both Base64 encoding and file paths.
- OpenAI compatible
- DashScope
File limits
- Image limits
- Video limits
-
Image resolution:
- Minimum size: both the width and height of the image must be greater than
10pixels. - Aspect ratio: the ratio of the long side to the short side of the image must not exceed
200:1. - Pixel limit: we recommend keeping the image resolution within
8K(7680x4320). Images above this resolution may cause API call timeouts due to oversized files or lengthy network transfers.
- Minimum size: both the width and height of the image must be greater than
-
Supported image formats
-
For resolutions below 4K
(3840x2160), the supported image formats are as follows:Image format
Common extensions
MIME Type
BMP
.bmp
image/bmp
JPEG
.jpe, .jpeg, .jpg
image/jpeg
PNG
.png
image/png
TIFF
.tif, .tiff
image/tiff
WEBP
.webp
image/webp
HEIC
.heic
image/heic
-
For resolutions from
4K(3840x2160)to8K(7680x4320), only the JPEG, JPG, and PNG formats are supported.
-
For resolutions below 4K
-
Image size:
- When passing via public URL or local path: each image must be no larger than
10MB. - When passing via Base64 encoding: the encoded string must be no larger than
10MB.
To compress files, see How to compress an image or video to meet the size requirements.
- When passing via public URL or local path: each image must be no larger than
- Number of images that can be passed: when passing multiple images, the number of images is limited by the model's maximum input; the total number of tokens of all images and text must be less than the model's maximum input.
Other features
Model | |||||||
|---|---|---|---|---|---|---|---|
kimi-k3.1-pro | Supported | Supported | Supported | Supported (JSON Mode) | Supported | Not supported | Supported (implicit cache) |
kimi-k3 | Supported | Supported | Supported | Supported | Supported (Responses API) | Supported | Supported |
kimi-k2.7-code | Supported | Supported | Supported | Not supported | Not supported | Not supported | Supported |
kimi-k2.6 | Supported | Supported | Supported | Not supported | Not supported | Not supported | Supported |
kimi-k2.5 | Supported | Supported | Supported | Not supported | Not supported | Not supported | Supported |
Dynamically Loaded Tools
When an application needs to mount a large number of tools, putting all tool declarations into the request's top-level tools field at once leads to the Tool Definition Bloat problem: every request must carry the descriptions and parameter schemas of all tools, resulting in high token consumption; the more candidate tools there are, the more likely the model is to pick the wrong tool and construct incorrect call parameters.
Dynamically Loaded Tools allow tools to be injected on demand during a conversation: mount only a few core tools first, and when the conversation progresses to the point where a specific tool is needed, dynamically insert it into messages, thereby reducing token consumption and improving the accuracy of tool selection.
tokenization failed error.The format and examples in this section for injecting tools into messages via the tools field of the system message (system.tools) apply to the OpenAI Chat Completions API.Injecting tool declarations into messages
Insert a message with role set to system into messages, and declare the tools to load via the tools field of that message. The declaration format is exactly the same as that of the request's top-level tools field, and complete tool information (name, description, parameters) must be provided.
- A
systemmessage carryingtoolshas the same standing as an ordinary message: wherever it appears in themessageslist is where the tools become visible to the model. - Dynamically loaded tools coexist with global tools declared in the request's top-level
toolsfield, and the model can see both types of tools at the same time. - A dynamically injected tool declaration must be a complete tool definition; you cannot pass only a tool name or reference a tool already declared globally.
- A
systemmessage carryingtoolscannot also carry acontentfield; otherwise the request fails with a 400 error. When using the OpenAI SDK, you can pass thetoolsfield through directly inmessages.
On-demand loading with a search tool
There is no dedicated tool search API at the API level. If you have a large number of tools, you can combine a "custom search tool + dynamically loaded tools" approach to achieve on-demand loading:
- At the start of a session, declare in the request's top-level
toolsonly asearch_toolstool implemented by your application backend (which returns matching tool names and brief descriptions by keyword), plus a small number of core tools that may be needed in every turn. - Declare searchable keywords in the System Prompt (for example, a tool catalog or domain tags) to guide the model to call
search_toolsfirst when it needs a tool. Settingtool_choice: "required"on the first request only guarantees that the model calls at least one tool, not that it callssearch_toolsfirst. If searching must come first, explicitly settool_choice: {"type": "function", "function": {"name": "search_tools"}}, and restoretool_choiceto"auto"once retrieval is complete. Modifyingtool_choicedoes not break the prefix cache. - Based on the results returned by
search_tools, the application dynamically inserts the complete declarations of the corresponding tools intomessagesvia asystemmessage carryingtools. - The model can then directly call these newly loaded tools in subsequent generation.
Notes
- Dynamic tool declarations take effect per request and are not remembered by the server. Whether to keep including them in subsequent requests is up to the integrator: if you keep including them, the tools remain available, which also helps hit the prefix cache; if you stop including them, the tool declarations become invalid — if the tools are not declared elsewhere, the model will no longer be able to call them, and the prefix cache after the changed position may no longer be hit.
- Appending dynamic tool declarations at the end of
messagesdoes not affect the cache of the existing prefix; deleting or modifying previous tool declarations may affect cache hits after the changed position. Declaring global tools in the request's top-leveltoolsfield likewise does not affect cache hits. - A
systemmessage carryingtoolsalso consumes context length, so only dynamically inject tools that the current conversation truly needs. - Dynamic tool declarations and global
toolsdeclarations share exactly the same format, so integrators do not need to maintain two sets of schemas.
Default parameter values
Model | enable_thinking | temperature | top_p | presence_penalty | fps | max_frames |
|---|---|---|---|---|---|---|
kimi-k3.1-pro | true (can be disabled; keeping it enabled is strongly recommended) | 1.0 | 0.95 | 0.0 | - | - |
kimi-k3 | true (can be disabled; keeping it enabled is recommended) | 1.0 | 0.95 | 0.0 | - | - |
kimi-k2.7-code | true (thinking mode only; cannot be disabled) | 1.0 | 0.95 | 0.0 | 2 | 2000 |
kimi-k2.6 | false | Thinking mode: 1.0 Non-thinking mode: 0.6 | Thinking/non-thinking mode: 0.95 | Thinking/non-thinking mode: 0.0 | 2 | 2000 |
kimi-k2.5 | false | Thinking mode: 1.0 Non-thinking mode: 0.6 | Thinking/non-thinking mode: 0.95 | Thinking/non-thinking mode: 0.0 | 2 | 2000 |
temperature=1.0, top_p=0.95, presence_penalty=0.0. The temperature and top_p of kimi-k3 are fixed values: temperature=1.0, top_p=0.95. Passing any non-default value for these parameters will cause an error.
The following reasoning effort levels apply only to kimi-k3.1-pro, with the default value max:
max(default): deep reasoninghigh: enhanced reasoningmedium: medium reasoninglow: light reasoning
- OpenAI Chat Completions: the top-level
reasoning_effortin the request; when using the OpenAI Python SDK, passreasoning_effort="max"directly. - DashScope: the SDK uses the
reasoning_effortparameter, and HTTP requests useparameters.reasoning_effort. - OpenAI Responses: uses
reasoning.effort. - Anthropic Messages: uses
output_config.effort.
Model list and billing
The Kimi series models are large language models developed by Moonshot AI.
- kimi-k3.1-pro: Supports text and image input, text output, and dynamic tool loading; does not support video input, Batch, or fine-tuning.
- kimi-k3: Kimi's flagship model, which performs reasoning by default and adopts reserved thinking. Supports text and image input (video input not yet supported), conversation and Agent tasks, and dynamic tool loading.
- kimi-k2.7-code: Kimi's coding model, with more reliable long-context instruction following and a higher success rate on coding tasks. Supports text, image, and video input; thinking mode; and conversation and Agent tasks.
- kimi-k2.6: A Kimi model with stronger and more stable long-range coding capabilities, and significantly improved instruction following and self-correction. Also supports text, image, and video input; thinking and non-thinking modes; and conversation and Agent tasks.
- kimi-k2.5: Achieves open-source SOTA performance on Agent, code generation, visual understanding, and a range of general intelligence tasks. Also supports image, video, and text input; thinking and non-thinking modes; and conversation and Agent tasks.
thinking_budget parameter; the thinking length cannot be limited via this parameter.For pricing information, see Model invocation billing.For model context length and pricing information, see the Model Studio console. Billing is based on the number of input and output tokens processed by the model.
In thinking mode, the chain of thought is billed as output tokens.