fix(opencode): apply long context config pricing - #42919
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Overall: clean fix connecting an advertised-but-unwired config knob, with tests that assert both the wiring and the resulting billing math including the boundary. Item 1 is the only behavioral concern. Thanks! |
|
The boundary case in the new test is pinned to the wrong side for xAI specifically, and it's worth catching now because the test will freeze it. expect(estimate(200_000)).toBe(0.4) // 200,000 × $2/M — base ratexAI documents the opposite:
— https://docs.x.ai/docs/models (read 2026-08-22; the note sits under the text pricing table, and the tables give 200k prompt tokens as the cutoff — e.g. grok-4.6 going $2.00 → $4.00 per million input). "Reaches" is The cause isn't in this PR — The fix is not a global
All read 2026-08-22: https://docs.x.ai/docs/models, https://ai.google.dev/gemini-api/docs/pricing, https://developers.openai.com/api/docs/models/gpt-5.4, https://platform.minimax.io/docs/guides/pricing-paygo. So This cuts both ways, which is why it's worth encoding rather than picking a house style — the same one-token error exists in the other direction elsewhere: Helicone's Re the review's item 3 above — a mirror case one token below is worth adding, but note Also worth flagging alongside item 2: for xAI the whole-request switch is right, and it's right for OpenAI too — "2x input and 1.5x output for the full session", with the input length selecting the output rate. That's what I keep the cross-vendor version of that table with each row carrying the sentence it came from, if it's useful while deciding the tier shape: https://xyzs996.github.io/llm-api-pricing/prices.html#same-number-opposite-answer. Happy to send the boundary test cases as a follow-up PR if you'd rather keep this one scoped to the config wiring. |
Issue for this PR
Closes #42910
Type of change
What does this PR do?
This fixes a bug where locally computed costs do not account for context tiered pricing. For models with higher pricing above a context threshold (e.g. 200k), the local pricing logic continued using the lower tier after the session crossed that threshold.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
Wrote two tests to verify locally with tiered Grok model:
If we want extra confidence, I can build an opencode version off of this change, and retest the grok scenario I flagged in the linked issue. Let me know.
Screenshots / recordings
N/A
Checklist
If you do not follow this template your PR will be automatically rejected.