[AI Gateway] Correct required API token permission for REST API - #32574
Merged
superhighfives merged 1 commit intoAug 7, 2026
Merged
Conversation
kai-cloudflare
requested review from
a team,
aninibread,
ethulia,
kathayl,
kflansburg,
mattrothenberg,
mchenco,
palashgo,
roerohan,
superhighfives and
zeke
as code owners
August 6, 2026 15:15
Contributor
Review✅ No issues found in commit Code ReviewThis code review is in beta and may not always be helpful — use your judgment. No code review issues found. ConventionsNo convention issues found. Style Guide ReviewNo style-guide issues found. CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
superhighfives
approved these changes
Aug 6, 2026
superhighfives
enabled auto-merge (squash)
August 6, 2026 15:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Authentication section of the AI Gateway REST API page states that the token needs the
AI Gatewaypermission. That permission does not grant access to these endpoints. A token holding onlyAI Gateway ReadorAI Gateway Runreturns401with error code10000.The permission the
/accounts/{account_id}/ai/*endpoints actually require isWorkers AI Read, whose own permission group description is "Grants access to invoke Workers AI models". This holds for third-party models as well as@cf/models, because the check applies to the API path rather than to the routed provider.How this was verified
Four single-permission user API tokens, each scoped to one account, against
POST /accounts/{account_id}/ai/v1/chat/completionswithmodel: openai/gpt-4.1(a third-party model):GET /ai-gateway/gatewaysPOST /ai/v1/chat/completions200401/10000403401/10000403402/2021(reached gateway)403402/2021(reached gateway)The
402responses are Unified Billing rejections raised inside AI Gateway, which confirms the request passed authentication and reached the gateway.With a
Workers AI Readtoken only, the following also pass authentication:POST /ai/runcf-aig-gateway-idmodel: dynamic/{route})@cf/models on the same tokenImpact
This wording sends users to configure
AI Gateway Run, which produces a401with no entry in AI Gateway logs, because the request is rejected before it reaches the gateway. The failure is indistinguishable from an invalid token, so it is expensive to diagnose from the response alone.