🔥 Slashing Agent Token Costs by 98% with RFC 9457
核心亮点
98% Token 减少! Cloudflare 现在返回 RFC 9457 合规的结构化 Markdown 和 JSON 错误载荷,替代原来为浏览器设计的大型 HTML 错误页面。
问题背景
AI agents 已经成为生产基础设施,每天发出数十亿个 HTTP 请求。但当这些 agents 遇到错误时,它们仍然收到我们为浏览器构建的相同 HTML 错误页面:数百行标记、CSS 和为人类设计的文案。这些页面给 agents 的是线索,而不是指令,浪费时间和 tokens。
解决方案
当 agent 发送 Accept: text/markdown、Accept: application/json 或 Accept: application/problem+json 并遇到 Cloudflare 错误时,我们返回结构化格式的语义契约,而非 HTML。
例如:
- 以前:仅被告知"你被阻止了"
- 现在:被告知"你被速率限制了 — 等待 30 秒并使用指数退避重试"
技术细节
支持的格式
Accept: text/markdown→ 返回 MarkdownAccept: application/json→ 返回 JSONAccept: application/problem+json→ 返回 JSON + application/problem+json content type
RFC 9457 字段
| 字段 | 描述 |
|---|---|
| type | 指向 Cloudflare 特定错误代码文档的 URI |
| status | HTTP 状态码 |
| title | 简短的人类可读摘要 |
| detail | 此特定发生的详细解释 |
| instance | 标识此特定错误发生的 Ray ID |
扩展操作字段
error_code- 错误代码error_name- 错误名称error_category- 错误类别retryable- 是否可重试retry_after- 重试等待时间owner_action_required- 是否需要所有者操作
示例响应
速率限制错误 (1015) JSON
{
"type": "https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1015/",
"title": "Error 1015: You are being rate limited",
"status": 429,
"error_code": 1015,
"error_name": "rate_limited",
"error_category": "rate_limit",
"retryable": true,
"retry_after": 30,
"owner_action_required": false,
"what_you_should_do": "**Wait and retry.** This block is transient. Wait at least 30 seconds, then retry with exponential backoff."
}
重要意义
核心价值不是格式选择,而是语义稳定性。Agents 需要确定性答案来回答操作问题:重试与否、等待多长时间、是否升级。Cloudflare 在两种 wire 格式中暴露一个策略契约。无论客户端消费 Markdown 还是 JSON,操作含义都相同。
对比
- Transient errors (如 1015): "等待并重试"
- Intentional blocks (如 1020, 1009): "不要重试,升级"