Skip to content

/usage 429 rate limit logged at error level with full stack trace #89

@nathanschram

Description

Description

The /usage command fetches API usage from the Anthropic API. When the API returns a 429 (Too Many Requests) response, the error is:

  1. Correctly surfaced to the user with a friendly message: "Usage API error (HTTP 429): Rate limited by Anthropic — too many requests. Try again in a minute."
  2. But logged at error level with a full Rich stack trace (usage.api_error), producing ~15 lines of log output per occurrence.

Impact

429 is an expected transient condition, not a bug. Logging it at error level:

  • Triggers the untether-issue-watcher auto-reporter unnecessarily
  • Clutters journalctl with multi-line stack traces for non-actionable events
  • May mask genuine errors in log monitoring

Expected behaviour

  • Log 429 at warning level with a single-line message (status code + short description)
  • Reserve error level for unexpected failures (5xx, connection errors, auth failures)
  • Consider logging 4xx client errors (except 429) at error and 429 specifically at warning

Affected files

  • src/untether/telegram/commands/usage.py

Reproduction

/usage  # send 3+ times rapidly to any chat

Logs show:

[error    ] usage.api_error  status=429
│ ❱  829 │   │   raise HTTPStatusError(message, request=request, response=self │
│ │      message = "Client error '429 Too Many Requests' for url ...
HTTPStatusError: Client error '429 Too Many Requests' for url ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions