Skip to Content

How do I track the cost of each session in OpenHands?

Rius records each OpenHands conversation as one trace and prices every model call inside it, once you set three OpenTelemetry environment variables. No plugin and no code changes are needed. The conversation id becomes the Rius session, so a multi-turn conversation groups together with its cost. Cost is a list-price estimate in US dollars, and SDK scripts that call Claude or GPT-4o report it in full.

How it works

The OpenHands SDK already traces every conversation with OpenTelemetry. When it finds the OTLP variables, it sends the spans to Rius, and Rius computes the cost. You never send a cost value.

  • One trace per conversation. The trace holds the conversation, each agent.step, and the model and tool calls inside it.
  • Cost per model call. The span for each model call carries the model, input and output tokens, cache reads and writes, and the cost. Rius prices them from LiteLLM’s public model-price catalog, so the figures are list-price estimates, not billed amounts.
  • Session grouping. The conversation id is the Rius session.
  • Example. A Claude Haiku 4.5 run of a small coding task made four model calls: 31,091 input tokens, 966 output tokens and $0.0175 in all.

What OpenHands does not report:

  • OpenAI Responses API models (GPT-4.1, GPT-5) have no token data, so they have no cost.
  • The local web app streams its model calls, and streamed calls record no usage. Web-app traces show prompts, answers and tool calls, but no tokens or cost.
  • OpenHands Cloud cannot send to Rius, because Cloud agents take no custom environment variables.

Set it up

  1. Install the OpenHands SDK on Python 3.12 or newer, and create a Rius API key with the Send telemetry scope under Settings → API keys. The OpenHands guide covers both in full.
  2. Set the three variables in the environment of the process that runs your agent. The protocol must be http/protobuf, the path must be the full /v1/traces, and the space after Bearer is written %20:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://ingest.eu.console.rius-glassflow.com/v1/traces export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer%20ri_..."
  1. Run your script from its own directory. The conversation appears in the trace list within a few seconds, named after the script or after agent.name if you set it.
  2. To see cost per developer as well, pass user_id when you create the Conversation. Every span then carries it:
conversation = Conversation( agent=agent, workspace=".", user_id="dev@example.com", observability_metadata={"agent.name": "fib-writer"}, )
  1. Run a conversation, then open it in the trace list and click the span for a model call to see its tokens and cost.

Without user_id, conversations land in the anonymous row on the Users page.

What you get

  • Cost on every model call, with tokens and cache reads and writes, so you can go from an expensive conversation to the step that drove it.
  • Cost per conversation in the trace list. You can find any conversation by agent, status, cost or error.
  • Cost over time. The Usage and cost view breaks cost and tokens down by model and agent.
  • Cost per agent. The Agents page shows each OpenHands agent’s traces, errors and cost on one page.
  • Cost per developer. With user_id set, the Users page lists each developer with traces, failures and cost.
  • Alerts on spend. A custom alert can fire on, for example, average cost per conversation above $0.50 for one agent.
  • Questions in plain language. With the Rius MCP server connected, you can ask what an agent cost per day this week.

Cost is an estimate at API list prices. An unknown model gets an empty cost, not zero.

When something else fits

  • If you run the OpenHands web app or OpenAI Responses API models, Rius shows the conversations but not their cost. SDK scripts with Claude or GPT-4o give full cost.
  • If you also use other coding agents, see Coding agents. The plugin traces Codex sessions (beta) with tokens and cost, and Cursor sessions (beta) without them, because Cursor’s hooks do not report usage.
  • To roll cost tracking out across a team, Track Claude Code usage and cost across a team shows the shared-workspace setup. OpenHands can send to that same workspace with an API key from it.

Still stuck? Get help

Last updated on