AI Gateway Sorts Providers by Cost, Latency, and Throughput
Key point
AI Gateway has added a `sort` option that sorts providers by cost, TTFT, and TPS.
Details
By default, AI Gateway determines order by jointly reflecting provider reliability, output quality, cost, and response speed, but now you can directly specify the priority criterion with sort. Put cost, ttft, or tps into providerOptions.gateway.sort.
cost: lowest listed price per 1 million input tokens firstttft: lowest median time to first token firsttps: highest median tokens per second first
Since rankings are calculated at request time, newly added providers, price changes, and changes in observed latency and throughput are automatically reflected without any code changes. For models with more than 5 providers and large cost differences, like GPT OSS 120B, you can use sort: 'cost' to try the cheapest provider first.
Providers are tried in the sorted order, and only fall back to the next provider when the top provider is unavailable. It also works together with zeroDataRetention, so for example with Deepseek V4 Pro you can first select only ZDR providers and then re-sort them by ttft. When used together with order, the specified providers are placed first, followed by the rest arranged according to the sort criterion.
The sort block in the response metadata contains the providers considered, the metric values used, the actual order attempted, and even providers pushed back due to degraded health.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.