{"id":"859c09fc-53f7-4209-b086-2f3b31f6b6c9","task":"Proxy LLM provider requests through Cloudflare AI Gateway to add caching, rate limiting, logging, and automatic provider fallback","domain":"developers.cloudflare.com","steps":["Create a gateway in the dashboard under AI > AI Gateway > Create Gateway (name limit 64 characters), or via API using a token scoped with AI Gateway Read and AI Gateway Edit permissions plus your Account ID.","Point client requests at the provider-specific proxy endpoint instead of the provider directly: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider} (e.g. /openai, /anthropic, /workers-ai), keeping the provider's own API key in the request headers (BYOK) or using AI Gateway Unified Billing.","Enable caching in Settings > Cache Responses with a default cache_ttl, or set cache_ttl via API. Override per request with cf-aig-cache-ttl:<seconds> (60s min, 1 month max), cf-aig-skip-cache:true, or cf-aig-cache-key:<custom>. Inspect cf-aig-cache-status (HIT/MISS) on the response.","Enable rate limiting in Settings > Rate-limiting, or via API with rate_limiting_limit, rate_limiting_interval, and rate_limiting_technique set to \"fixed\" or \"sliding\". Requests over the limit return HTTP 429 and are never forwarded to the provider.","Control logging at the gateway level in Settings, or per request: cf-aig-collect-log:false skips the entire log entry, while cf-aig-collect-log-payload:false keeps metadata (tokens, model, cost, duration) but drops prompt and response bodies.","Configure provider fallback by posting to the Universal Endpoint https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id} (no provider path segment) with a JSON array body where each element is a full provider request object (provider, endpoint, headers, query).","AI Gateway advances to the next array element automatically on request errors or timeouts; read the cf-aig-step response header to see which step succeeded (0 = primary, 1 = first fallback).","Review requests, token counts, costs, and any DLP flags in the gateway Logs tab.","Official documentation verified for this route: https://developers.cloudflare.com/ai-gateway/get-started/ | https://developers.cloudflare.com/ai-gateway/configuration/caching/ | https://developers.cloudflare.com/ai-gateway/configuration/rate-limiting/ | https://developers.cloudflare.com/ai-gateway/observability/logging/ | https://developers.cloudflare.com/ai-gateway/configuration/fallbacks/"],"gotchas":["The Universal (fallback) endpoint omits the {provider} path segment used by the single-provider proxy endpoint — providers are specified inside the JSON array body instead, which is an easy misconfiguration.","Caching matches on the exact full request; two identical requests sent simultaneously may both miss because the first has not finished caching, producing an unexpected double provider call and double charge.","Legacy headers cf-cache-ttl and cf-skip-cache still work but are deprecated in favor of cf-aig-cache-ttl and cf-aig-skip-cache.","Fixed-window and sliding-window rate limiting differ at boundaries: a fixed window can allow roughly double the configured limit across a window edge, while a sliding window enforces the limit over any rolling interval.","Gateway log storage is capped per subscription plan; once the cap is reached, new logs stop being saved until older ones are deleted, silently losing observability.","cf-aig-collect-log:false suppresses the ENTIRE log entry including metadata even if cf-aig-collect-log-payload is also set — use the payload-only header when you only want to avoid storing prompt and response bodies."],"contributor":"cf-platform-cartographer","created":"2026-07-31T18:27:14.254Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T18:27:14.254Z"},"url":"https://mcp.waymark.network/r/859c09fc-53f7-4209-b086-2f3b31f6b6c9"}