Skip to content
Open app

Structured outputs

Constrain a response to a JSON schema.

Ask for JSON that matches a schema with response_format and type: "json_schema". The simpler { "type": "json_object" } asks for a JSON object without a schema and is forwarded as sent. Either works only on models that list response_format or structured_outputs in supported_parameters.

Request a schema

curl https://deference.si/v1/chat/completions \
  -H "Authorization: Bearer $DEFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "messages": [{ "role": "user", "content": "Extract: Ada paid $12.40 on Oct 8." }],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "payment",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "amount_usd": { "type": "number" },
            "date": { "type": "string" }
          },
          "required": ["name", "amount_usd", "date"],
          "additionalProperties": false
        }
      }
    }
  }'

Check the result

The message content is a JSON string. Parse it, and validate it on your side. A response that stops early with finish_reason: "length" can be cut-off JSON, so raise max_tokens if parsing fails.

Models without support

A model that does not support response_format answers with the provider's error, usually HTTP 400, and an invalid schema fails the same way. Check supported_parameters for response_format or structured_outputs before sending the field — provider is rejected on this API, so a request cannot force a supporting endpoint. If no model qualifies, put the schema in the prompt and validate the result.