Structured Outputs
FreshForce Mercury 2 responses to conform to a specific JSON schema.
How It Works
Set response_format with type: "json_schema" and provide a strict schema definition.
Example: Sentiment Analysis
bash
curl https://api.inceptionlabs.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INCEPTION_API_KEY" \
-d '{
"model": "mercury-2",
"messages": [
{"role": "user", "content": "Analyze the sentiment: I love this product!"}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "sentiment_analysis",
"strict": true,
"schema": {
"type": "object",
"properties": {
"sentiment": {
"type": "string",
"enum": ["positive", "negative", "neutral"]
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"key_phrases": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["sentiment", "confidence", "key_phrases"]
}
}
}
}'Python Example
python
import os
import requests
import json
response = requests.post(
"https://api.inceptionlabs.ai/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {os.environ['INCEPTION_API_KEY']}"
},
json={
"model": "mercury-2",
"messages": [
{"role": "user", "content": "Extract entities: Apple released the new MacBook Pro in Cupertino."}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "entity_extraction",
"strict": True,
"schema": {
"type": "object",
"properties": {
"entities": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string", "enum": ["person", "org", "location", "product"]}
},
"required": ["name", "type"]
}
}
},
"required": ["entities"]
}
}
}
}
)
result = json.loads(response.json()["choices"][0]["message"]["content"])
print(json.dumps(result, indent=2))Schema Requirements
- Set
"strict": truein the schema definition - Define all required properties
- Use standard JSON Schema types:
string,number,boolean,array,object - Enums are supported for constrained values
See Also
- Chat Completions — Base API reference
- Tool Use — Function calling alternative