Skip to content

fix(provider): pass apiKey to createUnified for Cloudflare AI Gateway#32052

Merged
rekram1-node merged 2 commits into
anomalyco:devfrom
keefetang:fix/ai-gateway-workers-ai-auth
Jun 16, 2026
Merged

fix(provider): pass apiKey to createUnified for Cloudflare AI Gateway#32052
rekram1-node merged 2 commits into
anomalyco:devfrom
keefetang:fix/ai-gateway-workers-ai-auth

Conversation

@keefetang

@keefetang keefetang commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #32051

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

createUnified() is called without an apiKey in the cloudflare-ai-gateway provider. The ai-gateway-provider package injects a placeholder CF_TEMP_TOKEN, then strips it before sending the universal endpoint request — leaving the Workers AI sub-request with no authorization header. This causes a 401 for all Workers AI models. BYOK models (Anthropic/OpenAI) are unaffected because they carry their own real API keys.

The fix passes the API key to createUnified({ apiKey }) so the real token is set on the sub-request Authorization header. The stripping logic only removes headers containing the literal CF_TEMP_TOKEN, so real tokens survive.

How did you verify your code works?

  • Reproduced the 401 by calling the AI Gateway universal endpoint with no auth in the sub-request headers
  • Applied the fix and confirmed Workers AI model requests now return 200
  • Verified BYOK models (Anthropic/OpenAI) are unaffected — their keys never contain CF_TEMP_TOKEN
  • Verified CF_TEMP_TOKEN stripping still works correctly for no-key/unified-billing scenarios
  • Verified cloudflare-workers-ai provider is a completely separate code path and untouched

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
Workers AI models via cloudflare-ai-gateway fail with 401 because
createUnified() is called without an apiKey. The ai-gateway-provider
package injects CF_TEMP_TOKEN as a placeholder, then strips it before
sending — leaving the sub-request with no authorization header.

Passing the real API key means the Authorization header survives the
stripping logic and reaches the gateway correctly.

Fixes anomalyco#32051
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@rekram1-node rekram1-node merged commit 8fd5753 into anomalyco:dev Jun 16, 2026
6 of 8 checks passed
johnko added a commit to johnko/opencode that referenced this pull request Jun 17, 2026
* upstream: (4536 commits)
  fix(opencode): sanitize OpenAI MCP tool schemas (anomalyco#32489)
  chore: update nix node_modules hashes
  fix(provider): pass apiKey to createUnified for Cloudflare AI Gateway (anomalyco#32052)
  chore: generate
  feat(app): make session timelines much faster AND without flicker or scroll jumps (anomalyco#32331)
  chore: update nix node_modules hashes
  chore: generate
  experiment: better web picker using @pierre/tree (anomalyco#31208)
  fix(mcp): default tool schema properties (anomalyco#32568)
  fix(web): persist docs language selection (anomalyco#32551)
  fix(tui): render move errors inline (anomalyco#32241)
  Revert "fix(mcp): type tool error content"
  fix(mcp): enable progress timeout resets (anomalyco#32477)
  fix(mcp): stop idle OAuth callback server (anomalyco#32245)
  chore: generate
  chore: update nix node_modules hashes
  fix(mcp): type tool error content
  fix(stats): align homepage model ranks
  fix(mcp): handle tool result errors (anomalyco#32244)
  fix(stats): rank model pages by week
  ...
@kebiricrypto

Copy link
Copy Markdown

i have tested the lest version for windows this feauture not added

davidgut1982 pushed a commit to davidgut1982/opencode that referenced this pull request Jun 19, 2026
…anomalyco#32052)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
LuisAlbertoMK pushed a commit to LuisAlbertoMK/opencode that referenced this pull request Jun 21, 2026
…anomalyco#32052)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
thdxr pushed a commit that referenced this pull request Jun 21, 2026
…#32052)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
markjaquith pushed a commit to markjaquith/opencode that referenced this pull request Jun 23, 2026
…anomalyco#32052)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
BenGu3 pushed a commit to BenGu3/opencode that referenced this pull request Jun 27, 2026
…anomalyco#32052)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants