Skip to content

Token count is way off #5951

Closed
Closed

Description

@abdurahmanshiine

Description

Hey there,

I started using OpenCode today and I got an out-of-credit error very quickly, that surprised me because the token count in OpenCode said: ~85k tokens, but when I went to the billing page of my API provider (Fireworks AI) it said I had used close to 3.55m tokens, which is a crazy gap. And so I'm wondering where is that difference coming from

OpenCode version

1.0.185

Steps to reproduce

No response

Screenshot and/or share link

Image Image

Operating System

WSL

Terminal

Windows Terminal

Activity

  1. github-actions commented on Dec 22, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. abdurahmanshiine commented on Dec 22, 2025

    @abdurahmanshiine
    Author

    Taking a look at the stats I got this, which is really weird because I have only sent 12 messages (and not 75)

    Image
  3. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    and u only used fireworks in opencode? that usage couldn’t be from elsewhere?

    That big of a gap just doesnt make sense UNLESS the session that this happened in had a bunch of subagent calls?

    Rn it only shows the parent totals instead of including subagent costs and token usage

  4. self-assigned this
    on Dec 22, 2025
  5. abdurahmanshiine commented on Dec 23, 2025

    @abdurahmanshiine
    Author

    and u only used fireworks in opencode? that usage couldn’t be from elsewhere?

    Yes, I actually created one Fireworks account specifically to use it with OpenCode, and I didn't use any subagents (I didn't even know how to invoke them until I checked now 😅 )

    Not sure if it changes anything, but most of the messages in the convo (~10 of them) were using the planning mode, and only 2-3 used building mode

  6. coreyward commented on Jan 9, 2026

    @coreyward

    Rn it only shows the parent totals instead of including subagent costs and token usage

    @rekram1-node Yikes. That caught me off guard as well. I set up a brand new key to use OpenCode with Claude Opus 4.5 via API. I sent a single prompt/request in plan mode and it used a bunch of subagents to gather context. The TUI reported this as $0.16 of usage. The Anthropic billing dashboard, however, reported as $2.14. That's 13× the reported price.

    Image Image
  7. yassine-safraoui commented on Jan 27, 2026

    @yassine-safraoui

    I ran into a similar bug, but it's a little more specific. I was in a thread and decided to fork it from a certain message, then I started using a different model in the new fork. As I kept using the fork thread, I noticed the total price actually started decreasing. It looks like the math is flipped—instead of adding the cost of the new messages to the total, the system is performing a minus operation, so the more I talk, the "cheaper" the thread gets. Definitely seems like there's a bug in how the cost is being calculated, not sure what the root cause of. this is.

  8. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

  9. coreyward commented on Apr 2, 2026

    @coreyward

    ^^^ Bummer that this is closed as "completed" when it never got any attention. I stopped using OpenCode because of it. Oh well.

  10. Pxys-io commented on Apr 3, 2026

    @Pxys-io

    @thdxr This issue is reported multiple times and isnt fixed and continuously gets auto-closed, tia

    Update: Investigated the issue and found that the root cause lies in models.dev pricing and how the app handles missing pricing data. specifically, when cache pricing is absent, it defaults to zero. I've submitted a PR to models.dev to fix the missing cache price, and another PR is coming to opencode to fall back to the input/output price for read/write cache. I believe it's safer to overestimate the cost of a chat than to underestimate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions