anthropics / anthropics/claude-agent-sdk-python
[BUG] Incorrect total_cost_usd being returned by the SDK.
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 1.3k
- 平均合并
- 2 天 31 分钟
- 30 天内合并 PR
- 1
描述
### 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):**
**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):**
**For that usage, here's how the cost looks like for Sonnet 4.6 and Opus 4.6:**
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.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。