Skip to content

Feature: Expose OpenRouter usage cost to agent runtime #9016

@vinerima

Description

@vinerima

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:

  1. Session context/metadata - Make cumulative and per-turn costs available via session_status or similar
  2. 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.cost field
  • 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions