fix(billing): add line items for wand#2543
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryFixed missing billing line items for wand usage by refactoring Key changes:
Impact:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Wand Client
participant API as /api/wand
participant Session as getSession()
participant Stats as userStats (DB)
participant Log as usageLog (DB)
participant Billing as checkAndBillOverageThreshold
Client->>API: POST /api/wand<br/>(prompt, stream, history)
API->>Session: Get authenticated user
Session-->>API: session.user.id
alt Streaming Mode
API->>API: Stream OpenAI response
API->>API: Collect usage data
Note over API: When [DONE] received
API->>API: updateUserStatsForWand(session.user.id, usage)
else Non-Streaming Mode
API->>API: Call OpenAI completion
API->>API: updateUserStatsForWand(session.user.id, usage)
end
Note over API: updateUserStatsForWand flow
API->>Stats: Update totalTokensUsed,<br/>totalCost, currentPeriodCost
API->>Log: logModelUsage(userId, source='wand',<br/>model, tokens, cost)
API->>Billing: checkAndBillOverageThreshold(userId)
API-->>Client: Return generated content
|
There was a problem hiding this comment.
Additional Comments (1)
-
apps/sim/app/api/wand/route.ts, line 127-134 (link)style: removed
workspaceIdandworkflowIdfrom billing attribution - these are still available in scope (from lines 163 and 174-178) and could be useful for tracking usage by workspace/workflowwas removing workspace/workflow attribution intentional for simplification, or should we preserve this for better usage tracking?
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
1 file reviewed, 2 comments
|
@greptile |
* fix(billing): add line items for wand * ack pr comment
Summary
Type of Change
Testing
Tested manually
Checklist