Skip to main content
Ottili AI API

Ottili AI API — Structured outputs

How to request JSON-schema-constrained structured outputs from the public Ottili AI API.

The Ottili AI API can constrain responses to a JSON schema so you get parseable data instead of free text. Not every model supports structured outputs — check the model's capabilities first.

Request

{
  "model": "auto",
  "messages": [{ "role": "user", "content": "Extract the customer name and order total." }],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "order_summary",
      "schema": {
        "type": "object",
        "properties": {
          "customer_name": { "type": "string" },
          "order_total": { "type": "number" }
        },
        "required": ["customer_name", "order_total"],
        "additionalProperties": false
      }
    }
  }
}

Response

The assistant content is valid JSON matching the schema:

{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "{\"customer_name\":\"Acme GmbH\",\"order_total\":1299.0}"
      },
      "finish_reason": "stop"
    }
  ]
}

Notes

  • The schema must be a valid JSON Schema object; an invalid or oversized

schema returns invalid_request_error (HTTP 422).

  • Streaming is compatible with structured outputs; the final event carries the complete object.
  • If the selected model does not advertise structured_outputs in its capabilities, the API returns a clear capability error instead of an unconstrained reply.

Was this article helpful?