Python

Anthropic 缓存读:cache_read 对上缓存列

官方 Anthropic SDK:cache_read_input_tokens 进缓存列。Fable 5.1 贴纸 $10/$50、缓存读 $0.25 只写在 Fable 行的注释里,不是 MiniMax / Gemma 的价。

本页不发起请求;不收 Key;中转 curl 不在本站。

← 计费示例 · Token 主表 · 官方 usage 文档

输入usage.input_tokensusage.cache_creation_input_tokens
输出usage.output_tokens
缓存usage.cache_read_input_tokens
Python
import os
from anthropic import Anthropic

# Official Anthropic SDK only. Key from env. Never paste a key.
# claude-fable-5-1 sticker is $10 / $50; cache read $0.25/M — Fable row only.
# Do not copy those numbers onto MiniMax or Gemma.
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

message = client.messages.create(
    model="claude-fable-5-1",
    max_tokens=16,
    system=[
        {
            "type": "text",
            "text": ("You are a billing ledger. Keep answers short. ") * 80,
            "cache_control": {"type": "ephemeral"},
        }
    ],
    messages=[{"role": "user", "content": "Reply with one word: ok"}],
)

usage = message.usage
inp = usage.input_tokens or 0                                # 输入(未命中段)
out = usage.output_tokens or 0                               # 输出
cache_read = usage.cache_read_input_tokens or 0              # 缓存列
cache_write = usage.cache_creation_input_tokens or 0         # 写入,不进缓存列

print("输入", inp)
print("输出", out)
print("缓存", cache_read)
print("cache_write", cache_write)
这段打印对上哪一列 · Python · 输入 / 输出 / 缓存
字段对上列说明
usage.input_tokens输入未命中段。有缓存时这是断点之后的 tokens,不是整段 prompt。Fable 5.1 贴纸输入 $10/M。
usage.output_tokens输出对账乘 Fable 5.1 输出 $50/M。不要抄到 MiniMax / Gemma 行。
usage.cache_read_input_tokens缓存唯一按缓存读单价的字段。Fable 5.1 已核缓存读 $0.25/M。没有字段就当 0。
usage.cache_creation_input_tokens输入写入不是折扣。接近输入价。不要记进缓存列。

其它片段

语言片段对上列打开
PythonChat Completions 的 usage 怎么对上输入 / 输出 / 缓存输入 / 输出 / 缓存打开
JavaScriptResponses API 的 usage 怎么对上输入 / 输出列输入 / 输出 / 缓存打开
PythonPrompt Cache 片段:命中率不够就别指望折扣输入 / 输出 / 缓存打开
PythonAstra 输入超过 272K:加价门槛怎么记进三列输入 / 输出 / 缓存打开
JavaScriptAzure 部署名不是 OpenAI model id:usage 仍按部署背后的型号输入 / 输出 / 缓存打开

本页拒绝 zip 安装包与 API Key 表单。片段只从环境变量读 Key(OPENAI_API_KEY / ANTHROPIC_API_KEY / AZURE_OPENAI_API_KEY),页面不发请求、不收密钥;中转 curl、测速和请求构造器不在本站。

Anthropic 缓存读:cache_read 对上缓存列 · OpenAICN