स्ट्रक्चर्ड आउटपुट

स्ट्रक्चर्ड आउटपुट

response_format मॉडल को सादे पाठ के बजाय JSON में जवाब देने के लिए कहता है। इस्तेमाल करें json_schemaजब आपके पास लागू करने के लिए कोई आकार हो, और json_object जब आपको केवल वैध JSON की आवश्यकता हो।

पैरामीटरटाइपआवश्यकविवरण
response_formatobjectवैकल्पिकआउटपुट अनुबंध। फ़ॉर्म्स:{type:"text"}{type:"json_object"}{type:"json_schema", json_schema:{name, schema, strict}}
import json, os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OXYY_API_KEY"],
    base_url="https://api.oxyy.ai/v1"
)

response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Extract the invoice fields."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "invoice",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "total": {"type": "number"},
                    "currency": {"type": "string"},
                },
                "required": ["total", "currency"],
                "additionalProperties": False,
            },
        },
    },
)

data = json.loads(response.choices[0].message.content)
# json_object is the looser mode: valid JSON, no schema enforced.
curl https://api.oxyy.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OXYY_API_KEY" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role": "user", "content": "List 3 colours as JSON."}],
    "response_format": {"type": "json_object"}
  }'
बनावट से ही पोर्टेबल। जिन प्रदाताओं में नेटिव स्कीमा मोड नहीं है, उन्हें इसके बजाय एक फोर्सड आउटपुट टूल दिया जाता है, और उत्तर आपके लिए अनरैप किया जाता है — जिसमें हटाना शामिल है ```json fence कुछ models जोड़ते हैं। किसी भी तरह choices[0].message.content एक JSON दस्तावेज़ है जिसे आप पार्स कर सकते हैं। strict: true पूरी तरह से बंद schema चाहिए (additionalProperties: false और इसमें प्रत्येक प्रॉपर्टी required); leave it off if yours is not.