Skip to content

feat(tanstack-ai): add REST-only byokAlias for stored BYOK keys - #638

Open
L4Ph wants to merge 5 commits into
cloudflare:mainfrom
L4Ph:feat/tanstack-ai-byok-alias
Open

feat(tanstack-ai): add REST-only byokAlias for stored BYOK keys#638
L4Ph wants to merge 5 commits into
cloudflare:mainfrom
L4Ph:feat/tanstack-ai-byok-alias

Conversation

@L4Ph

@L4Ph L4Ph commented Aug 14, 2026

Copy link
Copy Markdown

Summary

  • Add byokAlias on AI Gateway credentials / REST config so createOpenAiChat, createAnthropicChat, createGeminiChat, createGrokChat, createOpenRouterChat, and Workers AI gateway REST can send cf-aig-byok-alias and select a stored BYOK key other than default.
  • Keep the field off the AI binding type. Cloudflare docs: the header is provider-passthrough only, and BYOK is not supported for third-party models called through the AI binding (env.AI.run() / Unified Billing).
  • Gemini maps the header through httpOptions.headers (Google GenAI SDK has no custom fetch).
createGeminiChat("gemini-2.5-flash", {
  accountId: "...",
  gatewayId: "...",
  cfApiKey: "...",
  byokAlias: "development",
});

Test plan

  • pnpm --filter @cloudflare/tanstack-ai exec vitest --run test/gateway-fetch.test.ts test/gateway-adapters.test.ts (66 passed)
  • REST createGatewayFetch sets cf-aig-byok-alias on the outer request
  • Binding config does not emit the header even if byokAlias is forced through the type
  • createOpenRouterChat / createOpenAiChat / createAnthropicChat HTTPClient fetchers forward the alias
  • createGeminiChat forwards the alias via httpOptions.headers

cf-aig-byok-alias is a provider-passthrough header. Expose it on
credentials config so OpenAI, Anthropic, Grok, OpenRouter, and
Workers AI gateway REST can select a non-default stored key. The
AI binding type omits it because that path does not honor the header
for third-party models.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 45b80c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/tanstack-ai Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

L4Ph and others added 4 commits August 14, 2026 11:24
Gemini is credentials / provider-passthrough only, so cf-aig-byok-alias
is honored. Map it through httpOptions.headers like the other cache
headers — it never went through createGatewayFetch.

Co-authored-by: Cursor <cursoragent@cursor.com>
Restore the original tab style after the previous edit rewrote those
files with spaces. Behavior is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
Every gateway adapter already intersects AiGatewayConfig. Keep the
field there so OpenAI, Anthropic, Grok, OpenRouter, Workers AI, and
Gemini share one type. Gemini still maps the header itself because
it cannot use createGatewayFetch.

Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit rewrote the file with spaces. Behavior is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant