import json
reply = client.chat.completions.create(
model="a1",
messages=[{"role": "user", "content": "Capital and population (millions) of Saudi Arabia?"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "country",
"strict": True,
"schema": {
"type": "object",
"properties": {"capital": {"type": "string"}, "population_millions": {"type": "number"}},
"required": ["capital", "population_millions"],
"additionalProperties": False,
},
},
},
)
data = json.loads(reply.choices[0].message.content)