anthropics / anthropics/claude-code

Gateway model discovery pricing is ignored by /usage

Ouverte
#88,659 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
area:api area:cost enhancement platform:macos
Langage dominant
Python
Étoiles
145k
Forks
23.1k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Domaine
api, backend-api-design
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.