Request JSON output using response_format parameter

Use response_format.type set to 'json_schema' or 'json_object' to get structured API responses.

GrokParaphrased
Code
response_format.type = "json_schema"
response_format.json_schema = {
  "type": "object",
  "properties": {
    "invoice_vendor": {"type": "string"},
    "invoice_amount": {"type": "number"},
    "invoice_date": {"type": "string", "format": "date"}
  },
  "required": ["invoice_vendor", "invoice_amount", "invoice_date"]
}
Language

json

Explanation

This snippet shows how to configure the API to return a JSON object that adheres to a defined schema. The `response_format.type` can be set to `json_schema` to enforce a specific structure or `json_object` for any well-formed JSON. The `json_schema` field accepts a JSON Schema object to define the expected output structure.

What it does and when to use it

Configure the API to return structured JSON output by setting the `response_format.type` parameter to `json_schema` or `json_object`. Provide a JSON schema to define the exact structure required for the model's response, ensuring type-safe and predictable data extraction.

Why it works

This method leverages the API's capability to parse and generate data according to a predefined schema, ensuring that the output is not free-form text but a structured object that can be easily processed by downstream applications.

Sources and credit

First seen on Subvolts May 11, 2026. Updated Sep 11, 2026. Spotted a problem? Tell us.

Where it shows up
Terms used

Schema

Related in the PlaybookPlaybook →

The Playbook: reusable how-tos, prompts, configs and tips pulled out of the news.

Questions people ask

Which AI tools does this work with?
The sources used it with Grok.
Where did this come from?
xAI (xAI Docs: Guides). Subvolts collected, normalized and credited it; the link above opens the original.