-
-
Notifications
You must be signed in to change notification settings - Fork 57.2k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Request: Expose OpenRouter Usage Cost to Agent Runtime
Summary
Add per-message cost tracking from OpenRouter API responses and expose it to agents so they can append cost information to replies.
Background
OpenRouter includes detailed usage information in every API response, including:
- Token counts (prompt, completion, reasoning, cached)
- Cost in credits (
usage.cost) - Upstream inference cost (
usage.cost_details.upstream_inference_cost)
See: https://openrouter.ai/docs/guides/guides/usage-accounting
Problem
Currently, agents don't have access to per-message cost data from OpenRouter responses. This makes it difficult to:
- Track costs per conversation/session in real-time
- Display cost information to users (e.g., appending to Telegram messages)
- Build cost-aware agent behaviors
Proposed Solution
Expose OpenRouter usage.cost data to agents through one or both of:
- Session context/metadata - Make cumulative and per-turn costs available via
session_statusor similar - Tool/API - Add a way for agents to query recent message costs
Use Case
User wants to see the cost of each agent reply in Telegram:
[Agent response]
💸 Cost: $0.0234
This would help users:
- Monitor spending in real-time
- Understand which conversations are expensive
- Make informed decisions about model selection
Implementation Notes
- OpenRouter already provides this data in
usage.costfield - No additional API calls needed - it's included in every response
- For streaming responses, cost appears in the final SSE message
Additional Context
- User wants to sum costs across multiple model calls within a single reply
- Cost should be appended automatically to messages on Telegram (and optionally other channels)
- This could also enable budget limits, warnings, or automatic model switching
Would this be feasible to implement in the OpenClaw runtime?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request