Skip to content

feat (provider/gateway): add provider routing sort options#14311

Merged
shaper merged 1 commit intomainfrom
04-09-feat_provider_gateway_add_sort_options
Apr 11, 2026
Merged

feat (provider/gateway): add provider routing sort options#14311
shaper merged 1 commit intomainfrom
04-09-feat_provider_gateway_add_sort_options

Conversation

@shaper
Copy link
Copy Markdown
Collaborator

@shaper shaper commented Apr 10, 2026

Background

The AI Gateway provider needed the ability to sort providers by performance and cost metrics to optimize routing decisions based on specific criteria like cost efficiency, response speed, or throughput.

Changes

Added a new sort option to the AI Gateway provider that allows sorting providers by:

  • 'cost' - lowest input cost per token first
  • 'ttft' - lowest time-to-first-token first
  • 'tps' - highest tokens-per-second first

When specified, the gateway tries the best-scoring provider first and falls back through the rest in sorted order. When combined with the existing order option, user-specified providers are promoted to the front while remaining providers follow the sorted order.

Manual Verification

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Copy link
Copy Markdown
Collaborator Author

shaper commented Apr 10, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@tigent tigent Bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/gateway Issues related to the @ai-sdk/gateway provider labels Apr 10, 2026
@shaper shaper force-pushed the 04-09-feat_provider_gateway_add_sort_options branch from 98d80f4 to e08b30d Compare April 10, 2026 02:32
@shaper shaper force-pushed the 04-09-feat_provider_gateway_add_sort_options branch from e08b30d to f0ed336 Compare April 10, 2026 02:42
@shaper shaper changed the title feat (provider/gateway): add sort options feat (provider/gateway): add provider routing sort options Apr 10, 2026
@shaper shaper marked this pull request as ready for review April 10, 2026 02:43
@shaper shaper force-pushed the 04-09-feat_provider_gateway_add_sort_options branch from f0ed336 to f4f0cc0 Compare April 10, 2026 02:49
@shaper shaper force-pushed the 04-09-feat_provider_gateway_add_sort_options branch from f4f0cc0 to a5a005e Compare April 10, 2026 02:49
@shaper shaper merged commit 6b0a40d into main Apr 11, 2026
19 checks passed
@shaper shaper deleted the 04-09-feat_provider_gateway_add_sort_options branch April 11, 2026 00:13
@ghost
Copy link
Copy Markdown

ghost commented Apr 11, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.83
@ai-sdk/amazon-bedrock 5.0.0-beta.29
@ai-sdk/angular 3.0.0-beta.83
@ai-sdk/anthropic 4.0.0-beta.25
@ai-sdk/gateway 4.0.0-beta.46
@ai-sdk/google-vertex 5.0.0-beta.43
@ai-sdk/langchain 3.0.0-beta.83
@ai-sdk/llamaindex 3.0.0-beta.83
@ai-sdk/otel 1.0.0-beta.29
@ai-sdk/react 4.0.0-beta.83
@ai-sdk/rsc 3.0.0-beta.84
@ai-sdk/svelte 5.0.0-beta.83
@ai-sdk/vue 4.0.0-beta.83

@shaper shaper added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 16, 2026
ghost pushed a commit that referenced this pull request Apr 16, 2026
## Background

The AI Gateway provider needed the ability to sort providers by performance and cost metrics to optimize routing decisions based on specific criteria like cost efficiency, response speed, or throughput.

## Changes

Added a new `sort` option to the AI Gateway provider that allows sorting providers by:

- `'cost'` - lowest input cost per token first
- `'ttft'` - lowest time-to-first-token first
- `'tps'` - highest tokens-per-second first

When specified, the gateway tries the best-scoring provider first and falls back through the rest in sorted order. When combined with the existing `order` option, user-specified providers are promoted to the front while remaining providers follow the sorted order.

## Manual Verification

## Checklist

- [ ] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)
@ghost ghost removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 16, 2026
@ghost
Copy link
Copy Markdown

ghost commented Apr 16, 2026

✅ Backport PR created: #14508

ghost pushed a commit that referenced this pull request Apr 16, 2026
…14508)

This is an automated backport of #14311 to the release-v6.0 branch. FYI
@shaper

---------

Co-authored-by: Walter Korman <shaper@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/gateway Issues related to the @ai-sdk/gateway provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants