跳转到内容

核对模型和用量

用调用日志和五项检查,核对每次调用的模型、token 用量和费用。

每次调用都记入控制台的调用日志,列出模型,输入、输出、缓存读取和缓存写入的 token 用量,以及费用。

下面的检查对照 Anthropic 接口的公开格式,用于发现返回字段和格式上的差异。

检查预期结果需要留意
1. 返回的 model 字段与请求的模型 ID 一致返回其他模型名,或没有该字段
2. 缓存读取满足缓存条件的同一请求在缓存有效期内发送两次,第二次的 cache_read_input_tokens 大于 0始终为 0,或 usage 中没有缓存字段
3. 工具调用 IDtool_use 块的 id 以 toolu_ 开头其他格式,或模型不按要求调用工具
4. 流式事件顺序依次出现 message_start、content_block_start、content_block_delta、message_delta 和 message_stop只有 OpenAI 格式的 data: 块,或事件缺失、顺序错乱
5. 真实任务对照用一道固定任务,与官方 API 或其他可信来源对比结果结果明显变差、拒答异常或频繁截断

这些检查只能发现字段和格式上的差异,不能单独确认实际使用的模型。model 字段可以被改写,格式也可以被模仿。

需要 bash、curl 和 jq。脚本会发起五次小调用,其中一次缓存写入约 1.8 万 token,按正常价格计费。

verify.sh
#!/usr/bin/env bash
# 用法:ONEZHE_API_KEY=sk-你的API密钥 bash verify.sh [模型ID]
set -euo pipefail
BASE="https://1zheai.com"
MODEL="${1:-claude-sonnet-5-5}"
H=(-H "x-api-key: $ONEZHE_API_KEY" -H "anthropic-version: 2023-06-01" -H "content-type: application/json")
echo "== 1. model 字段"
curl -s "$BASE/v1/messages" "${H[@]}" \
-d "$(jq -n --arg m "$MODEL" '{model:$m,max_tokens:16,messages:[{role:"user",content:"ping"}]}')" \
| jq 'if .error then .error else {id, model, usage} end'
echo "== 2. 缓存:同一请求发两次,看第二次的 cache_read_input_tokens"
LONG=$(printf '这是一段用来测试缓存的固定文本,内容不重要,长度够就行。%.0s' {1..600})
BODY=$(jq -n --arg m "$MODEL" --arg t "$LONG" '{model:$m,max_tokens:16,
system:[{type:"text",text:$t,cache_control:{type:"ephemeral"}}],
messages:[{role:"user",content:"ping"}]}')
for i in 1 2; do
curl -s "$BASE/v1/messages" "${H[@]}" -d "$BODY" | jq -c 'if .error then .error else .usage end'
done
echo "== 3. 工具调用 ID"
curl -s "$BASE/v1/messages" "${H[@]}" \
-d "$(jq -n --arg m "$MODEL" '{model:$m,max_tokens:256,
tools:[{name:"get_weather",description:"查询城市天气",
input_schema:{type:"object",properties:{city:{type:"string"}},required:["city"]}}],
tool_choice:{type:"auto"},
messages:[{role:"user",content:"北京今天天气怎么样"}]}')" \
| jq -r 'if .error then .error.message else (.content[]? | select(.type=="tool_use") | .id) end'
echo "== 4. 流式事件序列"
curl -sN "$BASE/v1/messages" "${H[@]}" \
-d "$(jq -n --arg m "$MODEL" '{model:$m,max_tokens:32,stream:true,messages:[{role:"user",content:"数到三"}]}')" \
| grep '^event:' | uniq

第 3 项用的是 tool_choice: auto。Sonnet 5.5 等 5.x 模型不支持强制指定工具({"type":"tool"} 或 {"type":"any"}),会返回 400 does not support forced tool_choice。

2026-10-15 用 claude-sonnet-5-5 实测的输出如下(第 1 项只保留了关键字段):

text
== 1. model 字段
{
"id": "msg_011Cg3Esh8zeEdLeXAPVALKe",
"model": "claude-sonnet-5-5",
"usage": {
"input_tokens": 518,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 12,
...
}
}
== 2. 缓存:同一请求发两次,看第二次的 cache_read_input_tokens
{"input_tokens":23,"cache_creation_input_tokens":17920,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":17920,"ephemeral_1h_input_tokens":0},"output_tokens":4,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global"}
{"input_tokens":23,"cache_creation_input_tokens":0,"cache_read_input_tokens":17920,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":4,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global"}
== 3. 工具调用 ID
toolu_01UPsdyKX8M9fJTTkDoSKHXA
== 4. 流式事件序列
event: message_start
event: content_block_start
event: ping
event: content_block_delta
event: content_block_stop
event: message_delta
event: message_stop

ping 事件是否出现、出现在哪个位置并不固定,不影响判断。

开启 thinking 后,返回的 thinking 块带 signature 字段,也可以作为一项格式检查。5.x 模型的写法和 4.x 不同,2026-10-15 实测:

模型thinking 参数结果
claude-sonnet-4-6{"type":"enabled","budget_tokens":1024}返回 thinking 块,有思考文本和 signature
claude-sonnet-5{"type":"enabled","budget_tokens":1024} 或 {"type":"adaptive"}都能用
claude-sonnet-5-5{"type":"adaptive"}能用;传 enabled 返回 400,提示只支持 adaptive

5.x 模型的 thinking 块默认只有 signature,思考文本为空字符串。需要看到思考摘要时,加上 "display": "summarized":

json
"thinking": {"type": "adaptive", "display": "summarized"}

使用第三方检测网站时,建议新建一个专用的 API 密钥,测完后删除。

发邮件至 [email protected],附上请求时间、模型 ID、完整的返回内容(删去 API 密钥)和对应的检查项。返回内容或错误信息中的 request id 可以帮助定位这次调用。

直接问模型「你是谁」可靠吗?

不可靠。模型的自我介绍受系统提示影响,在某些提示下会答错自己的版本。核对返回的字段和事件格式更有参考价值。

选的是 Opus,调用日志里为什么出现了 Haiku?

Claude Code 会用 Haiku 模型处理部分后台任务,调用日志里会出现对应的记录。可以用 ANTHROPIC_DEFAULT_HAIKU_MODEL 环境变量指定这类任务使用的模型,见 Claude Code 接入。不使用 Claude Code 时出现这种情况,请把请求时间发至 [email protected]。