Cloudflare Notes

Using Cloudflare AI Gateway (BYOK Claude)
Topic: Cloudflare AI Gateway
Classification: Tip
Working Curl Example

This is the exact invocation that works (OpenAI-compatible chat completions endpoint, routed through AI Gateway):

curl -X POST "https://gateway.ai.cloudflare.com/v1/<CF_ACCOUNT_ID>/<GATEWAY_NAME>/compat/chat/completions" \
  -H "cf-aig-authorization: Bearer $CF_AIG_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{
    "model": "anthropic/claude-sonnet-4-5",
    "messages": [{"role":"user","content":"What is Cloudflare?"}]
  }'
What You Need to Swap In
  • <CF_ACCOUNT_ID> - your Cloudflare account id (the long hex string)
  • <GATEWAY_NAME> - the gateway slug you created (example: my-gateway)
  • CF_AIG_TOKEN - your AI Gateway client token used in cf-aig-authorization
Setup Checklist (BYOK)
  • Create an AI Gateway in Cloudflare (pick a name/slug).
  • Configure the upstream provider + BYOK credentials on the gateway (Anthropic in this example).
  • Create an AI Gateway token for the client, export it as CF_AIG_TOKEN, and send requests to the gateway URL.
Why This Works for BYOK (Claude)

The /compat/chat/completions path is the key move: it keeps the request shape in the OpenAI Chat Completions format, while the model string selects the upstream provider model (here, Anthropic Claude).

For BYOK setups, the point is: your app only talks to Cloudflare and authenticates with cf-aig-authorization. Cloudflare handles routing/logging and (depending on how you configured the gateway) attaches the upstream provider credentials.

A Couple Useful Tips
Use env vars so you can copy/paste safely.
Set CF_AIG_TOKEN, CF_ACCOUNT_ID, and GATEWAY_NAME in your shell, then build the URL from those.
The header name matters.
Cloudflare AI Gateway auth is cf-aig-authorization. Don't swap it with the usual Authorization header unless you know you need both.
Model naming is provider-scoped.
If your request shape is OpenAI-compatible, your model can still be a provider model like anthropic/claude-sonnet-4-5.
END OF DOCUMENT