Why does the model repeatedly call the same tool when using `tool_calls`?
Why does the model repeatedly call the same tool when using `tool_calls`?
tool_calls), the model may issue multiple consecutive tool calls based on the context.If you find that the model repeatedly calls the same tool, each call uses exactly the same function.name and function.arguments, and the tool result does not provide new useful information, you can treat it as a repeated tool call.When handling this issue, we recommend checking the message layout first:- When the Kimi API returns
finish_reason=tool_calls, make sure the returnedchoice.messagehas been added to themessageslist as is. - Make sure each
tool_callhas a corresponding message withrole=tool. - Make sure the
tool_call_idin therole=toolmessage exactly matches the correspondingtool_call.id. - If you use streaming output with
stream=True, make sure the streamedtool_callschunks have been assembled correctly, especially thefunction.argumentsfield.
<system-reminder> is only an example prompt, not a special field of the Kimi API. You can merge it into the next role=system message, or write it into the system prompt based on your own message management logic. To avoid false positives, we recommend triggering this reminder only when the same tool, the same arguments, consecutive repetition, and no new progress from the tool result are all true.Why are API results different from Kimi Assistant results?
Why are API results different from Kimi Assistant results?
tool_calls guide:Use the Kimi API for Tool Calls (tool_calls)If you want help from the open-source community, you can refer to these open-source projects:If you want services from professional vendors, these options are available:The content returned by the Kimi API is incomplete or truncated
The content returned by the Kimi API is incomplete or truncated
choice.finish_reason in the response body. If the value is length, it means the number of tokens generated by the current model exceeded the max_completion_tokens parameter in the request. In this case, the Kimi API only returns up to max_completion_tokens tokens, and any extra content is discarded.When you encounter finish_reason=length, and you want the Kimi model to continue from the previous response, you can use Partial Mode. For details, see:Use Partial Mode with the Kimi APITo avoid finish_reason=length, we recommend increasing max_completion_tokens appropriately. A best practice is to use the estimate-token-count API to calculate the number of tokens in the input, then subtract that number from the maximum context window supported by the selected model. For example, moonshot-v1-32k supports up to 32k tokens, while kimi-k2.6, kimi-k2.5, kimi-k2-0905-preview, and kimi-k2-turbo-preview support up to 256k tokens. The remaining value can be used as the upper bound for max_completion_tokens in the current request.What is the output length of the Kimi model?
What is the output length of the Kimi model?
- For
moonshot-v1-8k, the maximum output length is8*1024 - prompt_tokens. - For
moonshot-v1-32k, the maximum output length is32*1024 - prompt_tokens. - For
moonshot-v1-128k, the maximum output length is128*1024 - prompt_tokens. - For
kimi-k2.6,kimi-k2.5,kimi-k2-0905-preview, andkimi-k2-turbo-preview, the maximum output length is256*1024 - prompt_tokens.
How many Chinese characters does the Kimi model support?
How many Chinese characters does the Kimi model support?
moonshot-v1-8ksupports approximately 15,000 Chinese characters.moonshot-v1-32ksupports approximately 60,000 Chinese characters.moonshot-v1-128ksupports approximately 200,000 Chinese characters.kimi-k2.6,kimi-k2.5,kimi-k2-0905-preview, andkimi-k2-turbo-previewsupport approximately 400,000 Chinese characters.
File extraction is inaccurate, or images cannot be recognized
File extraction is inaccurate, or images cannot be recognized
When using the `files` API, I want to reference file content with `file_id`
When using the `files` API, I want to reference file content with `file_id`
file_id.Error: `content_filter: The request was rejected because it was considered high risk`
Error: `content_filter: The request was rejected because it was considered high risk`
content_filter error.The TPM or RPM limit in the error message does not match my account tier
The TPM or RPM limit in the error message does not match my account tier
rate_limit_reached_error while using the Kimi API, for example:api_key for the current account. In most cases, this mismatch is caused by using the wrong api_key, such as accidentally using a key provided by another user or mixing up keys across multiple accounts.Error: `model_not_found`
Error: `model_not_found`
base_url=https://api.moonshot.ai/v1. The model_not_found error is usually caused by using the OpenAI SDK without setting base_url, which sends the request to OpenAI servers instead. OpenAI then returns the model_not_found error.The Kimi model makes numerical calculation errors
The Kimi model makes numerical calculation errors
tool_calls) to provide calculator functionality to the Kimi model. For more information, see our tool calling guide:Use the Kimi API for Tool Calls (tool_calls)The Kimi model cannot answer today's date
The Kimi model cannot answer today's date
- python
- node.js
How do I handle errors without using an SDK?
How do I handle errors without using an SDK?
- python
- node.js
Why do some requests respond quickly while others respond slowly when the prompts are similar?
Why do some requests respond quickly while others respond slowly when the prompts are similar?
stream=True and observe the time to first token, abbreviated as TTFT. In normal cases, when prompt lengths are similar, TTFT should not vary significantly.I set `max_completion_tokens=2000` to make Kimi output 2,000 characters, but the output is shorter
I set `max_completion_tokens=2000` to make Kimi output 2,000 characters, but the output is shorter
Note:Themax_tokensis deprecated. Please usemax_completion_tokensinstead. The two fields have the same meaning.
max_completion_tokens parameter means: when calling /v1/chat/completions, it specifies the maximum number of tokens the model is allowed to generate. Once the number of generated tokens exceeds max_completion_tokens, the model stops generating the next token.max_completion_tokens is used to:- Help the caller determine which model to use. For example, when
prompt_tokens + max_completion_tokens <= 8 * 1024, you can choosemoonshot-v1-8k. - Prevent the Kimi model from generating too much unexpected content in unusual cases, which could cause extra cost. For example, the model might repeatedly output whitespace.
max_completion_tokens does not tell the Kimi model how many tokens to output. In other words, max_completion_tokens is not used as part of the prompt input to the Kimi model. If you want the model to output a specific number of characters, use these general approaches:- For outputs under 1,000 characters:
- Clearly specify the desired character count in the prompt.
- Manually or programmatically check whether the output length meets expectations. If not, tell the model in a second round that the output is too long or too short, then ask it to generate a new version.
- For outputs over 1,000 characters or much longer:
- Split the expected output by structure or chapter, create a template, and use placeholders to mark where the model should fill in content.
- Ask the Kimi model to fill each placeholder one by one, then assemble the complete long-form text.
I only made one request in a minute, but triggered `Your account reached max request`
I only made one request in a minute, but triggered `Your account reached max request`
Certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default.This retry mechanism retries 2 times by default when an error occurs, for a total of 3 requests. In unstable network conditions or other cases that may cause request errors, using the OpenAI SDK can expand one request into 2 or 3 requests. All of these requests count toward your RPM quota.Note: For users on a
tier0 account using the OpenAI SDK, one failed request may consume the entire RPM quota because of the default retry mechanism.I used `base64` encoding for my text content to make transmission easier
I used `base64` encoding for my text content to make transmission easier
base64 can cause massive token consumption. If your file type is supported by our /v1/files API, upload the file through the files API and extract its content there.For binary files or files in other encoded formats, the Kimi model currently cannot parse the content. Do not add this content to the context.Why can't I use a key from another Kimi platform on platform.kimi.ai?
Why can't I use a key from another Kimi platform on platform.kimi.ai?
401 invalid_authentication_error. If you receive a 401 error, first check whether you are using a key from the wrong platform.- International open platform
base_url: https://api.moonshot.ai/v1