Applying for and Using the Kimi Chat Completion API

To use Kimi in an AI client, you can submit conversations through the aichat_create_conversation_v2 tool in AI Chat MCP. It calls AiChat v2; see the tool's model list for available models and parameters. AI Chat MCP Integration Guide

Kimi is a series of AI models developed by Moonshot AI. Currently, kimi-k3.1-pro is recommended for long-running programming, complex reasoning, visual understanding, and knowledge work; kimi-k3 is still available. They are accessed through the OpenAI-compatible Chat Completions API.

This document mainly introduces the process of using the Kimi Chat Completion API, which allows us to easily use the official Kimi chat functionality.

Supported Models

Four models are currently supported: kimi-k3.1-pro, kimi-k3, kimi-k2.6, and kimi-k2.7-code. K2.7 Code is intended for programming and tool-calling scenarios and is billed at the same rate as K2.6; do not pass a thinking switch or reasoning_effort for it in requests. Other Kimi models are no longer supported, so please explicitly select one of these four models in your client.

Application Process

To use the Kimi Chat Completion API, first go to the Ace Data Cloud Console to obtain your API Token and save it for later use.

If you have not yet logged in or registered, you will be automatically redirected to the login page to register and log in. Once completed, you will be automatically returned to the current page.

An API Key for a general application can be used for services enabled for the account; a Key for a dedicated application can be used within that application's service scope. Please check the Key's permissions, expiration date, and limits, and confirm that the application balance is sufficient to pay for the request. Available trial credits are subject to what is displayed in your account; if the balance is insufficient, click the "Recharge" button.

📘 Full documentation: Kimi Chat Completion API →

Basic Usage

Next, you can fill in the corresponding content on the interface, as shown below:

When using this interface for the first time, you need to fill in at least three items: authorization can be selected directly from the drop-down list; model is used to select the Kimi model, with kimi-k3.1-pro recommended; messages is an array of conversation messages, each containing role and content, where role supports user, assistant, system, and tool.

You can also see the corresponding generated call code on the right. You can copy and run the code directly, or click the "Try" button to test it.

The following is an actual K3 response obtained using reasoning_effort: max (unused extended fields are omitted):

{
  "id": "msg_2D4Btbg1WgvkNE3tCYkR4xGA",
  "object": "chat.completion",
  "created": 1784466588,
  "model": "kimi-k3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 86,
    "completion_tokens": 206,
    "total_tokens": 292
  }
}

The returned result contains several fields, described below:

  • id, the ID generated for this conversation task, used to uniquely identify it.
  • model , the selected model from the official Kimi website.
  • choices, the response information Kimi provides for the prompt.
  • usage : token usage statistics for this exchange.

Here, choices contains Kimi's response information, and the choices within it contains the details of Kimi's response, as shown in the figure.

As you can see, the content field within choices contains the specific content of Kimi's response; K3 may also return reasoning_content to represent the reasoning process.

K3.1 Pro Reasoning Effort

kimi-k3.1-pro always has reasoning enabled. You can set reasoning_effort to low, high, or max at the top level of the request body; do not pass a configuration that disables reasoning. The model supports a context of up to 1,048,576 tokens, but the actual request limit is subject to the current API. Pricing is based on input, output, and cache-hit usage; see the Pricing card in the model catalog for details.

curl https://api.acedata.cloud/kimi/chat/completions \
  -H "Authorization: Bearer $ACEDATACLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3.1-pro",
    "messages": [{"role": "user", "content": "审查这段代码并给出修复方案"}],
    "reasoning_effort": "low"
  }'

The following K3 example is retained for existing integrations, and the example response was indeed obtained from a K3 request.

K3 Reasoning Effort

kimi-k3 always has reasoning enabled. The top level of the request body supports the reasoning_effort field, and the only currently supported value is max; max is also used when the field is omitted. Please use the supported value.

curl https://api.acedata.cloud/kimi/chat/completions \
  -H "Authorization: Bearer $ACEDATACLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [{"role": "user", "content": "审查这段代码并给出修复方案"}],
    "reasoning_effort": "max"
  }'

When using the OpenAI SDK, you can pass this field directly:

response = client.chat.completions.create(
    model="kimi-k3",
    messages=[{"role": "user", "content": "设计一个可靠的任务队列"}],
    reasoning_effort="max",
)

For multi-turn conversations and tool calls, please pass the complete assistant message from the previous turn back into messages, including reasoning_content and tool_calls.

Official References

  • Thinking Effort: Explains that Kimi K3 always has reasoning enabled and that max is currently the only supported value for reasoning_effort.
  • Model Parameter Reference: Compares the reasoning parameters, context windows, and tool-calling differences between K3 and the K2 series.
  • Create Chat Completion: Moonshot's official Chat Completions request, response, and OpenAPI field definitions.

Streaming Responses

This interface also supports streaming responses, which is very useful for web integration and allows web pages to display text character by character. If you want to return the response as a stream, you can change the stream parameter in the request header to true.

Make the change as shown in the figure, but the calling code also needs corresponding changes to support streaming responses.

After changing stream to true, the API will return the corresponding JSON data line by line. In the code, we need to make corresponding changes to obtain the results line by line.

Python sample calling code:

import requests

url = "https://api.acedata.cloud/kimi/chat/completions"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "kimi-k3",
    "messages": [{"role":"user","content":"Hello"}],
    "reasoning_effort": "max",
    "stream": True
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

Below are excerpts of the initial, reasoning, content, ending, and usage data chunks from the same real K3 Max streaming response:

data: {"id":"msg_er7WZjyv2kD3TG2yzbFPu5ZJ","object":"chat.completion.chunk","created":1784466598,"model":"kimi-k3","choices":[{"index":0,"delta":{"content":"","role":"assistant"},"finish_reason":null}],"usage":null}

data: {"id":"msg_er7WZjyv2kD3TG2yzbFPu5ZJ","object":"chat.completion.chunk","created":1784466598,"model":"kimi-k3","choices":[{"index":0,"delta":{"reasoning_content":"The"},"finish_reason":null}],"usage":null}

data: {"id":"msg_er7WZjyv2kD3TG2yzbFPu5ZJ","object":"chat.completion.chunk","created":1784466598,"model":"kimi-k3","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}],"usage":null}

data: {"id":"msg_er7WZjyv2kD3TG2yzbFPu5ZJ","object":"chat.completion.chunk","created":1784466598,"model":"kimi-k3","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":null}

data: {"id":"msg_er7WZjyv2kD3TG2yzbFPu5ZJ","object":"chat.completion.chunk","created":1784466598,"model":"kimi-k3","choices":[],"usage":{"prompt_tokens":172,"completion_tokens":168,"total_tokens":340}}

data: [DONE]

As you can see, the response contains many data entries, and the choices in data contain the latest response content, consistent with the content introduced above. choices contains the newly added response content, which you can integrate into your system based on the results. At the same time, the end of the streaming response is determined by the content of data: if the content is [DONE], it indicates that the streaming response is complete. The returned data results contain several fields, described below:

  • id, the ID generated for this conversation task, used to uniquely identify it.
  • model , the selected model from the official Kimi website.
  • choices, the response information Kimi gives for the prompt.

JavaScript is also supported. For example, the Node.js streaming call code is as follows:

const options = {
  method: "POST",
  headers: {
    accept: "application/json",
    authorization: "Bearer {token}",
    "content-type": "application/json"
  },
  body: JSON.stringify({
    model: "kimi-k3",
    messages: [{ role: "user", content: "Hello" }],
    stream: true
  })
};

const response = await fetch("https://api.acedata.cloud/kimi/chat/completions", options);
const reader = response.body.getReader();
const decoder = new TextDecoder("utf-8");
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  process.stdout.write(decoder.decode(value));
}

Java sample code:

JSONObject jsonObject = new JSONObject();
jsonObject.put("model", "kimi-k3");
jsonObject.put("messages", new JSONArray().put(new JSONObject().put("role", "user").put("content", "Hello")));
jsonObject.put("stream", true);
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(jsonObject.toString(), mediaType);
Request request = new Request.Builder()
  .url("https://api.acedata.cloud/kimi/chat/completions")
  .post(body)
  .addHeader("accept", "application/json")
  .addHeader("authorization", "Bearer {token}")
  .addHeader("content-type", "application/json")
  .build();

OkHttpClient client = new OkHttpClient();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());

You can adapt the code for other languages yourself; the principle is the same.

Multi-Turn Conversations

If you want to integrate multi-turn conversation functionality, you need to upload multiple prompts in the messages field. A specific example of multiple prompts is shown below:

Python sample calling code:

import requests

url = "https://api.acedata.cloud/kimi/chat/completions"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "kimi-k3",
    "messages": [{"role":"assistant","content":"Hello! How can I help you today?"},{"role":"user","content":"What model are you?"}],
    "reasoning_effort": "max"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

By uploading multiple prompts, you can easily implement multi-turn conversations. Below is the real K3 Max response obtained from this request (unused extension fields omitted):

{
  "id": "msg_Rqp8nPGBDHWwBlL4VpxuafOp",
  "object": "chat.completion",
  "created": 1784466628,
  "model": "kimi-k3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I’m Kimi, an AI assistant developed by Moonshot AI (月之暗面). I don’t have a specific public model version identifier to share from here."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 134,
    "completion_tokens": 346,
    "total_tokens": 480
  }
}

As you can see, the information contained in choices is consistent with that described in basic usage. It contains the specific content of Kimi's response to multiple conversation messages, so it can answer the corresponding questions based on the content of multiple messages.

Error Handling

When calling the API, if an error occurs, the API will return the corresponding error code and message. For example:

  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Example Error Response

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

Conclusion

Through this document, you have learned how to use the Kimi Chat Completion API to implement standard conversations, streaming responses, and multi-turn conversations, as well as how to control K3's reasoning intensity through reasoning_effort.