Structured output
Structured output makes the model answer with JSON. Send an answer format with the request, as in the example below.
The exchange sends the request only to offers that support the format. When the job ends, it checks the answer against the format and reports the verdict.
Send an answer format
Send response_format on POST /v1/chat/completions:
curl https://router.inference.ai.exchange/v1/chat/completions \
-H "Authorization: Bearer $LIQUID_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-oss-120b",
"messages": [{"role": "user", "content": "Extract the invoice: ACME, due 2026-11-01, 1200 USD"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "invoice",
"strict": true,
"schema": {
"type": "object",
"properties": {
"vendor": {"type": "string"},
"due": {"type": "string"},
"amount": {"type": "number"}
},
"required": ["vendor", "due", "amount"],
"additionalProperties": false
}
}
}
}'
| Endpoint | Field |
|---|---|
POST /v1/chat/completions |
response_format |
POST /v1/messages |
output_config.format |
POST /v1/responses |
text.format |
type |
The answer must be |
|---|---|
json_object |
One JSON value. |
json_schema |
One JSON value that matches your schema. |
The schema name must use 1 to 64 letters, digits, _ or -.
Only an offer that declares support for the format can win the job. If no offer does, the call gets no_eligible_offer. A dry run names feature_unsupported for each offer that it leaves out.
Read the verdict
The exchange checks the text of the answer when the job ends. The verdict is in exchange.answer_checks.structured_output, on the last chunk of a stream. The results, such as passed, not_json and schema_mismatch, are in Errors.
What happens after a failed check depends on streaming:
- No stream. If the answer is
not_jsonorschema_mismatch, the exchange drops it and sends the job to the next offer. - Stream. A failed check does not change the job. You receive the answer and you pay for it.
The exchange records the verdict for the deployment that served the job. A deployment that breaks the format often gets a higher bad-answer rate. The exchange ranks a request with a format by that rate, unless the request sets exchange.rank.failure_risk_ranking to false. See Fewest redos.
Whitespace without end
Some models write whitespace until max_tokens under a schema, for example after a key with a boolean value. The exchange stops an answer that writes more than 1,024 whitespace characters in a row outside a JSON string. The failure counts against the deployment.
- No stream. The job goes to the next offer.
- Stream. The job fails with
provider_failed. You pay nothing, and you keep the text that you already received.
Try a format in the playground
The playground sends the format, shows the verdict and lists each problem, so you can fix a schema before you use it in code.
- Open the Request tab of a chat. Find Answer format.
- Choose Text, JSON object or JSON schema.
- For JSON schema, give the schema a name. Build the schema as a list of fields, or choose Edit as JSON and write it. To start from a sample, choose Infer from an example and paste one answer.
- Turn Strict on to require every field. An optional field then accepts
null. - Send the message.
A schema opens as fields only when the field list can write back the same schema. Otherwise it stays as JSON, and a note names each part that the list cannot show.
The answer shows as a record with a verdict. Fields shows each field and Raw shows the text. If the answer has a schema, the record also copies that schema, so you can paste it into a new request even after you change the answer format. The playground also checks the answer in the browser against your schema. It lists every field that is wrong, with its path. The exchange verdict decides. The browser list only explains it. If the two differ, a note says so.
If a seller sent an answer that is not JSON or does not match the schema, the playground shows the bad-answer rate of that seller. You can send the question again without that seller.
The format applies to chat jobs only. If Auto turns a chat into another kind of job, the playground drops the format. A preset does not hold an answer format. A workload does.
Next steps
- Workloads: run the same prompt many times against each provider.
- Errors: every result of the check.
- Purchasing rules: rank by the chance of a good answer.