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

Setup Checklist (BYOK)

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