Guides

Structured output

This is not available on this model yet. The model object's capabilities.structured_output turns true when it is.

What it is for

When a program reads the reply, free text is hard to use. Give response_format a JSON schema and the reply comes back as JSON in that shape.

Ask for a schema

curl https://antarya.ai/v1/chat \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Summarise this contract'"'"'s termination clause."}
    ],
    "response_format": {
      "type": "json_schema",
      "schema": {
        "type": "object",
        "properties": {
          "notice_period": {"type": "string"},
          "who_can_end_it": {"type": "string"},
          "summary": {"type": "string"}
        },
        "required": ["notice_period", "who_can_end_it", "summary"]
      }
    }
  }'
Output
{
  "id": "req_05",
  "content": [
    {"type": "text", "text": "{\"notice_period\": \"30 days\", \"who_can_end_it\": \"Either party\", \"summary\": \"Either side can end the agreement with written notice.\"}"}
  ],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 96, "output_tokens": 44}
}

The JSON is the text of the first content part. Parse it as you would any JSON string.

Parameters

NameTypeRequiredDescription
response_formatobjectNoAsks for the reply as JSON in a shape you give.
typetextYesRequiredAlways "json_schema".
schemaobjectYesRequiredA JSON schema for the reply.

Limits

If the reply stops early because it reached max_output_tokens, the JSON may be cut off. Read stop_reason before you parse: a reply that ended with max_output_tokens is not complete JSON.

Limit Value
Supported schema keywords type, properties, required, items, enum, description, additionalProperties

Next steps