Structured output

Updated

When you need machine-readable JSON from the model, there are two strengths of constraint:

Mode OpenAI Chat OpenAI Responses Gemini Capability the endpoint needs
JSON mode: output is valid JSON "response_format": {"type": "json_object"} "text": {"format": {"type": "json_object"}} generationConfig.responseMimeType set to application/json json_mode
Structured output: follows a JSON Schema "response_format": {"type": "json_schema", "json_schema": {...}} "text": {"format": {"type": "json_schema", ...}} generationConfig.responseSchema or responseJsonSchema structured_output
curl https://modelportal.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "messages": [{"role": "user", "content": "List three fruits and their colors"}],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "fruits",
        "schema": {
          "type": "object",
          "properties": {"items": {"type": "array", "items": {"type": "object", "properties": {"name": {"type": "string"}, "color": {"type": "string"}}, "required": ["name", "color"]}}},
          "required": ["items"]
        }
      }
    }
  }'

A request using either mode is routed only to endpoints declaring the matching capability; if none do, you get 400 unsupported_parameter rather than a silent fallback to plain text. The Anthropic protocol has no separate JSON mode parameter; use tool calling to constrain the output shape.