Skip to main content

Kimi-Moonshot AI

This document describes how to call the model inference service directly provided by Moonshot AI on the Alibaba Cloud Model Studio platform.

This document applies only to the China (Beijing) region. To use the model, you must use an API key from the China (Beijing) region.

Activate the service

  1. Go to the Model Studio console, search for Kimi, find the Kimi model card, and click Activate Now.
  2. In the pop-up window, confirm the activation and authorization.
After you complete these steps, you can call the Moonshot AI Kimi model service.

Getting started

Prerequisites The kimi series models all support text, image, or video input:
  1. kimi/kimi-k2.7-code-highspeed and kimi/kimi-k2.7-code are identical in functionality, with a 5~6x speed improvement.
  2. kimi/kimi-k3, kimi/kimi-k2.7-code-highspeed, and kimi/kimi-k2.7-code are thinking-only models (enable_thinking is always true and cannot be set to false).
  3. For kimi/kimi-k2.6, you can use the enable_thinking parameter to control the thinking mode, which is enabled by default:
  • Thinking mode (reasoning_effort: "max"): The model outputs a detailed inference process (reasoning_content).
  • Non-thinking mode (enable_thinking: false or if the parameter is omitted): The model directly outputs the result without the inference process.
kimi/kimi-k3, kimi/kimi-k2.7-code-highspeed, kimi/kimi-k2.7-code, and kimi/kimi-k2.6 support using the preserve_thinking parameter to pass the thinking process in multi-turn conversations. For more information, see Multi-turn conversation. The following example shows how to call the kimi/kimi-k3 model in thinking mode to perform text generation.
  • OpenAI compatible
reasoning_effort is not a standard OpenAI parameter. For the OpenAI Python SDK, you can pass it in the extra_body parameter. For the Node.js SDK, you can pass it as a top-level parameter.
  • Python
  • Node.js
  • HTTP
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi/kimi-k3",
    messages=[{"role": "user", "content": "What is 1+1?"}],
    # Use extra_body to set reasoning_effort and enable thinking mode.
    extra_body={"reasoning_effort": "max"}
)

msg = completion.choices[0].message

if getattr(msg, "reasoning_content", None):
    print("\n" + "=" * 20 + "Reasoning Process" + "=" * 20 + "\n")
    print(msg.reasoning_content or "")
print("\n" + "=" * 20 + "Full Response" + "=" * 20 + "\n")
print(msg.content)

Response

====================Reasoning Process====================

The user asked a simple math question: "What is 1+1?"

This is a very basic arithmetic problem. The answer is 2.

I should answer this question directly and clearly. Although the user asked in Chinese, the answer is a universal mathematical fact.

Answer structure:
1. Directly provide the answer: 2
2. Briefly explain that this is a basic arithmetic operation.

No need to overcomplicate. Keep it simple and clear.

====================Full Response====================

1+1 equals **2**.

This is the most basic arithmetic operation, where adding two units results in two units.

Multimodal call examples

In addition to plain text conversations, kimi/kimi-k3, kimi/kimi-k2.7-code-highspeed, kimi/kimi-k2.7-code, and kimi/kimi-k2.6 have powerful multimodal understanding capabilities. This section describes how to use the model to understand image and video content.
Image and video files can be provided only using public network URLs. Base64 encoding is not supported.

Image understanding

The image understanding feature allows the Kimi model to recognize and analyze image content. You can provide one or more images. For more information about limitations on image files, see Image limitations.
  • OpenAI compatible
  • Python
  • Node.js
  • HTTP
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

# Single-image input example (thinking mode enabled)
completion = client.chat.completions.create(
    model="kimi/kimi-k3",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What scene is depicted in the image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
                    }
                }
            ]
        }
    ],
    extra_body={"reasoning_effort":"max"}  # Enable thinking mode
)

# Output the reasoning process
if hasattr(completion.choices[0].message, 'reasoning_content') and completion.choices[0].message.reasoning_content:
    print("\n" + "=" * 20 + "Reasoning Process" + "=" * 20 + "\n")
    print(completion.choices[0].message.reasoning_content)

# Output the response content
print("\n" + "=" * 20 + "Full Response" + "=" * 20 + "\n")
print(completion.choices[0].message.content)

# Multi-image input example (thinking mode enabled, uncomment to use)
# completion = client.chat.completions.create(
#     model="kimi/kimi-k3",
#     messages=[
#         {
#             "role": "user",
#             "content": [
#                 {"type": "text", "text": "What content do these images depict?"},
#                 {
#                     "type": "image_url",
#                     "image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}
#                 },
#                 {
#                     "type": "image_url",
#                     "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"}
#                 }
#             ]
#         }
#     ],
#     extra_body={"reasoning_effort":"max"}
# )
#
# # Output the reasoning process and response
# if hasattr(completion.choices[0].message, 'reasoning_content') and completion.choices[0].message.reasoning_content:
#     print("\nReasoning Process:\n" + completion.choices[0].message.reasoning_content)
# print("\nFull Response:\n" + completion.choices[0].message.content)

Video understanding

For more information about limitations on video files, see Video limitations.
  • OpenAI compatible
  • Python
  • Node.js
  • HTTP
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi/kimi-k3",
    messages=[
        {
            "role": "user",
            "content": [
                # When passing a video file directly, set the type to video_url.
                {
                    "type": "video_url",
                    "video_url": {
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241115/cqqkru/1.mp4"
                    }
                },
                {
                    "type": "text",
                    "text": "What is the content of this video?"
                }
            ]
        }
    ]
)

print(completion.choices[0].message.content)

File limitations

  • Image files
  • Video files
  • Image resolution: The recommended image resolution is 4K (4096 × 2160) or lower.
  • Supported image formats: PNG, JPEG, WEBP, and GIF.
  • Image size and quantity: There is no limit on the size or quantity of images, but you must ensure that the total size of the text and images in the request does not exceed 100 MB.

Other features

ModelMulti-turn conversationFunction CallingPartial modeWeb searchContext CacheStructured output
kimi/kimi-k3SupportedSupportedSupportedNot supportedSupportedSupported
kimi/kimi-k2.7-code-highspeed
kimi/kimi-k2.7-code
kimi/kimi-k2.6
  • The preceding models support context cache (implicit cache, enabled by default):
    • For kimi/kimi-k3, input tokens that hit the cache are billed at 10% of the standard input price.
    • For kimi/kimi-k2.7-code-highspeed and kimi/kimi-k2.7-code, input tokens that hit the cache are billed at 20.0% of the standard input price.
    • For kimi/kimi-k2.6, input tokens that hit the cache are billed at 16.9% of the standard input price.

Parameter default values

Parameterkimi/kimi-k3kimi/kimi-k2.7-code-highspeedkimi/kimi-k2.7-codekimi/kimi-k2.6
stream_optionsThe only supported value is true.The only supported value is true.The only supported value is true.The only supported value is true.
temperature11.01.0Thinking mode: 1.0Non-thinking mode: 0.6
top_p0.950.950.95Thinking mode/Non-thinking mode: 0.95
repetition_penalty0.00.00.0Thinking mode/Non-thinking mode: 0.0
presence_penalty-0.00.0Thinking mode/Non-thinking mode: 0.0
tool_choiceauto / none / requiredautoautoThinking mode/Non-thinking mode: auto
top_k----
preserve_thinkingDisabled by defaultEnabled by defaultEnabled by defaultDisabled by default
  • The stream_options parameter supports only the value true. The values for the temperature, top_p, repetition_penalty, and presence_penalty parameters cannot be modified.
  • kimi/kimi-k3 supports the reasoning_effort parameter. The only supported value is max.
  • In thinking mode, when using Kimi models for tool calling: you must keep the reasoning_content field in each assistant message; for the tool_choice parameter, kimi-k3 supports auto / none / required (three options); other models do not support required and will return an error if it is passed. kimi-k3 supports dynamic tool loading. For details, see: https://platform.kimi.com/docs/guide/use-dynamic-tool-loading.
  • A hyphen (-) indicates that the parameter has no default value and cannot be set.

Model list and billing

kimi/kimi-k3, kimi/kimi-k2.7-code-highspeed, and kimi/kimi-k2.7-code are thinking-only models (enable_thinking is always true and cannot be set to false). kimi/kimi-k2.6 is a hybrid thinking model. You can use the enable_thinking parameter to enable or disable the thinking mode. Note: The thinking_budget parameter cannot be used to limit the length of the chain-of-thought for any of these models. For more information about model context length and pricing, see the Alibaba Cloud Model Studio console. Billing is based on the number of input and output tokens for the model.
In thinking mode, the chain-of-thought is billed as output tokens.

Error codes

If an execution error occurs, see Error messages to resolve the issue.
Token Plan
Model Playground
Fine-tuning
Model Compression
Statistics and Monitoring
Support