Skip to main content
Prefer native structured output. JSON mode is the fallback for models or schemas the json_schema path does not accept, and it leans on field descriptions to convey the shape, so keep them descriptive. Note that Kimi only emits JSON objects, never a top-level JSON array - wrap lists in a field rather than asking for an array at the root.
structured_output.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your Moonshot API key

4

Run the example

Save the code above as structured_output.py, then run:
Full source: cookbook/90_models/moonshot/structured_output.py