What is the name of the modal youâre running?
gpt-4o-mini (also tested with other OpenAI models)
What is the error number?
N/A (OpenAI error, not Cloudflare error code)
What is the error message?
You didnât provide an API key. You need to provide your API key in an Authorization header using Bearer auth
What is the issue or error youâre encountering
Cloudflare AI Gatewayâs universal endpoint format (from official docs) is no longer forwarding Authorization headers from the JSON payload to OpenAI. The standard endpoint format works fine, but the universal endpoint format documented at Overview ¡ Cloudflare AI Gateway docs fails to forward the Authorization header specified in the requestâs âheadersâ object, causing OpenAI to return âYou didnât provide an API keyâ errors. This seems to be a regression that appeared sometime during the last few weeks since the same code worked previously.
What steps have you taken to resolve the issue?
- Verified OpenAI API key works with direct API calls (
succeeds)
- Confirmed standard AI Gateway endpoint works (
/openai/chat/completions format succeeds)
- Tested universal endpoint format exactly as shown in Cloudflare docs on Universal Endpoint ¡ Cloudflare AI Gateway docs (
fails)
- Tested with and without streaming parameter (both fail)
- Verified cf-aig-authorization header is being sent correctly for gateway authentication
- Confirmed the Authorization header is properly included in the JSON payloadâs âheadersâ object
- Multiple tests show universal endpoint consistently fails while standard endpoint works
- Using anthropic as provider works, so this is openai specific
What are the steps to reproduce the issue?
-
Set up environment variables:
export OPENAI_API_KEY=âyour-openai-keyâ
export CF_AIG_TOKEN=âyour-gateway-tokenâ
export CLOUDFLARE_ACCOUNT_ID=âyour-account-idâ
export CLOUDFLARE_GATEWAY_ID=âyour-gateway-idâ -
Test standard endpoint (WORKS):
curl https://gateway.ai.cloudflare.com/v1/$CLOUDFLARE_ACCOUNT_ID/$CLOUDFLARE_GATEWAY_ID/openai/chat/completions
âheader âcf-aig-authorization: Bearer $CF_AIG_TOKENâ
âheader âAuthorization: Bearer $OPENAI_API_KEYâ
âheader âContent-Type: application/jsonâ
âdata â{âmodelâ: âgpt-4o-miniâ, âmessagesâ: [{âroleâ: âuserâ, âcontentâ: âTestâ}]}â -
Test universal endpoint from docs (FAILS):
curl https://gateway.ai.cloudflare.com/v1/$CLOUDFLARE_ACCOUNT_ID/$CLOUDFLARE_GATEWAY_ID
âheader âcf-aig-authorization: Bearer $CF_AIG_TOKENâ
âheader âContent-Type: application/jsonâ
âdata â[{âproviderâ: âopenaiâ, âendpointâ: âchat/completionsâ, âheadersâ: {âAuthorizationâ: âBearer â$OPENAI_API_KEYââ, âContent-Typeâ: âapplication/jsonâ}, âqueryâ: {âmodelâ: âgpt-4o-miniâ, âmessagesâ: [{âroleâ: âuserâ, âcontentâ: âWhat is Cloudflare?â}]}}]â
Expected: Both should return chat completions
Actual: Standard endpoint works, universal endpoint returns âYou didnât provide an API keyâ
The universal endpoint format seems to not forward the Authorization header from the JSON payloadâs âheadersâ object to OpenAI.