POST/v1/chat/completions

チャット補完を作成

OpenAI Chat Completions APIです。Server-Sent Eventsを受け取るにはstream: trueを設定し、最後のusageフレームを受け取るにはstream_options.include_usage: trueを追加します。

各モデルはプロバイダーのルートのチェーンで提供されます。ルートが失敗した場合は出力の送信前にフェイルオーバーし、トップレベルのproviderが応答したプロバイダーを示します。処理中のルートが対応できないフィールドは破棄されてx-experiential-ignored-parametersに示され、どのルートも対応できないフィールドは400になります。

認証: AuthorizationヘッダーにBearer形式のAPIキー

ヘッダー

  • Idempotency-Keystring

    同じリクエスト(再試行を含む)ごとに一意な文字列。同じキーとボディで再試行すると、再実行せずに最初の結果をそのまま返します。同じキーでボディが異なる場合は409を返します。キーを指定したレスポンスにはusage.costが含まれません(再送する結果をバイト単位で同一にするため)。

リクエストボディ

  • modelstring必須

    GET /v1/modelsで取得したスラッグ。<vendor>/<slug>(例:openai/gpt-6-luna)と、無料プロモーションの対象である場合は<slug>:freeも別表記として受け付けます。

  • messagesarray<object>必須

    会話。ロールはsystem、developer、user、assistant、tool。

  • streamboolean

    Server-Sent Eventsをストリーミングします。

    既定値: false
  • stream_optionsobject

    {"include_usage": true}を指定すると、usage(costを含む)が入った最後のチャンクが追加されます。

    stream_options
    • include_usageboolean
  • max_completion_tokensinteger

    出力の上限。max_tokensも受け付け、両方ある場合は小さい方が優先されます。モデルの最大値を超える上限は最大値まで下げられ、その旨が通知されます。

  • temperaturenumber

    リクエストを処理するルートがより狭い範囲しか受け付けない場合はその範囲内に収められ、サンプリングを行わないルートでは破棄されます。

  • top_pnumber
  • stopstring | array<string>

    停止文字列(プロバイダーの上限数まで)。

  • toolsarray<object>

    関数ツール。使用頻度の低いツールにdefer_loading: trueを付け、{"type": "openrouter:tool_search"}エントリと並べると、ゲートウェイが必要に応じて検索します。

  • tool_choicestring | object

    auto、none、required、または名前付きの関数。

  • response_formatobject

    {"type": "json_object"}または{"type": "json_schema", "json_schema": {...}}。リクエストを構造化出力のルートに振り分けます。モデルに該当ルートがない場合はunsupported_capabilityで拒否されます。

  • reasoning_effortstring

    モデルのsupported_reasoning_effortsのいずれか。未対応のeffortは最も近い値に置き換えられ、その旨が通知されます。

  • web_search_optionsobject

    Web検索を要求します。プロバイダーが検索に対応している場合はネイティブに実行し、それ以外はゲートウェイが検索して出典を示します。

  • prompt_cache_keystring

    キャッシュアフィニティのためのルーティングヒント。キャッシュを保証するものではありません。

  • userstring

    お客様側での識別用のエンドユーザーID。

  • providerobject

    OpenRouterのルーティング設定オブジェクトで、モデル自身のプロバイダールートに対して解決されます。組織のポリシーを厳しくすることはあっても、緩めることはありません。

    provider
    • zdrboolean

      trueの場合、このリクエストはゼロデータ保持のルートのみで提供されます。満たせない場合は除外されたプロバイダーを示す403で拒否されます。

    • onlyarray<string>

      これらのプロバイダーのみを使います。

    • ignorearray<string>

      これらのプロバイダーを除外します。

    • orderarray<string>

      これらのプロバイダーを順に優先し、残りはフォールバックとして使います。

    • allow_fallbacksboolean

      orderとともにfalseを指定すると一覧のプロバイダーのみで提供します。orderがない場合は最初の対象ルートのみです。

  • gatewayobject

    リクエストごとの再試行とルーティングの上限。プロバイダーには送信されません。SDKではextra_bodyで送信します。

    gateway
    • retryobject
      retry
      • max_attempts_per_routeinteger

        ルートごとの呼び出し回数(初回を含む)。既定値は2。

      • max_total_attemptsinteger

        再試行とフォールバックを含む呼び出しの合計回数。既定値は8。

      • backoffobject

        {"type": "none"}または{"type": "exponential", "base_delay_ms", "max_delay_ms", "multiplier"}(既定値は500、8000、2)。

    • routingobject
      routing
      • allow_fallbacksboolean

        falseの場合は最初の対象ルートを維持し、フェイルオーバーしません。

        既定値: true
      • route_idstring

        不透明なハンドル(route_ + 16進数64桁)でルートを固定します。ハンドルはGET /api/models/{slug}/providersから取得します。

レスポンス

  • 200

    補完。streamを設定した場合は、data [DONE]で終わるchat.completion.chunkイベント。

    レスポンス
    • idstring
    • objectstring
    • createdinteger
    • modelstring
    • providerstring

      Experientialの拡張。このリクエストを処理したプロバイダー。

    • choicesarray<object>
    • usageany

      OpenAIのusageにExperientialのフィールドを加えたもの。

      usage
      • prompt_tokensinteger
      • completion_tokensinteger
      • total_tokensinteger
      • prompt_tokens_detailsobject
        prompt_tokens_details
        • cached_tokensinteger
      • completion_tokens_detailsobject
        completion_tokens_details
        • reasoning_tokensinteger
      • costnumber

        このリクエストでクレジットから実際に課金されたUSD(浮動小数点数、プロモーションとプランの割引の適用後)。独自キーの場合は0。

      • is_byokboolean

        お客様自身のプロバイダーキー(独自キー)で実行された場合はtrue。独自キーの呼び出しはプラットフォームが課金しません。

      • cost_detailsobject

        次の2つの場合にのみ含まれます。upstream_inference_cost(USD。独自キーの場合に、プロバイダーが定価でお客様に請求する額)、またはlist_cost(USD。プラットフォーム負担の呼び出しが定価未満で課金された場合に、本来かかった額)。

        cost_details
        • upstream_inference_costnumber
        • list_costnumber
    • x-experiential-ignored-parametersarray<string>

      ゲートウェイがリクエストを変更した場合に含まれます。各エントリはフィールドと処理内容を示します。例:temperature->dropped(unsupported_by_provider)、max_tokens->32768(route_maximum)。

  • 400

    不正なリクエスト。paramはフィールド名を、codeは理由(invalid_parameter、unsupported_parameter、unsupported_capability、refusal、previous_response_not_found)を示します。課金されません。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 401

    キーがないか、形式が不正か、期限切れか、取り消されています。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 402

    組織での対応が先に必要です(card_required、email_unverified、org_under_review、free_tier_requires_payment、promotion_ended)。メッセージに手順が示されます。再試行しても解決しません。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 403

    model_not_granted(GET /v1/modelsのIDを使ってください)、model_location_not_supported、またはどのルートも満たせないゼロデータ保持の要求。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 409

    Idempotency-Keyが異なるボディで再利用されたか、元の結果がすでにありません。新しいキーを使ってください。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 429

    insufficient_quota(クレジット不足、支出上限の超過、またはモデルに購入が必要)とpromo_credits_now(無料プロモーションの使い切り):クレジットを追加してください。メッセージに手順が示されます。rate_limit_exceeded、free_limit_reached、admission_capacity_exceeded:Retry-Afterの秒数だけ待って再試行してください。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 502

    出力前にすべてのプロバイダールートが失敗しました(all_routes_failed)。バックオフを入れて再試行してください。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"
  • 503

    gateway_unavailable、gateway_draining、unavailable_route、deadline_exceededのいずれか。バックオフを入れて再試行し、Retry-Afterがある場合はそれに従ってください。

    レスポンス
    • errorobject
      error
      • messagestring

        問題の内容と解決方法。

      • typestring

        例:invalid_request_error、authentication_error、permission_error、rate_limit_error、insufficient_quota、api_error。

      • codestring

        安定したエラーコード。

      • paramstring | null

        該当する場合、問題のあるリクエストフィールド。

      • refusal_reasonenum

        code: refusalの場合にのみ含まれます。

        "cyber_policy""cbrn""content_policy""recitation""data_inspection""unspecified"

リクエスト

curl https://api.experientiallabs.ai/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-luna",
    "messages": [{"role": "user", "content": "Write a haiku about latency."}]
  }'

レスポンス

{
  "id": "chatcmpl_5d0f3b8e2a7c41e9b6f1a4c8d2e7f903",
  "object": "chat.completion",
  "created": 1795132800,
  "model": "gpt-6-luna",
  "provider": "openai",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Packets cross the sea,\nmilliseconds pile like snow,\nthe spinner turns on."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 21,
    "total_tokens": 45,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "cost": 0.0000129,
    "is_byok": false
  }
}

https://api.experientiallabs.ai/v1/chat/completions