cookbook/Architectural Patterns
Strict Structured JSON Outputs
Guarantee machine-readable JSON schemas without markdown fences or hallucinations.
Enforcing response_format: { type: 'json_object' }
from openai import OpenAI
client = OpenAI(
base_url="https://unlockedai.net/v1",
api_key="<YOUR_UNLOCKED_API_KEY>",
)
response = client.chat.completions.create(
model="claude-sonnet-5.5",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "You are a JSON emitter. Return ONLY valid JSON conforming to {users: string[], count: number}."},
{"role": "user", "content": "Generate a list of 3 imaginary beta testers."}
]
)
print(response.choices[0].message.content)Need an Unlocked AI Key or Credits?
Generate secret API keys backed by non-expiring pay-as-you-go credits starting at $5. No monthly minimums.