> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arouter.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取生成记录

> 获取特定已完成生成的费用、Token 用量和元数据。

通过 ID 获取已完成生成的详细元数据。使用此端点可以查看任何历史请求的费用和用量。

## 端点

```
GET /api/v1/generation
```

## 查询参数

| 参数   | 类型       | 必需 | 描述                     |
| ---- | -------- | -- | ---------------------- |
| `id` | `string` | 是  | 来自聊天补全响应 `id` 字段的生成 ID |

## 请求示例

```bash theme={null}
curl "https://api.arouter.ai/api/v1/generation?id=gen-1775226820-719aea642d4b4d279c897793" \
  -H "Authorization: Bearer lr_live_xxxx"
```

## 响应示例

```json theme={null}
{
  "id": "gen-1775226820-719aea642d4b4d279c897793",
  "model": "anthropic/claude-sonnet-4.6",
  "provider": "Google",
  "created_at": "2026-04-03T12:00:00Z",
  "latency_ms": 1240,
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 6,
    "total_tokens": 20,
    "cost": 0.000132,
    "is_byok": false,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "cache_write_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "cost_details": {
      "upstream_inference_cost": 0.000132,
      "upstream_inference_prompt_cost": 0.0000420,
      "upstream_inference_completions_cost": 0.000090
    }
  }
}
```

## 响应字段

| 字段                        | 类型        | 描述             |
| ------------------------- | --------- | -------------- |
| `id`                      | `string`  | 生成 ID          |
| `model`                   | `string`  | 生成响应的模型        |
| `provider`                | `string`  | 处理请求的提供商       |
| `created_at`              | `string`  | ISO 8601 时间戳   |
| `latency_ms`              | `integer` | 请求总延迟（毫秒）      |
| `usage.prompt_tokens`     | `integer` | 输入 Token 数     |
| `usage.completion_tokens` | `integer` | 输出 Token 数     |
| `usage.total_tokens`      | `integer` | 总 Token 数      |
| `usage.cost`              | `number`  | 总费用（USD）       |
| `usage.is_byok`           | `boolean` | 是否使用了用户提供的 key |

## 说明

* 生成元数据通常在请求完成后数秒内即可获取
* 生成 ID 在每个聊天补全响应的 `id` 字段中返回
* 历史数据保留 90 天
