opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[bug] Token usage info WAY off, failed request

Open akuuly-7 opened this issue 1 year ago • 8 comments

Hey @thdxr ,

just tried to use opencode to generate me some overviews and dunno what exactly happened, but the token usage is WAY off and the request failed. Even the TUI flickered for som reason while "working..." showed at the bottom - there also were 2 prompts at the same time (there were two subfolders, so it created 2 agents??) - might be a feature (not sure).

Obviously, also the price was higher - no $0.01, but $0.18.

Here is the share link: https://dev.opencode.ai/s/522f35d1


Also, attaching a screenshot of the TUI:

Image

And even the Anthropic Usage info, so you see the difference in token usage and at the bottom - blocked API calls...

Image

Here are the logs - it sent a quite a lot of requests too (blurred the request ids just in case):

Image

EDIT: yup, it spawned 2 child sessions and everything was going off at the same time - both produced $0.06 (which still doesnt add up to $0.18 of costs, but we're getting there) and around 20k of tokens each - everything together created a lot of load on the API - this thing should/could be handled somehow on the opencode's side IMHO - to detect the size before sending it off (maybe an Anthropic API mode VS the Claude Pro/Max mode where it compresses more agressively)

akuuly-7 avatar Jun 17 '25 19:06 akuuly-7

Going to bed, gonna come back in around 10 hours time (if any input is needed)

akuuly-7 avatar Jun 17 '25 21:06 akuuly-7

if possible can you open up the session again and do /share and see if the cost listed on that page is the same?

thdxr avatar Jun 18 '25 00:06 thdxr

if possible can you open up the session again and do /share and see if the cost listed on that page is the same?

Didn't change much on the last message, but it worked and produced an output :) See the share link

akuuly-7 avatar Jun 18 '25 04:06 akuuly-7

The compacting command from #180 could help :)

akuuly-7 avatar Jun 18 '25 11:06 akuuly-7

Even the TUI flickered for som reason while "working..." showed at the bottom

Not sure if related, but I noticed this same "flickering" in the TUI. It happened for about 20 seconds (or so) rapidly while this "TASK ..." message was shown. As if stuff was happening in the background. Eventually it stopped and then displayed the last message shown in my screenshot.

Image

I use a proxy so was monitoring the requests it was sending during this time and while it sent multiple (a few) it definitely was NOT spamming a bunch of API calls... this leads me to believe it was maybe doing tool calls locally or mcp stuff or something in the background?

GitMurf avatar Jun 18 '25 22:06 GitMurf

Just tried using OpenRouter and this is the result:

Image

Percentages and cost don't seem right at all. Here are the real ones (also why was the last prompt 33k tokens :D):

Image

Share doesn't really work either, throws a 500... But here's the link anyway: https://dev.opencode.ai/s/7c052e39

EDIT: a rather simple prompt to make a change in an ETL script cost me 2 dollars and used 500k tokens

akuuly-7 avatar Jun 19 '25 09:06 akuuly-7

the % is off because when you configure a custom provider + model you have to specify what the max content length is

i'm looking into getting openrouter to use input token caching though

thdxr avatar Jun 19 '25 14:06 thdxr

i got it working and it's released in 0.1.94 - i can see in the openrouter dashboard caching is drastically decreasing cost

going to close this issue for now because it's mixing a few different problems - feel free to reopen more specific ones

thdxr avatar Jun 19 '25 14:06 thdxr