Skip to content

Conversation

ben-vargas
Copy link

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

- Add GatewayOptions type for order/only configuration
- Create extractGateway helper function for DRY code
- Support both provider-level and model-level gateway config
- Model config overrides provider defaults
- Enables per-model routing strategies for Vercel AI Gateway
@ben-vargas ben-vargas force-pushed the feat-vercel-order-only-support branch from 067bd08 to 28e4eee Compare August 22, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add Vercel AI Gateway Provider Routing Support (only and order filters)
1 participant