[PR #2162] feat: add Vercel AI Gateway order/only routing support #10216

Closed
opened 2026-02-16 18:14:50 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2162

State: closed
Merged: No


Summary

Changes

This PR implements the Vercel AI Gateway routing feature requested in #2153 by:

  1. Adding GatewayOptions type - Defines the structure for order and only routing configuration
  2. Creating extractGateway helper - DRY function to extract gateway options from provider or model config
  3. Supporting dual-level configuration - Gateway options can be set at:
    • Provider level (global default for all models)
    • Model level (overrides provider defaults)
  4. Integrating with existing flows - Gateway options are now passed to:
    • Initial title generation
    • Main conversation streaming
    • Session summarization

Configuration Example

Users can now configure advanced routing strategies:

{
  "provider": {
    "vercel": {
      "options": {
        "gateway": {
          "order": ["cerebras", "groq", "fireworks"],
          "only": ["cerebras", "groq", "fireworks"]
        }
      }
    }
  }
}

Or per-model overrides:

{
  "models": {
    "gpt-4o": {
      "options": {
        "gateway": {
          "only": ["openai"]
        }
      }
    }
  }
}

Benefits

  • Cost optimization: Prioritize cheaper providers with order
  • Performance: Route to fastest providers for better UX
  • Compliance: Restrict to specific geographic regions with only
  • Flexibility: Model-specific overrides for specialized use cases
  • Backward compatible: No changes required for existing configurations

Test plan

  • Gateway options extracted correctly from provider config
  • Model-level config overrides provider defaults
  • Options passed to all AI SDK calls (title, streaming, summary)
  • No impact on non-Vercel providers
  • Backward compatibility maintained
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2162 **State:** closed **Merged:** No --- ## Summary - Adds support for Vercel AI Gateway's `order` and `only` routing filters - Enables advanced provider routing strategies for cost optimization and compliance - Closes #2153 ## Changes This PR implements the Vercel AI Gateway routing feature requested in #2153 by: 1. **Adding `GatewayOptions` type** - Defines the structure for `order` and `only` routing configuration 2. **Creating `extractGateway` helper** - DRY function to extract gateway options from provider or model config 3. **Supporting dual-level configuration** - Gateway options can be set at: - Provider level (global default for all models) - Model level (overrides provider defaults) 4. **Integrating with existing flows** - Gateway options are now passed to: - Initial title generation - Main conversation streaming - Session summarization ## Configuration Example Users can now configure advanced routing strategies: ```json { "provider": { "vercel": { "options": { "gateway": { "order": ["cerebras", "groq", "fireworks"], "only": ["cerebras", "groq", "fireworks"] } } } } } ``` Or per-model overrides: ```json { "models": { "gpt-4o": { "options": { "gateway": { "only": ["openai"] } } } } } ``` ## Benefits - **Cost optimization**: Prioritize cheaper providers with `order` - **Performance**: Route to fastest providers for better UX - **Compliance**: Restrict to specific geographic regions with `only` - **Flexibility**: Model-specific overrides for specialized use cases - **Backward compatible**: No changes required for existing configurations ## Test plan - [x] Gateway options extracted correctly from provider config - [x] Model-level config overrides provider defaults - [x] Options passed to all AI SDK calls (title, streaming, summary) - [x] No impact on non-Vercel providers - [x] Backward compatibility maintained
yindo added the pull-request label 2026-02-16 18:14:50 -05:00
yindo closed this issue 2026-02-16 18:14:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10216