# 价格

URL: https://docs.router.ezat.io/zh/pricing

> 每个模型每百万 token 的实时价格、每个价格列的含义、长上下文档位，以及如何根据 usage 算出一个请求的费用。

## 何时阅读本页

你想知道某个模型的价格、哪些 token 按哪种价格计费，或者想根据响应中的 `usage` 估算一个请求的费用。余额如何扣费见[计费方式](https://docs.router.ezat.io/zh/billing.md)。

## 价格

| 模型 id | 输入 | 输出 | 缓存写入（5 分钟） | 缓存写入（1 小时） | 缓存读取 |
| --- | --- | --- | --- | --- | --- |
| `anthropic/claude-fable-5-1` | $9 (~~$10~~) | $45 (~~$50~~) | $11.25 (~~$12.5~~) | $18 (~~$20~~) | $0.225 (~~$0.25~~) |
| `anthropic/claude-fable-5` | $9.5 (~~$10~~) | $47.5 (~~$50~~) | $11.875 (~~$12.5~~) | $19 (~~$20~~) | $0.95 (~~$1~~) |
| `anthropic/claude-opus-5-5` | $3.6 (~~$4~~) | $18 (~~$20~~) | $4.5 (~~$5~~) | $7.2 (~~$8~~) | $0.18 (~~$0.2~~) |
| `anthropic/claude-opus-5` | $4.75 (~~$5~~) | $23.75 (~~$25~~) | $5.9375 (~~$6.25~~) | $9.5 (~~$10~~) | $0.475 (~~$0.5~~) |
| `anthropic/claude-sonnet-5-5` | $1.8 (~~$2~~) | $9 (~~$10~~) | $2.25 (~~$2.5~~) | $3.6 (~~$4~~) | $0.09 (~~$0.1~~) |
| `anthropic/claude-sonnet-5` | $1.9 (~~$2~~) | $9.5 (~~$10~~) | $2.375 (~~$2.5~~) | $3.8 (~~$4~~) | $0.19 (~~$0.2~~) |
| `anthropic/claude-haiku-5-5` | $0.09 (~~$0.1~~) | $0.45 (~~$0.5~~) | $0.1125 (~~$0.125~~) | $0.18 (~~$0.2~~) | $0.009 (~~$0.01~~) |
| `anthropic/claude-opus-4-8` | $4.75 (~~$5~~) | $23.75 (~~$25~~) | $5.9375 (~~$6.25~~) | $9.5 (~~$10~~) | $0.475 (~~$0.5~~) |
| `anthropic/claude-opus-4-7` | $4.75 (~~$5~~) | $23.75 (~~$25~~) | $5.9375 (~~$6.25~~) | $9.5 (~~$10~~) | $0.475 (~~$0.5~~) |
| `anthropic/claude-opus-4-6` | $4.75 (~~$5~~) | $23.75 (~~$25~~) | $5.9375 (~~$6.25~~) | $9.5 (~~$10~~) | $0.475 (~~$0.5~~) |
| `anthropic/claude-sonnet-4-6` | $2.85 (~~$3~~) | $14.25 (~~$15~~) | $3.5625 (~~$3.75~~) | $5.7 (~~$6~~) | $0.285 (~~$0.3~~) |

实时读取自模型目录。划线价为 Anthropic 官方标价。价格单位为美元 / 百万 token，不含税。

**长上下文**

| 模型 id | 输入 | 输出 | 缓存写入（5 分钟） | 缓存写入（1 小时） | 缓存读取 |
| --- | --- | --- | --- | --- | --- |
| `anthropic/claude-haiku-5-5` > 100,000 | $0.45 (~~$0.5~~) | $2.25 (~~$2.5~~) | $0.5625 (~~$0.625~~) | $0.9 (~~$1~~) | $0.045 (~~$0.05~~) |

价格单位为美元 / 百万 token。每个价格都低于同一模型的 Anthropic 官方标价；旁边的划线价就是官方价。此表实时读取自模型目录（`GET https://api.router.ezat.io/api/models`），所以始终显示当前价格。

请求按开始时生效的价格，对它实际使用的 token 计费。列出模型和计算 token 数都免费。

## 各列的含义

| 列 | 计价对象 | Anthropic 格式 `usage` | OpenAI 格式 `usage` |
| --- | --- | --- | --- |
| 输入 | 既没有写入提示缓存、也不是从缓存读取的输入 token | `input_tokens` | `prompt_tokens` 减去 `cached_tokens` 和 `cache_write_tokens` |
| 输出 | 模型生成的所有 token，包括思考 | `output_tokens` | `completion_tokens` |
| 缓存写入（5 分钟） | 以默认 5 分钟有效期写入缓存的输入 token | `cache_creation.ephemeral_5m_input_tokens` | `prompt_tokens_details.cache_write_tokens` |
| 缓存写入（1 小时） | 以 `"ttl": "1h"` 写入缓存的输入 token | `cache_creation.ephemeral_1h_input_tokens` | 计入 `cache_write_tokens` |
| 缓存读取 | 从缓存读回的输入 token | `cache_read_input_tokens` | `prompt_tokens_details.cached_tokens` |

- `cache_creation_input_tokens` 是两种缓存写入的总和。如果响应没有拆分，全部按 5 分钟写入计费。
- 在兼容 OpenAI 的 API 上，`prompt_tokens` 统计全部输入，无论是否缓存。这个 API 会自动进行提示缓存，使用 5 分钟写入，所以除非你自己设置了 1 小时断点，`cache_write_tokens` 都是 5 分钟写入。见[提示缓存](https://docs.router.ezat.io/zh/guides/prompt-caching.md)。
- 不支持提示缓存的模型（见[模型](https://docs.router.ezat.io/zh/models.md)页的「能力」列）所有输入都按输入价格计费。

### 思考 token

思考 token 属于输出 token，按输出价格计费。在 `/v1/messages` 上，它们计入 `output_tokens`。在兼容 OpenAI 的 API 上，它们计入 `completion_tokens`，`completion_tokens_details.reasoning_tokens` 给出具体数量；思考文本本身不会返回。

## 长上下文档位

部分模型有长上下文档位，列在主表下方的 **长上下文** 中。请求的输入超过表中所示的阈值时适用该档位（在 `GET /api/models` 中，即达到该档位的 `minInputTokens`，也就是阈值加一）。这里的输入指全部输入 token：`input_tokens` 加缓存写入再加缓存读取。

请求超过阈值时，整个请求都按该档位的价格计费，输出和缓存 token 也包括在内，而不只是超出阈值的那部分 token。等于或低于阈值的请求全部按正常价格计费。

## 计算请求费用

把每类 token 数乘以对应的价格，再除以一百万：

```text
cost = ( input_tokens          × Input
       + 5-minute cache writes × Cache write (5 min)
       + 1-hour cache writes   × Cache write (1 h)
       + cache_read_input_tokens × Cache read
       + output_tokens         × Output ) / 1,000,000
```

如果请求超过了所用模型的阈值，就改用长上下文价格。金额保留 12 位小数，所以一个小请求的费用可能不到一美分。

下面的脚本发送一个请求，从公开模型目录读取价格，然后打印这个请求的费用：

```python title="cost.py" test
import json
import os
import urllib.request

import anthropic

client = anthropic.Anthropic(base_url="https://api.router.ezat.io", api_key=os.environ["EZAT_API_KEY"])
message = client.messages.create(
    model="anthropic/claude-sonnet-5-5",
    max_tokens=64,
    messages=[{"role": "user", "content": "Say hello in five words."}],
)

# Prices in USD per million tokens, from the public catalog (no key needed).
with urllib.request.urlopen("https://api.router.ezat.io/api/models") as response:
    catalog = json.load(response)["data"]
name = message.model.lower()  # the response echoes the id or alias you sent
pricing = next(m["pricing"] for m in catalog if name == m["id"] or name in m["aliases"])

usage = message.usage
written = usage.cache_creation_input_tokens or 0
written_1h = (usage.cache_creation.ephemeral_1h_input_tokens if usage.cache_creation else 0) or 0
tokens = {
    "input": usage.input_tokens,
    "cacheWrite5m": written - written_1h,
    "cacheWrite1h": written_1h,
    "cacheRead": usage.cache_read_input_tokens or 0,
    "output": usage.output_tokens,
}

# Above a long-context threshold, the whole request uses that tier's prices.
prompt = tokens["input"] + written + tokens["cacheRead"]
prices = {field: pricing[field] for field in tokens}
for tier in sorted(pricing["longContext"], key=lambda tier: tier["minInputTokens"]):
    if prompt >= tier["minInputTokens"]:
        prices.update(tier["prices"])

cost = sum(count * float(prices[field]) for field, count in tokens.items()) / 1_000_000
print(tokens)
print(f"about {cost:.8f} USD")
```

脚本用目录中的价格进行估算。一个请求实际扣了多少费用，见控制台 **用量** 页面（https://router.ezat.io/zh/usage）的 **最近请求** 中的 **费用** 列。

## 不计费的情况

- 到达模型前就被拒绝的请求：缺少 key 或 key 无效、模型未知、触发限制，或余额为零。
- 失败的请求：提供方返回错误、没有可用容量，或响应因错误中止。
- `POST /v1/messages/count_tokens` 和模型列表。

中断的流式输出按已生成的部分计费，详见[计费方式](https://docs.router.ezat.io/zh/billing.md)。

## 给 AI agent 的说明

1. 价格单位为美元 / 百万 token。从 `GET https://api.router.ezat.io/api/models`（`pricing`，含 `longContext` 档位）或 `https://docs.router.ezat.io/pricing.md` 读取，绝不要硬编码。
2. 费用 = Σ token 数 × 价格 / 1,000,000，涵盖 `input_tokens`、两种缓存写入、`cache_read_input_tokens` 和 `output_tokens`。
3. 思考 token 属于输出 token。
4. 如果 `input_tokens` + 缓存写入 + 缓存读取大于或等于某个档位的 `minInputTokens`，每一部分都按该档位的价格计费。
5. 在兼容 OpenAI 的 API 上，未缓存的输入 = `prompt_tokens` − `cached_tokens` − `cache_write_tokens`。