feat: add settings usage tab with real Anthropic rate limits#590
feat: add settings usage tab with real Anthropic rate limits#590mkarpacts wants to merge 1 commit into
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis pull request introduces a usage tracking system that logs per-model token consumption and costs to a database, exposes usage statistics via an authenticated API endpoint, and adds a new Usage settings tab to display rate-limit information and plan details from Anthropic's API. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (SDK)
participant SDK as claude-sdk.js
participant DB as Database
participant Logs as usage_log Table
Client->>SDK: Send message (receives result with modelUsage)
SDK->>SDK: Process SDK result message
SDK->>SDK: Iterate over message.modelUsage entries
loop For each model usage entry
SDK->>DB: usageDb.log(sessionId, model, tokens, cost)
DB->>Logs: Insert usage metrics
Logs-->>DB: Confirm insert
end
DB-->>SDK: Logging complete
SDK-->>Client: Continue session (errors wrapped in try/catch)
sequenceDiagram
participant User as User
participant UI as UsageSettingsTab
participant API as Frontend API Client
participant Server as /api/usage/current
participant Creds as ~/.claude/.credentials.json
participant Anthropic as Anthropic API
User->>UI: Open Usage tab
UI->>API: Call api.usage.current()
API->>Server: GET /api/usage/current (authenticated)
Server->>Creds: Read Claude credentials
Creds-->>Server: Return claudeAiOauth & accessToken
alt If accessToken present
Server->>Anthropic: POST /v1/messages (minimal request)
Anthropic-->>Server: Return rate-limit headers
Server->>Server: Parse headers into session/weekly objects
end
Server-->>API: Return plan, tier, rateLimits
API-->>UI: Resolve response
UI->>UI: Render plan badges & progress meters
UI-->>User: Display usage & utilization status
User->>UI: Click refresh button
UI->>API: Call api.usage.current() again
Note over UI: Repeat fetch cycle
Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary by CodeRabbit