# JSON mode

Page: https://galatea.co/api/docs/json-mode

Ask for JSON that matches a schema, and get an object you can parse.

Set response_format to json_schema with a schema and strict set to true. The content of the answer is then JSON that matches the schema. response_format json_object asks for any valid JSON object, without a schema.

```python
import json, os
from openai import OpenAI

client = OpenAI(base_url="https://api.galatea.co/v1", api_key=os.environ["GALATEA_API_KEY"])
reply = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017-uncensored",
    messages=[{"role": "user", "content": "Give a city and its country as JSON."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "place",
            "schema": {
                "type": "object",
                "properties": {"city": {"type": "string"}, "country": {"type": "string"}},
                "required": ["city", "country"],
                "additionalProperties": False,
            },
            "strict": True,
        },
    },
)
print(json.loads(reply.choices[0].message.content))
```

Keep the schema small. A schema with additionalProperties set to false and every field in required is the most reliable shape.
