API

Structured output

Pass a JSON Schema in response_format to get a response that is valid JSON matching your schema.

JSON Schema

{
  "model": "gpt-5.6-sol",
  "messages": [{"role": "user", "content": "Give me a city and its country"}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "place",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "city": {"type": "string"},
          "country": {"type": "string"}
        },
        "required": ["city", "country"],
        "additionalProperties": false
      }
    }
  }
}

The JSON is returned as a string in choices[0].message.content, for example {"city":"Kyoto","country":"Japan"}. Parse it in your code.

Structured output support depends on the model. GPT models support json_schema.

Last updated