Skip to content

[Feature] Add model-specific upstream provider routing for Vercel AI Gateway #1406

Closed

Description

@yongs3

Area

Provider adapters

What are you trying to accomplish?

I want to route a model exposed through the vercel-ai-gateway provider to a specific underlying inference provider.

For example, zai/glm-5.2 is available through multiple upstream providers. I need to pin it to one provider, define an ordered preference list, or select providers by cost/latency/throughput while continuing to use Vercel AI Gateway for authentication, billing, observability, and fallback.

OpenCodex already supports the equivalent workflow for OpenRouter through provider-wide openRouterRouting and model-specific modelOpenRouterRouting.

What prevents this today?

Vercel AI Gateway supports request-scoped provider filtering and ordering, but OpenCodex does not currently expose or forward those options for a vercel-ai-gateway configuration.

Vercel documents:

  • order: preferred provider order
  • only: restrict routing to an allowed provider set
  • sort: rank providers by cost, ttft, or tps
  • providerOptions in the REST / OpenAI-compatible API
  • a top-level provider shorthand in the Chat Completions API

The existing OpenRouter routing configuration cannot be reused as a workaround because OpenCodex intentionally validates it against the canonical https://openrouter.ai/api/v1 endpoint and only emits the OpenRouter request payload for that target.

The Vercel dashboard also does not provide an equivalent persistent per-model routing choice for this OpenCodex workflow.

What should OpenCodex do?

OpenCodex should allow provider-wide and exact model-specific Vercel AI Gateway routing preferences.

Observable behavior:

  1. A user can restrict a Vercel-routed model to one or more underlying provider slugs.
  2. A user can define the order in which eligible providers are attempted.
  3. A user can optionally sort eligible providers by cost, ttft, or tps.
  4. Model-specific settings override provider-wide defaults.
  5. Requests without these settings preserve Vercel's current dynamic routing behavior.
  6. The preferences are forwarded using Vercel's documented OpenAI-compatible request shape.

Example usage or interface

The exact configuration names are only illustrative, but a configuration parallel to the existing OpenRouter fields would make the behavior clear:

{
  "providers": {
    "vercel-ai-gateway": {
      "adapter": "openai-chat",
      "baseUrl": "https://ai-gateway.vercel.sh/v1",
      "vercelGatewayRouting": {
        "sort": "ttft"
      },
      "modelVercelGatewayRouting": {
        "zai/glm-5.2": {
          "only": ["novita"],
          "order": ["novita"]
        }
      }
    }
  }
}

A preference list with restricted fallback could look like:

{
  "modelVercelGatewayRouting": {
    "zai/glm-5.2": {
      "only": ["novita", "deepinfra"],
      "order": ["deepinfra", "novita"]
    }
  }
}

For the OpenAI-compatible Chat Completions wire, the resulting request could use Vercel's documented shorthand:

{
  "model": "zai/glm-5.2",
  "provider": {
    "only": ["novita"],
    "order": ["novita"]
  }
}

Alternatives or workarounds

  • Accept Vercel's dynamic provider selection.
  • Configure the upstream provider directly in OpenCodex, which loses Vercel AI Gateway billing, observability, and centralized credentials.
  • Patch the openai-chat adapter locally to add a provider or providerOptions request field.
  • Use OpenRouter instead, where OpenCodex already supports provider-level routing preferences.

None provides the requested Vercel AI Gateway workflow without giving up gateway functionality or maintaining a local patch.

Additional context

Checks

  • I searched existing issues and documentation.
  • This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
  • I removed secrets and personal data.

Activity

  1. added
    enhancement
    provider
    on Aug 10, 2026
  2. Ingwannu commented on Aug 10, 2026

    @Ingwannu
    Owner

    Confirmed as a real missing capability on current dev. OpenCodex only validates and emits openRouterRouting / modelOpenRouterRouting; the canonical Vercel AI Gateway preset has no equivalent path, even though Vercel documents provider filtering, ordering, and cost / ttft / tps sorting.

    This direction is valuable, with these implementation boundaries:

    • use Vercel-specific provider-wide defaults plus exact native-model-id overrides; do not reuse or weaken the canonical OpenRouter gate;
    • validate the fields strictly and accept them only for the canonical Vercel gateway with openai-chat;
    • preserve Vercel's dynamic routing when no preference is configured;
    • emit only the request shape documented for the actual OpenAI-compatible endpoint/transport being used;
    • cover provider-wide defaults, exact model replacement, sibling-model isolation, invalid fields, and unchanged requests without configuration;
    • document the accepted provider slug and sorting semantics from Vercel's primary documentation.

    A focused PR following that contract would be reviewable. Keeping the issue open for implementation.

  3. lidge-jun commented on Aug 19, 2026

    @lidge-jun
    Owner

    리뷰 · 우선순위 40 / 80

    vercel-ai-gateway로 노출된 모델을 특정 업스트림 추론 프로바이더에 고정하거나 순서/정렬하고 싶다는 요청입니다. 인증과 빌링은 Vercel에 두고, OpenRouter의 openRouterRouting과 같은 운영 경험을 원합니다.

    현재 dev의 src/providers/registry.ts에 vercel-ai-gateway가 openai-chat, https://ai-gateway.vercel.sh/v1 로 있습니다. 라우팅 설정은 src/types.ts의 openRouterRouting과 modelOpenRouterRouting, src/providers/openrouter-routing.ts 검증뿐입니다. src/adapters/openai-chat.ts는 resolveOpenRouterRouting이 있을 때만 body.provider를 넣습니다. vercelGatewayRouting 필드는 없습니다. OpenRouter 설정은 캐논 openrouter.ai에만 쓰이도록 막혀 있어 우회가 아닙니다.

    원하는 동작은 only, order, sort(cost/ttft/tps), 모델별 오버라이드, 설정 없으면 Vercel 기본 동적 라우팅 유지입니다. Chat Completions의 provider 단축 형태는 이슈가 인용한 Vercel 문서와, 이미 OpenRouter에 쓰는 body.provider 주입과 비슷합니다.

    해결방안: OpenRouter와 나란히 프로바이더/모델 설정을 추가하고, 유효 와이어가 Vercel 게이트웨이일 때만 provider 페이로드를 넣으면 됩니다. 기본 동작은 바꾸지 말아야 합니다. 필드 이름을 이슈 예시와 똑같이 할지는 제품 결정입니다. 게이트웨이 호스트 핀은 OpenRouter와 같게 유지해야 합니다.

    이 댓글은 grok-bot이 작성했습니다

  4. lidge-jun commented on Aug 19, 2026

    @lidge-jun
    Owner

    리뷰 · 우선순위 40 / 80 · 유지

    Vercel AI Gateway에서 같은 모델을 novita/deepinfra 중 어디 탈지 고르자는 요청. OpenRouter는 이미 openRouterRouting / modelOpenRouterRouting이 있는데, Vercel은 그 필드를 안 받음. order / only / sort(cost, ttft, tps) 받아서 업스트림 provider 샤트핸드로 넘기면 됨.

    유지함. OpenRouter 경로를 그대로 검증하거나 다시 쓰지 말 것. 설정 없으면 지금처럼 Vercel 동적 라우팅 그대로.

    해결방안: vercelGatewayRouting + modelVercelGatewayRouting을 OpenRouter랑 같은 모양으로 넣고, openai-chat에서 Vercel 문서 페이로드로 전송. 모델 설정이 프로바이더 기본보다 우선.

    이 댓글은 grok-bot이 작성했습니다

  5. added 10 commits that reference this issue on Aug 22, 2026
    72176f1
    c74729a
    a1df339
    0efb483
    f3436f5
    18045c6
    0ae0716
    895a865
    f16849f
    99cf69b
  6. 6 remaining items

  7. added 5 commits that reference this issue on Aug 25, 2026
    2870b15
    92015e0
    a522890
    31130ab
    8cc4cc2
  8. added 7 commits that reference this issue on Aug 29, 2026
    7487d97
    352d0f6
    e35ad17
    fc64a1f
    16a45bf
    fdf41e1
    aa5f711
  9. added a commit that references this issue on Sep 14, 2026
    d5239d6
  10. added a commit that references this issue on Sep 17, 2026
    d14cae7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementprovider

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions