Skip to main content
Structured output helps you use model responses directly in software. Instead of asking for free-form text and parsing it later, you can request JSON or a strict JSON Schema shape. Use it for extraction, form filling, configuration generation, routing decisions, and any workflow where downstream code expects stable fields.

JSON mode

JSON mode asks the model to return valid JSON:
JSON mode guarantees valid JSON, but it does not guarantee a specific field structure. Describe the expected keys clearly in the prompt when you use this mode.

JSON Schema mode

Use json_schema when you need a stricter shape:
Important fields:
  • strict: true asks the model to follow the schema closely.
  • required lists fields that must be present.
  • additionalProperties: false prevents unexpected fields.

Python example

Replace the entire sk-your-api-key value in API_KEY with your actual key. To use another model, change MODEL. The example bypasses system proxy environment variables and connects directly to Moxus AI.

Node.js example

Replace the entire sk-your-api-key value in API_KEY with your actual key. To use another model, change MODEL. The model returns a JSON string; the example converts it to an object with JSON.parse.

Nested structures

Schemas can include arrays, nested objects, and enums:

Structured output vs. function calling

Notes

  • Prefer JSON Schema for production workflows that require stable fields.
  • Add field descriptions when the schema is complex.
  • Still validate and handle parse errors in your application.
  • Strict schema support depends on the selected model.

Next steps