Capabilities
Structured output
Constrain replies to JSON with response_format on the OpenAI surface
Use response_format on /v1/chat/completions to make the model return JSON instead of free text.
from openai import OpenAI
import json
client = OpenAI(
base_url="https://api.ablatic.ai/v1",
api_key="sk-ablatic-...",
)
resp = client.chat.completions.create(
model="talos",
messages=[{"role": "user", "content": "Extract the city and country from: Linz, Austria"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "location",
"schema": {
"type": "object",
"properties": {
"city": {"type": "string"},
"country": {"type": "string"},
},
"required": ["city", "country"],
},
},
},
)
data = json.loads(resp.choices[0].message.content)
print(data["city"], data["country"])Modes
response_format accepts three values:
textreturns plain text. This is the default.json_objectreturns a JSON object with no schema constraint.json_schemareturns JSON that follows the schema you supply.
Not available on the Anthropic surface
response_format works only on the OpenAI surface. On /v1/messages the field is not honored, so structured outputs are not available there. To constrain output shape with the Anthropic SDK, use a tool with an input_schema and read the tool_use.input object.
response_format has no effect on /v1/messages. Use the OpenAI surface for structured JSON output.