anthropics / anthropics/claude-agent-sdk-python

[BUG] Incorrect total_cost_usd being returned by the SDK.

Aperta
#609 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
8.1k
Fork
1.3k
Merge medio
2g 31m
PR unite (30g)
1

Descrizione

### Problem:
1. I'm using Sonnet 4.6,
2. The agent is infact using Sonnet 4.6,
3. The usage values are right (token consumption)
4. I am being charged for Sonnet 4.6
5. But the total_cost_usd aligns with that of Opus 4.6.

### How I've verified
I've created a new API key on platform.claude.com, and I've monitored a run for a very simple "hello good morning" message. My system prompt's too large, so that's the reason why the cache_creation_tokens are through the roof.

**Before (New API key):**
Image

**The usage & cost values:**
```
"value": {
"usage": {
"input_tokens": 3,
"cache_creation_input_tokens": 60710,
"cache_read_input_tokens": 2170,
"output_tokens": 122,
"server_tool_use": {
"web_search_requests": 0,
"web_fetch_requests": 0
},
"service_tier": "standard",
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 60710
},
"inference_geo": "",
"iterations": [],
"speed": "standard"
},
"total_cost_usd": 0.38358749999999997
}
```

**After run (Claude Platform):**
Image

**For that usage, here's how the cost looks like for Sonnet 4.6 and Opus 4.6:**
Image
As you can see, the Agent SDK's total_cost_usd aligns with Opus 4.6 despite the agent actually using Sonnet 4.6.

**What I've tried:**
Apart from passing the model as a parameter to the agent, I've also defined it in the settings.json (assuming some CLI setting is messing it all up), but it was all in vain.

How do I get the right cost values from Claude Agent SDK? Is this a bug in the CLI binary / the SDK, or a problem with my configuration?
I'm passing in the model as a parameter to the agent, and the agent is running all fine, but why is the cost value wrong?
Please let me know if you need any more information.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.