Structured output: validate, do not assume
Use JSON Schema output only where the catalogue reports support, and validate every answer locally.
Also available as Markdown · all agent guides in one file
Key points
- Aether forwards
response_format,text.formatoroutput_config.format, but does not validate or enforce the schema itself. - Send a schema option only when
structured_outputs.json_schemaissupported; otherwise request JSON in the prompt. - Validate every answer locally, even when support is reported.
For regular API keys, the proxy forwards response_format (Chat Completions), text.format (Responses) or output_config.format (Messages) to the provider. Aether does not validate or enforce the schema itself. Do not infer support from OpenAI-compatible request syntax.
Check support first
- Check
capabilities[endpoint].structured_outputs.json_schemain model discovery. supportedmeans every possible fallback confirms schema-constrained output and Aether preserves it; it does not promise every JSON Schema keyword, and nojson_objectmode is implied.- With unsupported or unknown, do not send the option. Request JSON in the prompt and validate the result locally instead.
- Prompting for JSON is not constrained decoding and can fail; reject invalid or truncated output and bound any repair attempts.
Always validate
Validate even when support is reported.Validate a text answer before using it
This Node.js example uses the same regular API-key environment as the quickstart. It deliberately relies on no unverified response_format option. Save as structured-output.mjs. A validation error is an expected failure mode and must stop downstream actions.
const apiKey = process.env.AETHER_API_KEY;
const model = process.env.AETHER_MODEL;
if (!apiKey || !model) throw new Error("Set AETHER_API_KEY and AETHER_MODEL");
const response = await fetch("https://api.aetherapi.dev/v1/chat/completions", {
method: "POST",
headers: { Authorization: "Bearer " + apiKey, "Content-Type": "application/json" },
body: JSON.stringify({ model, messages: [{ role: "user",
content: 'Return only a JSON object with exactly one field: "summary" (a string). Summarize: The sky is blue.' }] }),
});
const result = await response.json();
if (!response.ok || result.error) throw new Error("Request failed");
if (result.choices?.[0]?.finish_reason !== "stop") throw new Error("Incomplete output");
const value = JSON.parse(result.choices[0].message.content);
if (!value || Array.isArray(value) || typeof value !== "object"
|| Object.keys(value).length !== 1 || typeof value.summary !== "string") {
throw new Error("Invalid summary schema");
}
console.log(value.summary);The sandbox can rehearse json_schema output for Chat Completions, Responses and Messages with a bounded schema subset (see the sandbox document). It returns a value generated from the schema, not model output, so it cannot establish live support or semantic accuracy.