Structured outputs
Get schema-constrained JSON from any capable model
Structured outputs constrain a response to any JSON object (json_object) or JSON matching your schema (json_schema), using each vendor’s native mechanism. Use json_schema when you deserialize into typed structures.
Request JSON
Pass response_format on /v1/responses or OpenAI Chat Completions, or text.format on /v1/openai/responses. In the TypeScript SDK, build it with zodResponseFormat from merge-gateway-sdk/zod.
Your schema passes to the vendor as written, including $ref/$defs and anyOf, rewriting dialect (such as definitions to $defs) only where a vendor needs it.
Strict mode
strict is tri-state on the native API:
The AI SDK provider defaults strictJsonSchema to true; set it to false for schemas with optional fields.
Routing and failover
Gateway checks support on the exact route before calling the vendor: routing policies drop candidates that can’t serve the request, and fallbacks re-check.
On a route with forced tool choice but no native structured outputs, Gateway serves json_schema by forcing one tool whose parameters are your schema, returning its arguments as the message text. This doesn’t apply to json_object, to routes that can’t force a tool, or to requests with their own tools or tool_choice, which return 400 unsupported_params.
With strict: true, a 200 whose body isn’t valid JSON or doesn’t match your schema is a failed attempt, and a Priority or Intelligent policy moves to the next candidate. If every candidate fails, Gateway serves the last body, so validate it. Streaming, tool-call turns, and output-token-limit stops are exempt. Each discarded attempt bills at the route that ran it. Vendor strict modes don’t enforce value keywords such as minimum.
With stream: true, JSON arrives as text deltas, and a mid-stream fallback sends a {"fallback_restart": true, "model": "...", "vendor": "..."} data frame and restarts generation, so discard anything parsed before it.
Reference
Unsupported formats and validation errors
supports_structured_outputs on GET /v1/models is true for routes Gateway serves natively or by emulation. Errors has the error shapes.