AI Gateway でプロバイダーをコスト、レイテンシ、スループット順に並べ替え可能に
Vercel は AI Gateway にコスト、レイテンシ、スループットに基づく動的ソート機能を追加し、リクエストごとの最適化を可能にした。
キーポイント
動的なプロバイダソート機能の導入
AI Gateway で、コスト(最低価格)、TTFT(最小レイテンシ)、TPS(最大スループット)のいずれかを基準にプロバイダをリアルタイムで並べ替え可能になった。
コード変更不要な自動最適化
ソート計算はリクエスト時に実行されるため、価格変動や新しいプロバイダの追加、パフォーマンス変化に対して即時に対応し、コード修正を必要としない。
既存ルーティング機能との統合
ゼロデータ保持(ZDR)フィルタリングや明示的な順序指定(order)と組み合わせることで、セキュリティ要件を満たしつつ性能を最適化する複合制御が可能になる。
影響分析・編集コメントを表示
影響分析
この機能により、企業は固定されたルーティングルールに縛られず、コストとパフォーマンスのトレードオフを動的に管理できるようになります。特に複数のプロバイダが競合する環境や価格変動が激しい市場において、運用コストの削減とユーザー体験の向上を両立させる重要な手段となります。
編集コメント
マルチプロバイダ構成が一般的になる中で、単なる冗長化から「状況に応じた最適選定」へパラダイムシフトを促す実用的なアップデートです。開発者が複雑なロジックを書かずにコストと速度のバランスを調整できる点は非常に評価できます。
AI Gateway では、モデル背後のプロバイダーをコスト、最初のトークンまでの時間 (TTFT)、またはスループット (TPS) で並べ替えることができるようになりました。
デフォルトのプロバイダー順序は、プロバイダーの信頼性、モデル出力の品質、コスト、応答速度を組み合わせたものです。現在は sort を使用して、ランキング基準を明示的に制御できるようになりました。
多数のプロバイダーがあり、コストや速度に顕著なばらつきがあるモデルの場合、sort を使用して選択した次元で最適化できます。ランキングはリクエスト時に計算されるため、新たに追加されたプロバイダー、価格変更、観測されるレイテンシまたはスループットの変化も、コードの変更なしに自動的に反映されます。
providerOptions.gateway に sort を設定し、以下の 3 つの値のいずれかを指定してください:
Value
Description
Direction
When to use
'cost'
プロバイダーがリストした百万トークンあたりの入力価格で並べ替え
最安値から
高ボリュームでコストに敏感なワークロード
'ttft'
最初のトークンまでの中央値時間 (ミリ秒) で並べ替え
最小レイテンシから
応答速度が重要なレイテンシ敏感型ワークロード
'tps'
1 秒あたりのトークン数スループットの中央値で並べ替え
最高値から
総応答時間が最も重要となる長文生成
基本的な使用方法
sort を使用して、選択した指標の最適化を確実に実行します。
この例では、GPT OSS 120B には価格が異なる 5 つ以上のプロバイダーが存在するため、コストで並べ替えることは、最安値のプロバイダー経由でルーティングしたいリクエストにとって有用なオプションです。
プロバイダーは並べ替え順に試行されます。上位ランクのプロバイダーが利用できない場合にのみ、次のプロバイダーへフォールバックします。
他のルーティング制御と組み合わせる
sort は、ゼロデータ保持(ZDR)などの他のゲートウェイのルーティングオプションと互換性があります。
以下の例では、遅延とデータ保持が重要なインタラクティブなリクエストに対して deepseek/deepseek-v4-pro を使用します。AI Gateway は、まずゼロデータ保持を持つ Deepseek V4 Pro のプロバイダーのみをフィルタリングし、その後、残りのプロバイダーを最初のトークンまでの時間(TTFT)でソートします。
sort は order と組み合わせることも可能です。リストされた順序のプロバイダーが最前面に優先され、残りのプロバイダーは要求されたソート基準に従います。
ルーティング判断の検証
各リクエストがなぜ特定の場所に振り分けられたのかを正確に確認できます。すべてのレスポンスには、ルーティングメタデータ内に sort ブロックが含まれており、考慮されたプロバイダー、ランク付けに使用されたメトリック値、試行された順序、および健康状態の低下により優先度が下げられたプロバイダーが示されます。
AI Gateway によるソートに関する詳細については、ドキュメントをご覧ください。
続きを読む
原文を表示
You can now sort the providers behind a model by cost, time to first token (TTFT), or throughput (TPS) in AI Gateway.
The default provider order blends provider reliability, quality of model output, cost, and speed of response. You can now use sort for explicit control over ranking criteria.
For models with many providers and noticeable cost or speed variation, you can use sort to optimize on your dimension of choice. Ranking is computed at request time, so newly added providers, price changes, and shifts in observed latency or throughput flow through automatically without any code changes.
Set sort on providerOptions.gateway to one of the three values:
Value
Description
Direction
When to use
'cost'
Sort by the provider's listed input price per million tokens
Lowest price first
High-volume, cost-sensitive work
'ttft'
Sort by median time to first token, in ms
Lowest latency first
Latency-sensitive workloads where response speed matters
'tps'
Sort by median tokens per second throughput
Highest first
Long-output generation where total response time matters most
Basic usage
Use sort to ensure optimizing for your metric of choice.
In this example, AI Gateway has over five providers for GPT OSS 120B with different prices, so sorting by cost is a useful option for requests that want to route through the lowest price provider.
Providers are tried in sort order. Fallback to the next provider only happens when the higher-ranked one is unavailable.
Combine with other routing controls
sort is compatible with other gateway routing options like Zero Data Retention (ZDR).
The example below uses deepseek/deepseek-v4-pro for an interactive request where latency and data retention matter: AI Gateway filters to only providers for Deepseek V4 Pro that have zero data retention, and then sorts the remaining providers by time to first token (TTFT).
sort also composes with order: providers listed in order are promoted to the front, and the remaining providers follow the requested sort criterion.
Inspecting routing decisions
See exactly why each request landed where it did. Every response includes a sort block in the routing metadata showing which providers were considered, the metric values used to rank them, the order they were attempted, and any that were deprioritized due to degraded health.
For more information on sorting via AI Gateway, read the documentation.
Read more
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み