Skip to content

[Feature]: Show token usage and rate-limit warnings per turn #70

Description

@shauryagangrade

Problem

Free OpenRouter models are rate-limited and users get no feedback on how
much context they're consuming. ChatOpenAI streams carry usage metadata,
but GCode drops it.

Proposed approach

  • Capture usage/rate-limit info from stream chunks (response_metadata,
    OpenRouter X-RateLimit-* headers).
  • Print a compact footer after each turn: tokens in/out, approximate cost
    (OpenRouter publishes per-token pricing), and remaining rate limit.
  • Add a /usage command or fold it into /history.

Where to look

  • gcode/agent.py:59-79 (_stream), :101-137 (run_turn)
  • gcode/ui.py for footer rendering hooks.

Acceptance criteria

  • A turn prints usage when the provider supplies it; silently omits otherwise.
  • Rate-limit warnings appear before a 429 aborts the request.

Difficulty

Medium.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions