outputSchema option, and the gateway handles the provider-specific translation — whether you are using OpenAI, Anthropic, Google, or Mistral.
The outputSchema option
Add outputSchema to any client.chat() or client.stream() call:
json_object mode
The model is instructed to return valid JSON of any shape. Use this when you want JSON output but do not need to enforce a specific schema:
json_schema mode
The model is constrained to match a specific JSON Schema. Provide the schema inline alongside mode: "json_schema":
Automatic parsing with chatJson<T>()
client.chatJson<T>() is a convenience wrapper around chat() that parses the response content as JSON and returns it typed — no JSON.parse required:
Complete example
Here is a full end-to-end example that asks a model to evaluate a piece of text and return a structured assessment:Cross-provider compatibility
Structured output normalization is applied by the gateway, not the SDK. The same
outputSchema option works identically whether you target OpenAI, Anthropic, Google, or Mistral — the gateway translates it to each provider’s native format before forwarding the request.