anthropics / anthropics/claude-code

Gateway model discovery pricing is ignored by /usage

Aperta
#88,659 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
area:api area:cost enhancement platform:macos
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
api, backend-api-design
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.