Cloudflare Workers AI 定价与限速全解析:Neurons 计费、免费额度与 Kiln 并发接入策略

原创2026-10-13 13:31:101,360 阅读
文章标签:人工智能AI 应用大模型模型评测提示工程微调RAGAI Agent数据标注数据增强LLMOps本地部署桌面应用

Cloudflare Workers AI 定价与限速全解析:Neurons 计费、免费额度与 Kiln 并发接入策略

本文基于 specs/projects/cloudflare_workers_ai_provider 项目的研究文档(研究日期 2026-09-28),系统梳理 Workers AI 的 Neurons 计费模型、免费/付费配额、逐模型定价、三档速率限制,以及 Kiln 在接入该提供商时对限流与容量错误的分类、重试与并发设计。读完本文,你将掌握 Workers AI 的成本估算方法、免费额度换算、429 错误码三兄弟(3021/3036/3040)的判别与处置,以及如何在 Kiln 中安全地配置并发与重试。

一、定价模型:以 Neurons 为计量单位

Cloudflare 官方对 Workers AI 的定价描述(原文引用):

"Workers AI is included in both the Free and Paid Workers plans and is priced at $0.011 per 1,000 Neurons."

"Our free allocation allows anyone to use a total of 10,000 Neurons per day at no charge. To use more than 10,000 Neurons per day, you need to sign up for the Workers Paid plan."

也就是说,Neurons(神经元)是 Workers AI 衡量 AI 输出的专属计量单位,它本质上是"执行一次请求所需 GPU 计算量"的抽象(官方原话:"Neurons are our way of measuring AI outputs across different models, representing the GPU compute needed to perform your request.")。不同模型的单次请求消耗的 Neurons 不同,付费单价统一为 $0.011 / 1,000 Neurons。

1.1 每日额度与重置规则

  • 免费额度:每天 10,000 Neurons,Free 与 Paid 计划都包含(Paid 计划"starts at $5 per month and still includes the 10,000 free Neurons per day allocation",见 2026-07-28 变更日志)。
  • 重置时间:所有限额均在 每天 00:00 UTC 重置。
  • 超额行为:超出任一限额后,后续操作将直接失败并返回错误——具体为 HTTP 429、错误码 3036,消息形如 "You have used up your daily free allocation of 10,000 neurons..."(见 Cloudflare Workers AI 错误码文档)。

1.2 按 token 展示、按 Neurons 计费

一个容易混淆的细节:Cloudflare 在 2026 年的更新中将定价改为"per-model unit-based pricing"(按模型、按单位展示),价格表同时给出 "Price in Tokens" 与 "Price in Neurons" 两列,官方声明两者是等价的(equivalent),但后端仍以 Neurons 结算。因此用户在前端看到的"每百万 token 单价"其实是从 Neurons 折算而来的,实际扣费按 Neurons 累积计算。

1.3 部分模型享缓存输入折扣

Prompt caching 对部分模型提供缓存输入折扣价,例如 Kimi K2.6 缓存输入 $0.16/M,而普通输入为 $0.95/M。注意:

  • 缓存对选定模型默认开启;
  • 通过发送 x-session-affinity 请求头可以将请求路由到同一实例,提升前缀缓存命中率(prefix-cache hits),从而享受更低的缓存输入计费。

1.4 替代支付方式:AI Gateway 预付费积分

除了常规按量计费,还可以使用 AI Gateway 预付费积分(prepaid AI Gateway credits)支付 Workers AI 费用,前提是该网关的 Workers AI 计费设置为 "Unified billing"(统一计费)。该方案的额外收益见下文"限速"章节——预付费积分模式下 paid-only 前沿模型的速率限制更高(50 rpm vs 20 rpm)。

二、Paid-only 模型:只有付费计划才能调用

部分模型强制要求付费账单方式("Some models require a paid billing method")。根据研究文档,截至 2026-09-28,以下模型属于 paid-only:

模型 说明
@cf/moonshotai/kimi-k2.6 2026-07-28 起移入付费墙
@cf/moonshotai/kimi-k2.7-code 2026-07-28 起移入付费墙
@cf/zai-org/glm-5.2 2026-07-28 起移入付费墙
@cf/zai-org/glm-5.3 —
@cf/zai-org/glm-5.3-flash —
@cf/deepseek-ai/deepseek-v4-flash-0731 —
@cf/deepseek-ai/deepseek-v4-pro-0813 —

在 Workers Free 计划下调用这些模型会返回 HTTP 403、错误码 5035("This model requires a Workers Paid plan")。Cloudflare 官方说明这些模型被移入付费墙是"so we can prioritize capacity"(为优先保障容量)。

对 Kiln 的工程含义:5035 是一个确定性的配置级错误——它不代表 API Key 错误,而是"该模型需要 Workers Paid 计划"。因此 Kiln 应将 5035 明确呈现为"此模型需要 Workers Paid 计划",而不是把用户引导去检查 API Key。这一点与仓库中错误分类的设计一致(见后文"Kiln 的错误分类")。

三、样本模型价格表(截至 2026-09-28)

以下价格来自官方定价表,单位为每百万 token 的美元价格(Input $/M 与 Output $/M)。标注 "paid only" 的模型在 Free 计划下不可用:

模型 Input $/M Output $/M
@cf/ibm-granite/granite-4.0-h-micro 0.017 0.112
@cf/zai-org/glm-4.7-flash 0.060 0.400
@cf/google/gemma-4-26b-a4b-it 0.100 0.300
@cf/openai/gpt-oss-20b 0.200 0.300
@cf/meta/llama-4-scout-17b-16e-instruct 0.270 0.850
@cf/meta/llama-3.3-70b-instruct-fp8-fast 0.293 2.253
@cf/openai/gpt-oss-120b 0.350 0.750
@cf/qwen/qwen3.8-27b 0.450 3.200
@cf/nvidia/nemotron-3-120b-a12b 0.500 1.500
@cf/moonshotai/kimi-k2.6(paid only) 0.950 4.000
@cf/deepseek-ai/deepseek-v4-pro-0813(paid only) 1.320 3.960
@cf/zai-org/glm-5.3(paid only) 1.400 4.400

注意文档漂移(docs drift):定价表仍列出了 2026-05-30 已弃用的模型(如 @cf/meta/llama-3.1-8b-instruct、@cf/mistral/mistral-7b-instruct-v0.1、@cf/google/gemma-3-12b-it、@cf/moonshotai/kimi-k2.5)。实际可用模型应以实时模型目录为准,这也正是 Kiln 维护自有模型清单(见 ml_model_list.py)的原因之一——例如其中 Nemotron 3 Super 在 Cloudflare 侧登记为 @cf/nvidia/nemotron-3-120b-a12b(见 ml_model_list.py)。

四、10,000 免费 Neurons 每天能干什么

研究文档根据定价表的 Neurons 列做了换算(单一维度上限估算,即要么全算输入、要么全算输出),示例模型如下:

模型 Neurons per M(in / out) ≈ 免费输入 token/天 ≈ 免费输出 token/天
glm-4.7-flash 5,500 / 36,400 1.8M 275k
gemma-4-26b-a4b-it 9,091 / 27,273 1.1M 367k
gpt-oss-120b 31,818 / 68,182 314k 147k
llama-3.3-70b-instruct-fp8-fast 26,668 / 204,805 375k 49k

结论很关键:免费额度看似慷慨,但注意这些是"单维度上界"(all input or all output)。实际场景中,一个 Kiln 评测(eval)或合成数据(synthetic data generation)运行会很快耗尽免费额度——尤其是中等规模模型。研究文档明确给出建议:真正要做实际工作量的用户需要 Workers Paid 计划。

五、速率限制(Rate Limits)

与 Neurons 计费并列的另一套约束是请求速率限制。官方表述为"default per task type, with some per-model limits"(按任务类型设定默认值,部分模型有专属限制):

  • 文本生成(Text Generation):300 requests per minute,除非该模型要求 Workers Paid 计划;
  • Paid-only 模型:按"per account, per model"限制——标准 Workers AI 计费为 20 rpm,使用 AI Gateway 预付费积分(Unified billing)为 50 rpm。官方解释:"These limits are designed for typical agentic and coding workloads, where requests to frontier models can take longer to complete."
  • 文本嵌入(Text Embeddings):3000 rpm(其中 bge-large 为 1500 rpm)。
  • Beta 模型可能享有更低的速率限制。
  • 本地模式:使用 Wrangler 进行的本地推理(local mode)同样计入这些限制。
  • 提高上限:可通过 Custom Requirements Form 申请自定义/更高限制。
  • 无 token 级限制:官方文档中没有记录每分钟 token 数限制。

5.1 容量(Capacity)是另一个独立的失败模式

速率限制之外的独立故障模式是容量问题:

  • 返回 HTTP 429、错误码 3040:"Capacity temporarily exceeded, please try again."
  • 正常情况下请求会进入容量队列等待;在请求体中设置 options.rejectIfBusy: true 可以改为快速失败(fail fast),不排队直接返回 429/3040。该选项自 2026-09-17 起可用,"OpenAI clients that preserve custom fields can send this option"。
  • 部分模型还宣传支持 async_queue(Batch API),但这对 Kiln 的同步调用没有意义。

5.2 Cloudflare API 全局限速(存疑项)

Cloudflare 全局 API 限制为:"The global rate limit for the Cloudflare API is 1,200 requests per five minute period per user ... If you exceed this limit, all API calls for the next five minutes will be blocked"。研究文档明确指出一个未解问题:Workers AI 的推理调用走 api.cloudflare.com,是否计入这个全局限额并不清楚——Workers AI 限制文档未提及它,而且 1,200/5 分钟(折合 240 rpm)会低于文档宣称的文本生成 300 rpm,自相矛盾。研究时未能找到权威出处解决该疑问。对于实际使用,这意味着:请勿把 300 rpm 当作可以打满的硬指标,尤其是同时进行大量并行调用时。

六、三种 429:3021 / 3036 / 3040 的判别与处置

这是对 Kiln 集成最核心的实践知识。HTTP 429 在 Workers AI 中对应三种完全不同语义的错误,绝不能一律同等处理:

错误码 含义 是否可重试 出处/证据
3021 每分钟速率限制("rate limiting: inference request per min rate reached") ✅ 可重试 live_test_findings.md 实测
3036 每日免费 Neurons 配额耗尽("You have used up your daily free allocation of 10,000 neurons...") ❌ 当天不可重试 官方错误文档
3040 临时容量不足("Capacity temporarily exceeded, please try again.") ✅ 可重试 官方错误文档,rejectIfBusy 也返回该码

6.1 Kiln 的实测证据:3021 → RateLimitError

在 live_test_findings.md 的实测中,对 @cf/meta/llama-3.2-1b-instruct 做 max_tokens: 1 的突发压测(经 LiteLLM openai/ 路径、num_retries=0):

  • 400 个请求 / 4.7 秒:全部成功——文档宣称的 300 rpm 在小突发下并未被严格逐条执行;
  • 1,212 个请求 / 7.4 秒:51 个失败,返回 HTTP 429、code 3021,消息为 AiError: AiError: rate limiting: inference request per min rate reached;
  • 通过 cf-aig-gateway-id: default 网关路径:同样返回 429/3021;
  • 两条路径下 LiteLLM 均抛出 litellm.RateLimitError;Kiln 的错误分类器将其判定为 is_retryable_error=True、is_batch_fatal_error=False,format_error_message 输出 "Rate limit exceeded. Wait a moment and try again."

这一映射在仓库测试中有精确固化的验证:test_cloudflare_litellm.py 中录入了 3021 的响应体,并在 test_cloudflare_rate_limit_is_retryable_rate_limit_error 中断言:unwrap 后为 litellm.RateLimitError、is_retryable_error(error) 为真、is_batch_fatal_error(error) 为假、错误消息以 "Rate limit exceeded" 开头(有无网关 ID 两种情况均验证)。

6.2 Kiln 的错误分类器源码

Kiln 的通用重试判定位于 retry_classification.py:litellm.RateLimitError、litellm.Timeout、litellm.InternalServerError、ServiceUnavailableError、BadGatewayError、APIConnectionError 等都被视为可重试(transient);而 AuthenticationError、PermissionDeniedError、NotFoundError 等确定性错误被归类为 batch-fatal(retry_classification.py)——批处理会在首个此类错误时整体中止,而不是逐 case 失败继续烧钱。这套机制正是处置 Workers AI 3021/3036/3040 三种 429 的基础:

  • 3021(RateLimitError)→ 可重试、非 batch-fatal;
  • 3040(容量)→ 应重试(可结合退避);
  • 3036(配额耗尽)→ 当天重试无意义,且不是 transient——需要用户升级付费计划。

6.3 对 Kiln 并发策略的现实影响

研究文档明确指出("What matters for Kiln users"):

  • Kiln 在**评测(evals)与合成数据生成(synthetic data generation)**阶段会发起大量并行请求;
  • 在 20 rpm 的限制下,paid-only 前沿模型(Kimi、GLM 5.x、DeepSeek V4)会严重节流;
  • 因此 Kiln 面向 Workers AI 的并发应该保守,并对 3040 进行重试。

仓库中 Cloudflare 接入的实际配置也印证了这一设计:provider_tools.py 中 Cloudflare 提供商要求 cloudflare_api_key 与 cloudflare_account_id 两个配置项;请求构造时把 account ID 拼入 base URL(https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1),并通过 cf-aig-gateway-id 默认头支持可选的 AI Gateway 路由(provider_tools.py)。测试同时覆盖了带网关头与不带网关头两种请求形态(test_cloudflare_litellm.py)。

七、其他值得注意的限制细节

7.1 输出长度:必须显式设置 max_tokens

这是文档以外、但对成本与正确性影响极大的实践要点(见 feature-support.md):

  • Legacy 模型(Llama 3.x/4、GPT-OSS、Mistral、老版 Qwen 等)的输入 schema 中 max_tokens 默认值为 256;
  • 第三方报告指出,在 /v1/chat/completions 上省略 max_completion_tokens 时,Cloudflare 会把一次完成截断在 256 token;
  • 因此 Kiln 对 Workers AI 必须始终显式发送 max tokens,否则结构化输出会被截断。

7.2 连接检查:免费且不耗 Neurons

研究文档推荐用 GET /accounts/{account_id}/ai/models/search?per_page=1(可选追加 &task=Text Generation)作为"Connect"校验:它同时校验 token、account ID 与 Workers AI 权限,且不触发推理、不消耗 Neurons。实测发现 per_page 参数会被忽略(返回全部约 65 个模型,约 100KB),因此 Kiln 的校验改用 search=kiln-connection-check,返回空结果(约 120 字节)且同样免费(见 live_test_findings.md)。

7.3 模型别名(Aliasing):K2.5 会被静默解析为 K2.6

实测确认了一个重要现象:请求 @cf/moonshotai/kimi-k2.5 会返回 "Model @cf/moonshotai/kimi-k2.6 is not available on the Workers Free plan"——即 Cloudflare 会静默把 K2.5 解析为 K2.6。升级到 Paid 后,成功的调用在响应 model 字段中回显请求的 ID(k2.5),即使实际跑的是 K2.6。结论:运行时无法通过响应体做模型替换检查。

八、给 Kiln 用户的实用建议汇总

  1. 默认走 OpenAI 兼容端点:https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1,配合 LiteLLM openai/ 提供商(仓库中 Cloudflare 正是这样接入的,见 provider_tools.py)。
  2. 付费预算:免费 10,000 Neurons/天适合轻量验证;任何认真的 eval / 合成数据运行应视为需要 Workers Paid。
  3. 限速预期:免费模型 300 rpm、paid-only 模型 20 rpm(预付费积分 50 rpm);对 paid-only 前沿模型务必降低 Kiln 并发。
  4. 重试矩阵:3021(每分钟限速)与 3040(容量)可重试;3036(每日配额)当天不可重试;5035 不是 key 错误,而是"需要 Workers Paid 计划"。
  5. 显式 max_tokens:对 legacy 模型尤其重要,避免 256 token 截断。
  6. 可选网关:加一个 cf-aig-gateway-id 请求头即可把请求路由到 AI Gateway,获得日志、分析、缓存与自定义限速/消费限制能力;预付费积分还能把 paid-only 模型的限速从 20 rpm 提升到 50 rpm(细节见 workers-ai-through-gateway.md)。

一句话总结:Workers AI 的计费与限速体系可以概括为"Neurons 计费 + 三层速率限制 + 三类 429",其中 3021/3036/3040 的判别直接决定重试策略的有效性;对 Kiln 这类会大量并发推理的工具,保守并发、显式 max_tokens、按错误码分类重试,是把免费额度与付费预算花在刀刃上的关键。

登录后查看全文
Kiln