AIVAX

Structured output

Use structured responses when your application needs JSON output that matches a schema. AIVAX supports them through response_schema, response_format, and json_only.

JSON
{
    "model": "@google/gemini-3.8-flash",
    "prompt": "Search for recent news about electric vehicles.",
    "stream": true,
    "builtin_tools": {
        "tools": [
            "WebSearch"
        ],
        "options": {
            "web_search_mode": "full"
        }
    },
    "response_schema": {
        "type": "object",
        "properties": {
            "news": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "title": {
                            "type": "string",
                            "description": "News title"
                        },
                        "summary": {
                            "type": "string",
                            "description": "News summary"
                        }
                    },
                    "required": ["title", "summary"]
                }
            }
        },
        "required": ["news"]
    }
}

response_schema enables JSON Healing. AIVAX asks the model for JSON, extracts JSON from the generated text or markdown blocks, validates it against the schema, and retries with validation feedback until the output is valid or the attempt limit is reached.

If your application cannot parse or validate the result, follow the invalid JSON troubleshooting guide before increasing the retry budget.

Choose a field #

FieldValidationUse when
response_schemaAIVAX validates the output and retries with feedback (JSON Healing).Any model, including models without native structured output, and responses that use tools before the JSON.
response_format with json_schemaThe provider enforces the schema natively; AIVAX also heals when healing_options is set or automatic JSON Healing is enabled on the account.The model supports native structured output and you want the provider to constrain generation.
json_onlyReturns only the final JSON, without the chat completion envelope.The consumer is a program that expects a bare JSON body; see JSON-only.

With tools or reasoning, the model can call tools and reason first; the JSON is extracted from the final answer only. See Reasoning and tools.

Structured output fields are not available with public API keys. When the attempt limit is reached, the request fails with 503 Service Unavailable; see JSON Healing.

Type to search the documentation.