> ## 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 天
