テーマ
言語

構造化出力

response_formatでJSON出力を強制します。モードは2つあります: json_object(任意の有効なJSON)とjson_schema(厳密なスキーマ準拠)です。curlとPythonの例を掲載しています。

response_format パラメータはモデルに有効な JSON を返すよう強制します。2 つのモードに対応しています。

json_object mode

モデルは出力が有効な JSON であることを保証します。構造はシステムプロンプトで定義します。

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

厳密な JSON Schema 準拠 — モデルは指定されたフィールドを正確に埋めます。GPT-5.x および互換モデルで対応しています。

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 を指定すると、ゲートウェイはスキーマを実際に遵守するモデルバリアントにのみリクエストをルーティングし、それをすべての試行で行います — バックアップサプライヤーへの切り替え時も含みます。現在適切なバリアントが利用できない場合は、JSON を要求したのにプレーンテキストが返るのではなく、明示的な structured_output_unsupported エラーが返ります。このガードは測定結果に基づいて構築されており、測定済みのバリアントのみを対象としています。未測定のバリアントでは、サプライヤーがスキーマを黙って破棄する可能性があります。
JSON をどの程度保持できるかはモデルによって異なります — ご利用のモデルを確認してください。 2026-09-12 に deepseek-v4-flash-0731 で測定、各セル10回呼び出し: json_object は :cxa と :cxbc のバリアントで 10/10、:network で 8/10 をパースしました。一方、厳密な json_schema は両方のバリアントで 0/10(:cxa は 400 を返し、:cxbc はプレーンテキストで 200 を返します)、:network で 3/10 でした。DeepSeek 自身の API には json_schema モードがないため、json_object を使用してください。正確に1つの形が必要な場合は、強制関数呼び出し(tools + tool_choice)がすべてのバリアントでパース可能な引数を 10/10 で返しました。バリアントごとの数値は GET /v1/model-capabilities の structuredOutput フィールドにあります。いずれもその日付(measurement: "point-in-time")が付された一度きりの測定値であり、保証ではありません。バリアントを提供するサプライヤーは変更される可能性があり、定期的な再測定は行っていません。

レスポンス例

{
  "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