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
JSON Schema (Recommended)
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
- Python (OpenAI SDK)
- Python (raw schema)
- TypeScript
- cURL
Responses API
- Python (OpenAI SDK)
- Python (raw schema)
- TypeScript
- cURL
Schema Requirements
When usingjson_schema mode with strict: true, your schema must follow these rules:
All fields must be required
All fields must be required
Every property in your schema must be listed in the
required array. Optional fields should use a union type with null instead.additionalProperties must be false
additionalProperties must be false
Set
"additionalProperties": false on every object in your schema. This tells the model exactly which keys to produce.Supported types
Supported types
string, number, integer, boolean, null, array, object, and unions via anyOf. Enums are supported via the enum keyword.Nested objects
Nested objects
Nested objects must also have
required and additionalProperties: false:JSON Object Mode
For models that don’t supportjson_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.
- Chat Completions
- Responses API
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 athttps://router.requesty.ai/v1.
- LangChain
- Instructor
- Pydantic AI
- LiteLLM
- DSPy
- Haystack
Streaming with Structured Outputs
Bothjson_object and json_schema work with streaming. Tokens are delivered incrementally, and you can parse the complete JSON once the stream finishes.
Finding Compatible Models
Use the List Models endpoint to discover which models support structured outputs:supports_json_schema: true— model supports strictjson_schemamodesupports_json_object: true— model supportsjson_objectmode (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
Keep schemas simple
Keep schemas simple
Simpler schemas produce more reliable outputs. Flatten deeply nested structures where possible and limit arrays to 10–20 items in your schema descriptions.
Use descriptions for guidance
Use descriptions for guidance
Add
description fields to your schema properties to guide the model on what to extract:Handle optional fields with null unions
Handle optional fields with null unions
Since strict mode requires all properties in
required, use null unions for optional values:Combine with system prompts
Combine with system prompts
The schema enforces structure, but your system prompt controls the content quality. Be specific about what you want extracted and how.
Use fallback policies for reliability
Use fallback policies for reliability
Combine structured outputs with fallback policies to automatically retry with a different model if the primary one fails:
Error Handling
Common issues:
400error withjson_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→ Checksupports_json_schemavia List Models or fall back tojson_objectmode.