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?"}]
}'
<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-authorizationCF_AIG_TOKEN, and send requests to the gateway URL.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.
CF_AIG_TOKEN, CF_ACCOUNT_ID, and GATEWAY_NAME in your shell, then build the URL from those.cf-aig-authorization. Don't swap it with the usual Authorization header unless you know you need both.model can still be a provider model like anthropic/claude-sonnet-4-5.