anthropics / anthropics/claude-agent-sdk-python

[BUG] Incorrect total_cost_usd being returned by the SDK.

オープン
#609 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
8.1k
フォーク
1.3k
平均マージ
2日 31分
マージ済み PR(30日)
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):**
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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。