⚡ RFC 9457 合规错误响应 - AI 代理 token 成本降低 98%
⭐⭐⭐⭐⭐ 核心发现
Cloudflare 宣布现在返回符合 RFC 9457 的结构化 Markdown 和 JSON 错误负载,将重量级 HTML 页面替换为机器可读指令,将 token 使用量减少 98% 以上。
98%+
Token 节省
RFC 9457
标准兼容
自动
无需配置
🐛 之前的问题
当 AI 代理遇到错误时,它们仍然收到我们为浏览器构建的相同 HTML 错误页面:
<!DOCTYPE html>
<html>
<head>
<title>Access denied | example.com used Cloudflare to restrict access</title>
<style>/* 200 lines of CSS */</style>
</head>
<body>
<div class="cf-wrapper">
<h1 data-translate="block_headline">Sorry, you have been blocked</h1>
<!-- ... hundreds more lines ... -->
</div>
</body>
</html>
对于代理来说,这是垃圾。它无法确定发生了什么错误、为什么被阻止,或者重试是否有帮助。
✅ 解决方案
现在,当代理发送以下 Accept 头时,Cloudflare 返回结构化响应:
Accept: text/markdown→ 返回 MarkdownAccept: application/json→ 返回 JSONAccept: application/problem+json→ 返回 JSON (RFC 9457 格式)
之前 vs 现在
| 场景 | 之前 | 现在 |
|---|---|---|
| 速率限制 | "You were blocked" | "You were rate-limited — wait 30 seconds and retry with exponential backoff" |
| 访问拒绝 | "Access denied" | "This block is intentional: do not retry, contact the site owner" |
📦 响应格式
Markdown 响应
---
error_code: 1015
error_name: RateLimiting
category: rate_limiting
retryable: true
retry_after: 30
owner_action_required: false
ray_id: 3c1a3b1f2026a1b2
timestamp: 2026-03-21T12:00:00Z
zone: example.com
---
## What happened
You have been rate-limited because you made too many requests.
## What you should do
Wait 30 seconds and retry with exponential backoff.
JSON 响应 (RFC 9457)
{
"type": "https://developers.cloudflare.com/firewall/cf-firewall-rules/errors#rate-limiting",
"title": "Rate Limiting",
"status": 429,
"detail": "You have been rate-limited because you made too many requests.",
"cf": {
"ray_id": "3c1a3b1f2026a1b2",
"timestamp": "2026-03-21T12:00:00Z",
"zone": "example.com",
"error_code": 1015,
"error_name": "RateLimiting",
"category": "rate_limiting",
"retryable": true,
"retry_after": 30,
"owner_action_required": false
}
}
🔑 YAML Frontmatter 字段
| 字段 | 用途 |
|---|---|
error_code |
错误代码,用于分类 |
error_name |
错误名称 |
error_category |
错误类别 |
retryable |
是否可重试 |
retry_after |
重试等待时间(秒) |
owner_action_required |
是否需要站点所有者介入 |
ray_id |
追踪 ID,用于日志和支持 |
timestamp |
错误时间戳 |
zone |
相关区域 |
🌐 覆盖范围
- 当前: 所有 1xxx 类错误(Cloudflare 平台错误代码)
- 即将: Cloudflare 生成的 4xx 和 5xx 错误
- 自动生效: 无需站点所有者配置
- 浏览器兼容: 浏览器继续获得相同的 HTML 体验
"这些不仅是错误页面,它们是代理网络的指令。"
🎯 代理开发者的价值
- 确定性控制流 - 稳定的模式让代理实现持久的控制流
- 自动化决策 - 可重试性和重试时间指导退避逻辑
- 简化日志 - ray_id、timestamp、zone 使日志和支持交接变得确定
- 无需解析 HTML - 提取稳定键值,无需抓取 HTML 或猜测意图
- 符合标准 - RFC 9457 定义了标准 JSON 形状,任何理解问题详情的 HTTP 客户端都可以解析
📈 技术意义
这是 AI 代理网络的基础设施改进:
- Token 效率 - 98% token 节省使大规模代理工作流更加经济
- 机器可读 - 从"线索"到"指令"的范式转变
- 标准化 - 符合 RFC 9457,行业通用
- 零配置 - 自动适用于整个 Cloudflare 网络