Structured output
Ship features that need reliable JSON — extracted fields, labels, configs — without adding recovery logic. With Meta Model API you define the JSON Schema in response_format, and the model constrains decoding to match it exactly.
Understand how it works
Set response_format to type: "json_schema" and provide your schema in the json_schema field. The model constrains token generation to produce only valid JSON matching your schema. This is not post-processing: decoding itself is constrained, so the output is guaranteed to conform.
Benefits:
- Consistent format: Output always follows your defined structure, so you can drop brittle parsing logic.
- Reduced errors: No unexpected variations in response shape.
- Simpler integration: Feed model output directly to APIs, databases, or downstream services that expect structured data.
Choose the right use cases
Structured output fits tasks where shape matters:
- Extracting information: Pull names, dates, locations, or product details from unstructured text.
- Classifying data: Categorize input into predefined labels or categories.
- Generating function arguments: Produce structured arguments for downstream functions or APIs from natural language.
- Generating configurations: Create JSON configuration files from user requirements.
Using a JSON schema
Define your schema directly in response_format. The schema follows standard JSON Schema syntax.
The example below extracts an address into a structured object.
pythonimport osfrom openai import OpenAIclient = OpenAI(base_url="https://api.meta.ai/v1",api_key=os.environ["MODEL_API_KEY"],)response = client.chat.completions.create(model="muse-spark-1.3",messages=[{"role": "system","content": "Extract the address from the user input into the specified JSON format.",},{"role": "user","content": "Please format this address: 1 Hacker Wy Menlo Park CA 94025",},],response_format={"type": "json_schema","json_schema": {"name": "Address","schema": {"type": "object","properties": {"street": {"type": "string",},"city": {"type": "string",},"state": {"type": "string","description": "2-letter state abbreviation",},"zip": {"type": "string","description": "5-digit zip code",},},"required": ["street","city","state","zip",],},},},)print(response.model_dump_json(indent=2))
typescriptimport OpenAI from 'openai';const apiKey = process.env.MODEL_API_KEY;if (!apiKey) {throw new Error('MODEL_API_KEY is not set');