Skip to main content
JSON Mode makes the Kimi large language model output a valid, correctly parsable JSON document. When you need structured output โ€” for example, summarizing an article into structured data like this โ€” enable it with the response_format parameter:

Enable JSON Mode with response_format

If you only tell the Kimi large language model in the prompt: โ€œPlease output content in JSON format,โ€ the model can understand your request and generate a JSON document as required. However, the generated content often has some flaws: for instance, in addition to the JSON document, Kimi might output extra text to explain the JSON document โ€”
โ€”or the JSON document might be malformed and cannot be parsed correctly (note the comma at the end of the summary field on the last line):
The response_format parameter constrains the output format. Its default value is {"type": "text"}, which means ordinary text content with no formatting constraints. Set response_format to {"type": "json_object"} to enable JSON Mode, and the Kimi large language model will output a valid, correctly parsable JSON document as required. Using JSON Mode takes three steps:
  1. Define the output JSON format in the system or user prompt, including specific field names and field types; the best practice is to provide a concrete output example and explain the meaning of each field;
  2. Set the response_format parameter to {"type": "json_object"};
  3. Parse the content in the message returned by the Kimi large language model; message.content is a valid JSON Object serialized as a string.

Full example: a customer-service bot with mixed message types

Imagine a WeChat intelligent robot customer service (referred to as intelligent customer service): it uses the Kimi large language model to answer customer questions, and can reply not only with text messages but also with images, link cards, voice messages, and other types of messages, mixing different types of messages in a single response. For example, for customer product inquiries, it provides a text reply, a product image, and finally a purchase link (in the form of a link card). The following code demonstrates how to use JSON Mode in this scenario to make the model output replies in a fixed structure, and how to parse each type of message in the returned content:
The examples on this page use the latest model kimi-k3 by default. K3 configures reasoning effort with the top-level reasoning_effort request field (supports "low" / "high" / "max", default "max"). To use another model such as kimi-k2.6 or kimi-k2.5, just replace the model field โ€” parameter configurations differ across models. See the Model Parameter Reference.

Troubleshoot truncated JSON output

If you have correctly set the response_format parameter and specified the format of the JSON document in the prompt, but the JSON document you receive is incomplete or truncated and cannot be parsed correctly, check whether the finish_reason field in the return value is length. A smaller max_tokens value will cause the modelโ€™s output to be truncated, and this rule also applies when using JSON Mode. We recommend estimating the size of the output JSON document and setting a reasonable max_tokens value, so that you can correctly parse the JSON document returned by the Kimi large language model. For a more detailed explanation of incomplete or truncated output from the Kimi large language model, see Troubleshooting.

Notes

  • The Kimi large language model only generates JSON Object type JSON documents; do not prompt it to generate JSON Array or other types of JSON documents.
  • If you do not correctly inform the Kimi large language model of the required JSON Object format, it will generate unexpected results.