संरचित आउटपुट

response_format के साथ JSON output को force करें। दो modes: json_object (कोई भी valid JSON) और json_schema (strict schema conformance)। curl और Python में उदाहरण।

response_format parameter model को valid JSON लौटाने के लिए बाध्य करता है। दो modes समर्थित हैं।

json_object mode

Model गारंटी देता है कि output valid JSON है। Structure आप system prompt में तय करते हैं।

curl https://getvibeapi.com/v1/chat/completions \
  -H "Authorization: Bearer $GETVIBE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "response_format": { "type": "json_object" },
    "messages": [
      {"role": "system", "content": "Reply with JSON with fields: name (string), score (number)."},
      {"role": "user", "content": "Rate this answer: very good"}
    ]
  }'

json_schema mode

Strict JSON Schema compliance — model ठीक उन्हीं specified fields को भरता है। GPT-5.x और compatible models द्वारा समर्थित।

curl https://getvibeapi.com/v1/chat/completions \
  -H "Authorization: Bearer $GETVIBE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "review",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "score": { "type": "number", "minimum": 1, "maximum": 10 },
            "summary": { "type": "string" }
          },
          "required": ["name", "score", "summary"],
          "additionalProperties": false
        }
      }
    },
    "messages": [
      {"role": "user", "content": "Rate this product: fast delivery, careful packaging"}
    ]
  }'
strict: true के साथ gateway request को केवल उन्हीं model variants तक route करता है जो वाकई schema का पालन करते हैं, और ऐसा हर attempt पर करता है — backup supplier पर switch होने पर भी। अगर अभी कोई suitable variant उपलब्ध नहीं है तो JSON माँगे जाने पर plain text के बजाय आपको एक explicit structured_output_unsupported error मिलता है। यह guard measurements से बनाया गया है और केवल उन्हीं variants को cover करता है जिन्हें हमने measure किया है: किसी unmeasured variant पर supplier अब भी schema चुपचाप discard कर सकता है।
JSON कितनी अच्छी तरह hold होती है, इसमें models अलग-अलग हैं — अपना model जाँचें। deepseek-v4-flash-0731 पर 2026-09-12 को मापा गया, प्रति cell 10 calls: json_object ने :cxa और :cxbc variants पर 10/10 और :network पर 8/10 parse किया, जबकि एक strict json_schema ने दोनों variants पर 0/10 (:cxa जवाब 400, :cxbc जवाब 200 plain text के साथ) और :network पर 3/10 parse किया। DeepSeek के अपने API में json_schema mode नहीं है — json_object उपयोग करें, और जब आपको ठीक एक shape चाहिए, तो forced function call (tools + tool_choice) ने हर variant पर 10/10 parseable arguments लौटाए। Per-variant numbers GET /v1/model-capabilities के structuredOutput field में हैं। प्रत्येक अपनी तारीख (measurement: "point-in-time") के साथ एक one-off reading है, कोई वादा नहीं: किसी variant के पीछे का supplier बदल सकता है, और हम किसी schedule पर दोबारा माप नहीं करते।

प्रतिक्रिया उदाहरण

{
  "id": "chatcmpl-...",
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "{\"name\":\"product X\",\"score\":9,\"summary\":\"Fast and convenient\"}"
    },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 42, "completion_tokens": 18, "total_tokens": 60 }
}
GetVibe API संरचित आउटपुट — JSON Schema, json_object, Python | GetVibe API