🐛 Universal endpoint no longer forwarding Authorization headers to OpenAI

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?

  1. Verified OpenAI API key works with direct API calls (:white_check_mark: succeeds)
  2. Confirmed standard AI Gateway endpoint works (:white_check_mark: /openai/chat/completions format succeeds)
  3. Tested universal endpoint format exactly as shown in Cloudflare docs on Universal Endpoint ¡ Cloudflare AI Gateway docs (:cross_mark: fails)
  4. Tested with and without streaming parameter (both fail)
  5. Verified cf-aig-authorization header is being sent correctly for gateway authentication
  6. Confirmed the Authorization header is properly included in the JSON payload’s “headers” object
  7. Multiple tests show universal endpoint consistently fails while standard endpoint works
  8. Using anthropic as provider works, so this is openai specific

What are the steps to reproduce the issue?

  1. 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”

  2. 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”}]}’

  3. 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.

1 Like

Cross-posting from Discord, where Bryan replied:

I disabled gateway auth and that got it working
zero responses from CF

I have also confirmed that turning of authentication for the AI Gateway is a valid workaround, but of course it is not desirable in the long run.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.