anthropics / anthropics/claude-code

Gateway model discovery pricing is ignored by /usage

オープン
#88,659 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:api area:cost enhancement platform:macos
主要言語
Python
スター
145k
フォーク
23.1k
PR マージ指標
PR 指標を取得中

説明

## Bug description

Claude Code's gateway model discovery reads only `data[].id` and optional `display_name`. It discards a gateway's per-model pricing metadata, so `/usage` applies the built-in fallback tariff to every custom model and reports an inaccurate cost.

Claude Code 2.1.238 currently displays:

```text
Total cost: $0.3181 (costs may be inaccurate due to usage of unknown models)
stealth/ox-alpha: 63.0k input, 134 output ... ($0.3181)
```

The gateway's authenticated `/v1/models` row publishes the model's actual input, output, cache-read, and cache-write prices, and its inference response includes provider-accounted cost details. Neither source reaches Claude Code's local cost table.

## Steps to reproduce

1. Configure `ANTHROPIC_BASE_URL` for an Anthropic-compatible gateway.
2. Set `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`.
3. Select a gateway model whose price differs from Claude's built-in fallback tariff.
4. Send one request and open `/usage`.

## Expected behavior

Gateway discovery should have a documented optional pricing shape that populates the same per-model cost table `/usage` uses. At minimum it should support input, output, cache read, cache write, and web-search rates with explicit units.

## Actual behavior

The documented discovery response consumes only `id` and `display_name`. The installed 2.1.238 bundle validates the same two fields, strips the rest, and falls back to the default built-in tariff for unknown models while marking the estimate inaccurate.

## Environment

- Claude Code 2.1.238
- macOS arm64
- Anthropic-compatible custom gateway through `ANTHROPIC_BASE_URL`
- Gateway discovery enabled

## Additional context

The official gateway protocol already makes `/v1/models` the model-discovery boundary. Extending that response is safer than asking launchers to mutate the undocumented `additionalModelCostsCache` in `~/.claude.json`, and lets `/usage` stay accurate after an in-session `/model` switch.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start at the authenticated /v1/models discovery response and trace how its data[].id and display_name fields reach the /usage cost table. Define and document the optional input, output, cache-read, cache-write, and web-search pricing shape, then verify that a discovered gateway model uses those rates without the unknown-model warning.

索引モデルが issue の本文から書いたものです。

評価

領域
api, backend-api-design
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。