Skip to main content
Requesty makes every supported model speak structured JSON — from simple json_object mode to strict, schema-enforced json_schema mode. One API, consistent behavior, regardless of the underlying provider.
Get your API key in the Requesty Console.

Overview

Use json_schema whenever you need type-safe, parseable output. It eliminates the need for retry loops and manual validation — the model is constrained at the decoding level to only produce tokens that satisfy your schema.
For reusable structured outputs, save json_object or json_schema as the prompt’s Response Format in the Prompt Library. Requests using that prompt_id inherit the response format automatically, and the prompt-level setting overrides any caller-provided response_format.

JSON Schema mode gives you guaranteed structured output. You define the exact shape of the response, and the model is constrained to produce only valid output conforming to that schema.

Chat Completions API

Responses API

Schema Requirements

When using json_schema mode with strict: true, your schema must follow these rules:
Every property in your schema must be listed in the required array. Optional fields should use a union type with null instead.
Set "additionalProperties": false on every object in your schema. This tells the model exactly which keys to produce.
string, number, integer, boolean, null, array, object, and unions via anyOf. Enums are supported via the enum keyword.
Nested objects must also have required and additionalProperties: false:

JSON Object Mode

For models that don’t support json_schema, or when you just need valid JSON without strict schema enforcement, use json_object mode. The model will return valid JSON, but you’re responsible for instructing it on the desired structure via your prompt.
With json_object mode, you must instruct the model to produce JSON in your system or user message. The model is only guaranteed to return valid JSON — not any particular structure. Use json_schema mode for guaranteed structure.

Real-World Examples

Multi-step extraction pipeline

Enums and complex types

Chain of thought with structured output


Framework Integrations

Requesty’s structured outputs work seamlessly with popular frameworks. Since Requesty is OpenAI-compatible, just point the framework’s OpenAI client at https://router.requesty.ai/v1.

Streaming with Structured Outputs

Both json_object and json_schema work with streaming. Tokens are delivered incrementally, and you can parse the complete JSON once the stream finishes.
See the streaming documentation for more details.

Finding Compatible Models

Use the List Models endpoint to discover which models support structured outputs:
The response includes:
  • supports_json_schema: true — model supports strict json_schema mode
  • supports_json_object: true — model supports json_object mode (most models)

Comparison: Chat Completions vs Responses API

Both APIs support the same structured output modes. The difference is in how you pass the format:

Tips & Best Practices

Simpler schemas produce more reliable outputs. Flatten deeply nested structures where possible and limit arrays to 10–20 items in your schema descriptions.
Add description fields to your schema properties to guide the model on what to extract:
Since strict mode requires all properties in required, use null unions for optional values:
The schema enforces structure, but your system prompt controls the content quality. Be specific about what you want extracted and how.
Combine structured outputs with fallback policies to automatically retry with a different model if the primary one fails:

Error Handling

Common issues:
  • 400 error with json_schema → Your schema likely has an unsupported construct. Check the schema requirements above.
  • Model returns empty content → Ensure your prompt gives the model enough context to fill all required fields.
  • Model not supporting json_schema → Check supports_json_schema via List Models or fall back to json_object mode.
Last modified on July 10, 2026