Cloudflare AI Gateway

Cloudflare AI Gateway adds analytics, caching, and rate limiting in front of provider APIs. Uses Anthropic Messages API through your Cloudflare Gateway endpoint.

Cloudflare AI Gateway is a proxy layer that sits between your application and AI providers, adding analytics, caching, rate limiting, and logging without changing your underlying provider setup. It's not a model provider itself — it's an observability and optimization layer for providers you're already using. For OpenClaw, Cloudflare AI Gateway routes requests through Cloudflare's edge network to your chosen provider (typically Anthropic). The gateway provides real-time analytics dashboards showing request counts, token usage, latency, and costs. Semantic caching can cache similar (not just identical) requests, potentially saving significant money on repetitive queries. The core features are genuinely free on all Cloudflare plans — analytics, caching, and rate limiting cost nothing. You only pay for persistent logging beyond the free allocation (100K logs on free plan, 1M on paid). Setup is minimal: create a gateway in the Cloudflare dashboard, then change your provider's base URL to route through it. Your existing API keys and auth flow remain unchanged. Cloudflare AI Gateway supports 6+ provider backends including Anthropic, OpenAI, Azure, Google, and others, with access to 350+ models. For OpenClaw specifically, it proxies Anthropic Messages API calls, maintaining full compatibility with streaming, tool use, vision, and thinking. The main value is visibility into your AI spend and the potential for cache-based cost savings.

Tags: gateway, cloudflare, analytics, caching, rate-limiting

Use Cases

  • Cost visibility and analytics for OpenClaw AI spend
  • Semantic caching to reduce repeated API calls in agent workflows
  • Rate limiting to prevent runaway costs from agent loops
  • Centralized logging for debugging agent behavior
  • Adding an observability layer without changing provider setup
  • Enterprise environments wanting Cloudflare's security and compliance features

Tips

  • Use Cloudflare AI Gateway for visibility even if you don't need caching — the analytics dashboard alone justifies the zero-cost setup.
  • Enable semantic caching for repetitive agent workflows (heartbeats, similar queries) to reduce API costs.
  • Set up rate limiting through the gateway to prevent runaway cost if your agent enters a loop.
  • Combine with Cloudflare Workers for custom request/response transformation before hitting the provider.
  • Use the Logpush feature to send request logs to your own analytics system (S3, BigQuery, etc.).
  • The free plan's 100K log limit is generous for personal use. Most OpenClaw users won't need to upgrade.

Known Issues & Gotchas

  • Cloudflare AI Gateway is NOT a model provider — you still need API keys for the underlying provider (Anthropic, OpenAI, etc.).
  • The gateway adds a small amount of latency (routing through Cloudflare's network). Typically 20-100ms depending on location.
  • Semantic caching can return incorrect results if two requests are similar but semantically different. Monitor cache behavior carefully.
  • Persistent logging beyond free tier (100K free, 1M on paid plan) can incur charges. Manage log retention.
  • The gateway URL includes your Cloudflare account ID and gateway ID — don't expose these in public code.
  • Not all provider features may be fully proxied. Test your specific use case (streaming, tool calling, thinking) through the gateway.

Alternatives

  • LiteLLM
  • OpenRouter
  • Helicone
  • Direct Provider APIs

Community Feedback

AI Gateway now gives you access to over 350+ models across 6 different providers. You can get billed for usage across different providers through one Cloudflare account.

— Cloudflare Blog

Cloudflare AI Gateway's core features are free — analytics, caching, and rate limiting. You only pay for persistent logging beyond the free allocation.

— TrueFoundry Blog

The semantic caching is the killer feature. If your agent asks similar questions repeatedly, the cache savings can be substantial.

— Reddit r/CloudFlare

Configuration Examples

Cloudflare AI Gateway with Anthropic

providers:
  cloudflare-ai-gateway:
    apiKey: sk-ant-xxxxx  # Your Anthropic API key
    baseUrl: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic
    model: cloudflare-ai-gateway/claude-sonnet-4-5

Cloudflare Gateway setup steps

# 1. Create gateway at dash.cloudflare.com → AI → AI Gateway
# 2. Note your account_id and gateway_id
# 3. Replace base URL in OpenClaw config:
providers:
  cloudflare-ai-gateway:
    apiKey: sk-ant-xxxxx
    baseUrl: https://gateway.ai.cloudflare.com/v1/abc123/my-gateway/anthropic
    model: cloudflare-ai-gateway/claude-sonnet-4-5

Cloudflare Gateway with caching

# Enable caching in Cloudflare dashboard:
# AI Gateway → Settings → Cache → Enable
# Set TTL based on your use case
# Semantic caching: enable for similar-query deduplication
providers:
  cloudflare-ai-gateway:
    apiKey: sk-ant-xxxxx
    baseUrl: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic
    model: cloudflare-ai-gateway/claude-sonnet-4-5