Skip to content

Fix thinking-token cost undercount; send Gemini images at low resolution - #4

Merged
howarddc merged 1 commit into
mainfrom
fix/gemini-cost
Sep 27, 2026
Merged

howarddc merged 1 commit into
mainfrom
fix/gemini-cost

Conversation

@howarddc

Copy link
Copy Markdown
Owner

Summary

  • Cost fix (all providers): estimates now bill everything in total_tokens beyond the prompt as output, so thinking tokens reported outside completion_tokens (Gemini) are counted. OpenAI reasoning (already inside completion_tokens) isn't double-counted. Logs show a Thinking Tokens figure when present; the monthly spending limit uses the corrected amounts. A real Gemini log row re-prices from $0.000324 to $0.000489.
  • Gemini at low resolution: Gemini moves from the OpenAI-compatible endpoint to the native Interactions API (v1beta/interactions, x-goog-api-key) so images are sent with resolution: "low" (280 tokens vs the 1,120 default). Requests use store: false. Parses model_output steps, maps incomplete/failed status, reads total_thought_tokens. Thinking level is left at the model default (minimal for Flash-Lite) instead of forcing low.

Testing

  • Harness tests against Google's documented request/response shapes: endpoint, auth header, body (store:false, inline base64, resolution: low), text parsing, truncation/failure statuses, cost with thinking tokens; OpenAI and DeepInfra requests and costs unchanged (13/13 pass)
  • Verified with a real Gemini key on a live site via the 1.1.0-beta.3 ZIP

🤖 Generated with Claude Code

- Cost estimates bill everything in total_tokens beyond the prompt as
  output, so thinking tokens reported outside completion_tokens (Gemini)
  are counted. OpenAI's reasoning (already inside completion_tokens) is
  not double-counted. Logs show a Thinking Tokens figure when present.
- Gemini moves from the OpenAI-compatible endpoint to the native
  Interactions API (v1beta/interactions, x-goog-api-key) so images can be
  sent with resolution "low" (280 tokens vs 1,120 default). Uses
  store:false, parses model_output steps, maps status incomplete/failed,
  and reads total_thought_tokens. Thinking level is left at the model
  default (minimal for Flash-Lite) instead of forcing "low".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@howarddc
howarddc merged commit ded810f into main Sep 27, 2026
4 checks passed
@howarddc
howarddc deleted the fix/gemini-cost branch September 27, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant