text.format to constrain the model’s output to a specific structure. The schema definition matches Chat Completions; the parameter path differs.
Prerequisites
- An Auriko API key
- Python 3.10+ with the OpenAI SDK (
pip install openai) or the Auriko SDK (pip install auriko)- OR Node.js 18+ with the OpenAI SDK (
npm install openai) or@auriko/sdk(npm install @auriko/sdk)
- OR Node.js 18+ with the OpenAI SDK (
Return JSON
Constrain the output to valid JSON:import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AURIKO_API_KEY"],
base_url="https://api.auriko.ai/v1"
)
response = client.responses.create(
model="gpt-4o",
input="List 3 programming languages and their main use cases. Respond in JSON.",
text={"format": {"type": "json_object"}}
)
print(response.output_text)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AURIKO_API_KEY,
baseURL: "https://api.auriko.ai/v1",
});
const response = await client.responses.create({
model: "gpt-4o",
input: "List 3 programming languages and their main use cases. Respond in JSON.",
text: { format: { type: "json_object" } },
});
console.log(response.output_text);
import os
from auriko import Client
client = Client(
api_key=os.environ["AURIKO_API_KEY"],
base_url="https://api.auriko.ai/v1"
)
response = client.responses.create(
model="gpt-4o",
input="List 3 programming languages and their main use cases. Respond in JSON.",
text={"format": {"type": "json_object"}}
)
print(response.output_text)
import { Client } from "@auriko/sdk";
const client = new Client({
apiKey: process.env.AURIKO_API_KEY,
baseUrl: "https://api.auriko.ai/v1",
});
const response = await client.responses.create({
model: "gpt-4o",
input: "List 3 programming languages and their main use cases. Respond in JSON.",
text: { format: { type: "json_object" } },
});
console.log(response.output_text);
curl https://api.auriko.ai/v1/responses \
-H "Authorization: Bearer $AURIKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"input": "List 3 programming languages and their main use cases. Respond in JSON.",
"text": {"format": {"type": "json_object"}}
}'
json_object constraint.
Enforce schema
Constrain the output to a specific JSON Schema:import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AURIKO_API_KEY"],
base_url="https://api.auriko.ai/v1"
)
response = client.responses.create(
model="gpt-4o",
input="Extract contact info: John Doe, john@example.com, 555-0123",
text={
"format": {
"type": "json_schema",
"name": "contact_info",
"strict": True,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["name", "email", "phone"],
"additionalProperties": False
}
}
}
)
print(response.output_text)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AURIKO_API_KEY,
baseURL: "https://api.auriko.ai/v1",
});
const response = await client.responses.create({
model: "gpt-4o",
input: "Extract contact info: John Doe, john@example.com, 555-0123",
text: {
format: {
type: "json_schema",
name: "contact_info",
strict: true,
schema: {
type: "object",
properties: {
name: { type: "string" },
email: { type: "string" },
phone: { type: "string" },
},
required: ["name", "email", "phone"],
additionalProperties: false,
},
},
},
});
console.log(response.output_text);
import os
from auriko import Client
client = Client(
api_key=os.environ["AURIKO_API_KEY"],
base_url="https://api.auriko.ai/v1"
)
response = client.responses.create(
model="gpt-4o",
input="Extract contact info: John Doe, john@example.com, 555-0123",
text={
"format": {
"type": "json_schema",
"name": "contact_info",
"strict": True,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["name", "email", "phone"],
"additionalProperties": False
}
}
}
)
print(response.output_text)
import { Client } from "@auriko/sdk";
const client = new Client({
apiKey: process.env.AURIKO_API_KEY,
baseUrl: "https://api.auriko.ai/v1",
});
const response = await client.responses.create({
model: "gpt-4o",
input: "Extract contact info: John Doe, john@example.com, 555-0123",
text: {
format: {
type: "json_schema",
name: "contact_info",
strict: true,
schema: {
type: "object",
properties: {
name: { type: "string" },
email: { type: "string" },
phone: { type: "string" },
},
required: ["name", "email", "phone"],
additionalProperties: false,
},
},
},
});
console.log(response.output_text);
curl https://api.auriko.ai/v1/responses \
-H "Authorization: Bearer $AURIKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"input": "Extract contact info: John Doe, john@example.com, 555-0123",
"text": {
"format": {
"type": "json_schema",
"name": "contact_info",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["name", "email", "phone"],
"additionalProperties": false
}
}
}
}'
Map parameters
| Chat Completions | Response API |
|---|---|
response_format: {type: "json_object"} | text: {format: {type: "json_object"}} |
response_format: {type: "json_schema", json_schema: {name, schema}} | text: {format: {type: "json_schema", name, schema}} |
json_schema.schema. In the Response API, it’s under format.schema (one less level of nesting).
See Structured Output guide for model support and strict parameter behavior.