Skip to main content
Give the model a JSON schema and it answers with a JSON object that follows it. Your code parses the answer instead of pulling fields out of free text.
The answer is a JSON string such as {"city": "Lisbon", "country": "Portugal"}, which the example parses and prints.

Schema options in each format

Each format puts the schema in its own field and returns the JSON in its own place: JSON mode, json_object, asks for valid JSON without a schema. Say in the prompt that you want JSON when you use it, since some models need the hint. The SDK helpers client.responses.parse() and client.chat.completions.parse() build the same request from a Pydantic or Zod model, and they work against NagaAI too.

Models without schema support

Check parameters of the model’s chat operation in /v1/models for response_format. The list covers every provider that serves the model, so the provider that takes a given request can still lack schema support. In that case NagaAI asks the provider for JSON mode and adds your schema to the prompt. The answer is still JSON, but nothing guarantees it follows the schema, so validate it in your code before you use it.