Skills2026年4月6日·1 分钟阅读

Cloudflare AI Gateway — LLM Proxy, Cache & Analytics

Free proxy gateway for LLM API calls with caching, rate limiting, cost tracking, and fallback routing across providers. Reduce costs up to 95% with response caching. 7,000+ stars.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
Cloudflare AI Gateway — LLM Proxy, Cache & Analytics
直接安装命令
npx -y tokrepo@latest install b1962c77-9ecf-4a84-87b1-e7d4b677dabe --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Free proxy gateway for LLM API calls that adds caching, rate limiting, cost tracking, and fallback routing across providers.
§01

What it is

Cloudflare AI Gateway is a free proxy gateway for LLM API calls. It sits between your application and AI providers (OpenAI, Anthropic, Google, etc.), adding response caching, rate limiting, cost tracking, fallback routing, and analytics. You change one URL in your code and get visibility and control over all your AI API usage.

It is designed for engineering teams running production AI applications who need cost control, observability, and resilience without building custom proxy infrastructure.

§02

How it saves time or tokens

The token estimate for this workflow is 2,600 tokens. Response caching can reduce costs by up to 95% for repeated queries. Rate limiting prevents budget overruns. Fallback routing automatically switches to a backup provider if your primary one goes down, improving reliability without code changes.

§03

How to use

  1. Sign up at dash.cloudflare.com (free tier available)
  2. Navigate to AI > AI Gateway > Create Gateway
  3. Replace your API base URL with the Cloudflare gateway URL
  4. Your existing code and API keys continue to work
§04

Example

from openai import OpenAI

# Before: direct to OpenAI
# client = OpenAI(base_url='https://api.openai.com/v1')

# After: route through Cloudflare AI Gateway
client = OpenAI(
    base_url='https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/openai'
)
# Same API key, same code -- now with caching, logging, and analytics

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{'role': 'user', 'content': 'Explain caching'}]
)
# Universal endpoint for any provider
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/openai/chat/completions \
  -H 'Authorization: Bearer sk-...' \
  -H 'Content-Type: application/json' \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'
§05

Related on TokRepo

§06

Common pitfalls

  • Caching only works for identical requests; small prompt variations generate cache misses
  • The gateway adds a small latency overhead (typically under 50ms) for the proxy hop
  • Fallback routing requires configuring multiple providers; it does not auto-discover alternatives

常见问题

Is Cloudflare AI Gateway free?+

Yes. The core gateway features (caching, rate limiting, analytics) are available on the free tier. Advanced features and higher request volumes may require a paid Cloudflare plan.

Which AI providers does it support?+

Cloudflare AI Gateway supports OpenAI, Anthropic, Google (Gemini), Azure OpenAI, HuggingFace, Replicate, and other major providers. The universal endpoint format works with any OpenAI-compatible API.

How does response caching work?+

When a request matches a previous identical request (same model, messages, and parameters), the gateway returns the cached response without calling the provider. You configure cache TTL and can invalidate the cache manually.

Can I use it with streaming responses?+

Yes. Cloudflare AI Gateway supports streaming (SSE) responses. Cached streaming responses are replayed as if they were live, maintaining the same chunked delivery format.

Does it work with self-hosted models?+

The gateway is designed for cloud AI providers. For self-hosted models, you would need to expose them behind an OpenAI-compatible API and configure a custom provider endpoint in the gateway.

引用来源 (3)
🙏

来源与感谢

Created by Cloudflare. Licensed under Apache 2.0.

ai-gateway — ⭐ 7,000+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产