anthropics / anthropics/claude-code
Gateway model discovery pricing is ignored by /usage
- Vorherrschende Sprache
- Python
- Sterne
- 145k
- Forks
- 23.1k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
## 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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Bereich
- api, backend-api-design
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100