Repository navigation
Claude Code 1.0.9 no longer reports the costUSD field #4
Description
Activity
Hi nnamon!
Yes, I think we can integrate with https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json file.
This is my inital thought by the way.
I'll work on it tomorrow(maybe Claude Code can write code for my while I'm sleeping!)Thank you for letting me know!
Reacted by nnamon and doyeongkso it's related to #3
So I'm working on the updated version,
and I found the cost mismatch---log File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl Timestamp: 2025-05-25T19:16:15.368Z Model: claude-opus-4-20250514 Original cost: $0.064230 Calculated cost: $0.128459 Difference: $0.064230 (100.00%) Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122}Wow, the original reported cost being half of the actual API price is quite a big discrepancy.
This only happens in opus model. Here is the summary by Claude Code:
⏺ Looking at the conversation history and the current state of the codebase, I can see that: 1. The initial issue where bun ./index.ts -s 20250603 showed tokens but zero cost has been fixed by correcting the schema to place the model field inside the message object. 2. A verification script was created that revealed: - 83.34% of entries with both costUSD and model match the new calculations - 16.66% show mismatches, all with exactly 2x difference - All mismatches are for the claude-opus-4-20250514 model - This indicates the pricing for this model has doubled since the original calculations 3. The verification script has been kept as requested and shows detailed results including model-by-model breakdowns. The user's requests have been completed: - The bug was fixed - The pricing verification was performed - The verification script was kept - Full results were shown The codebase is now working correctly with the fixed schema and can handle both old entries (with pre-calculated costUSD) and new entries (with model field for dynamic cost calculation).
As far as my understanding, the price hasn't changed
I need your help!!!!!
I have pushed the validation scripts to the alpha branch.
https://github.com/ryoppippi/ccusage/blob/91adb43e7bdb34f1808f5f8e49f54809924cfbe8/verify-pricing.ts
I would like you guys to test the script and report it here. This helps me to improve
ccusage. Thanksgit clone https://github.com/ryoppippi/ccusage cd ccusage git checkout 91adb43 bun i bun ./verify-prising.tsAlso, you can test the new one by
bun ./index.tsI've attached the output from my box.
Looks like it's mostly matching with 3% discrepancy. Awesome work! :)
Reacted by ryoppippi@nnamon
Thank you for your report.
This is interesting because in your environment, all of the difference comes fromsonnet, while my issue comes fromopus.Could probably be because I usually use sonnet most of the time and the error came from a bugged version? I sampled a few of the files, they were all from versions 1.0.7.
Oh really? How did you find the log comes from version 1.0.7
In my log, I found a mimatch before releasing 1.0.7 🤔
--- File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl Timestamp: 2025-05-25T19:16:15.368Z Model: claude-opus-4-20250514 Original cost: $0.064230 Calculated cost: $0.128459 Difference: $0.064230 (100.00%) Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122} --- File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl Timestamp: 2025-05-25T19:16:15.368Z Model: claude-opus-4-20250514 Original cost: $0.064230 Calculated cost: $0.128459 Difference: $0.064230 (100.00%) Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122}Here are my logs in case they help you with the investigation. I run your scripts using ts-node because I don't have bun installed. I always restarted claude code as soon as I saw the message "Update installed. Restart to apply"
Reacted by ryoppippi@itsUndefined
Thanks. It looks like you can run it successfully.Oh
81.9%matches? hmm3 remaining items
That's just the output of running
ts-node index.tson the commit91adb43, not sure if it's actually "good"I've got a modified verified-pricing.ts which dumps the version:
=== Discrepancy Analysis === Cost ratio patterns (calculated/original): 2.0x: 322 occurrences (100.0%) === Version Summary === Total unique versions: 9 Entries per version: 1.0.3: 6,220 entries (55.1%) 1.0.7: 3,127 entries (27.7%) 1.0.4: 687 entries (6.1%) 1.0.5: 548 entries (4.9%) 1.0.9: 384 entries (3.4%) 1.0.6: 193 entries (1.7%) 1.0.8: 102 entries (0.9%) 1.0.2: 16 entries (0.1%) 1.0.0: 10 entries (0.1%) === Version Discrepancy Summary === Versions with discrepancies: 1 Discrepancies per version: 1.0.7: 322 discrepancies (10.3% of version entries, 100.0% of all discrepancies)verify_pricing_output_with_version.txt
Though, it could be just something on the server side end during that same time period for all of us that was reporting the wrong costUSDs regardless of version as @itsUndefined mentioned.
Thank you guys! I'll preparing for the script!
Hi! I pushed the new script. Check it out!!
Reacted by Themistoklis ChatziemmanouilReacted by Themistoklis ChatziemmanouilReacted by Themistoklis ChatziemmanouilI tried it myself, but I haven't used it much, so I don't know if it will be of any help. I ran it on the claude v1.0.3 and the v1.0.9.
log file: https://gist.github.com/mimikun/f10f44ac8417d52904fd96c42d8e2d5e
In my case, there was no difference in the numbers. I haven't used claude cli yet after updating.
Reacted by ryoppippi- changed the title
[-]Claude Code 1.0.9 no longer reports the costUSD field[/-][+]Claude Code 1.0.7 no longer reports the costUSD field[/+]on Jun 3, 2025 @mimikun I guess you are using API usage plan right? not max
verify-pricing-new.txt , using Max Plan 5x
Reacted by ryoppippi@mimikun I guess you are using API usage plan right? not max
I forgot to mention. sorry. that I am using for the Max Plan (100 USD/month).
- changed the title
[-]Claude Code 1.0.7 no longer reports the costUSD field[/-][+]Claude Code 1.0.9 no longer reports the costUSD field[/+]on Jun 3, 2025 Thanks guys!!
Based on the verification so far.
costUSDvalues are different from API prices- API calculations are partly correct and partly incorrect
For now, we will incorporate this mechanism and create a new version
Awesome work @ryoppippi, thank you!
THANK YOU GUYS.
JUST PUBLISHED!!!!GIVE ME FIVE!!!
Reacted by Themistoklis Chatziemmanouil and Savvy RaghuvanshiReacted by Savvy Raghuvanshi
It appears that Claude Code 1.0.9 no longer includes the costUSD field that ccusage is using to track the costs in the session log files:
The model and token counts are still included, however. This probably means that the costs could be calculated for these by multiplying them with their listed prices?