X6.AI

单请求对账 — Markdown 源文

以下为可直接复制或提供给 AI Agent 的 Markdown 原文。

> **AI Agents**: 索引 `/api/llms.txt` | 英文全文 `/api/llms-full-en.txt` | 中文全文 `/api/llms-full-zh.txt` | OpenAPI `/api/openapi.yaml`
> Base URL: `<BASE_URL>/v1`

# 单请求对账

按一次对话请求的 ID 查询 token 分档与实扣卖价(Teamo 风格)。

```
GET <BASE_URL>/v1/billing/requests/{request_id}
```

## 认证

必需:`Authorization: Bearer <API_KEY>`。仅能查询**本 Key** 产生的请求。

## Path

| 参数 | 说明 |
|------|------|
| `request_id` | 对话成功响应头 **`X-Request-Id`**(与 `X-SNX-Trace-ID` 同值)。勿用 body 里的 `msg_` / `chatcmpl_` / `resp_` id |

调用后通常 **1–数秒** 可查;未落库返回 **404**(可重试)。

## 响应(200)

```json
{
  "request_id": "550e8400-e29b-41d4-a716-446655440000",
  "created_at": 1730700123,
  "model": "claude-haiku-5-5-discount",
  "usage": {
    "input_tokens": 100,
    "cached_write_tokens": 80,
    "cached_write_short_tokens": 80,
    "cached_write_long_tokens": 0,
    "cached_read_tokens": 0,
    "output_tokens": 20,
    "total_tokens": 200
  },
  "amount": {
    "value": "0.001234",
    "currency": "USD"
  }
}
```

| 字段 | 说明 |
|------|------|
| `amount.value` | 客户实扣卖价(`sell_amount`)字符串 |
| `usage.*` | 与 [模型定价](./model-pricing.md) 四档对齐;短/长写缓存为扩展字段 |

TTL 拆桶细节仍以 Messages 响应 `usage.cache_creation` 为准;本接口给出写总量与短/长列。

## 探针建议

1. `GET /v1/billing/balance` 记 before  
2. `POST /v1/messages`(或 chat / responses)→ 读 `X-Request-Id`  
3. poll 本接口 → 核 `amount` 与 token  
4. 可选再拉 balance 做差;时段汇总用 [时段用量](./usage.md)

## 相关

- [账户余额](./billing-balance.md)
- [时段用量](./usage.md)
- [响应头](./response-headers.md)
- [模型定价](./model-pricing.md)