OpenClaw Finally Counts HTTP API Tokens Where Operators Spend Money

Agent cost dashboards have a simple failure mode: they look useful while quietly ignoring the path where the money is actually spent. OpenClaw PR #96227 fixes one of those failures. OpenAI-compatible HTTP ingress traffic was emitting model-call events, but not model.usage, the event that downstream consumers use for token and cost accounting. For deployments that put OpenClaw behind /v1/responses or /v1/chat/completions, that is not a missing chart. It is a budget-control bug.

The patch is tiny on paper: 57 additions, zero deletions, one changed file, src/gateway/openresponses-http.ts. The operational impact is larger because HTTP ingress is how agent gateways become production infrastructure. Chat channels are where teams demo agents. HTTP-compatible APIs are where those agents get wired into internal tools, CI systems, product workflows, automation scripts, and other software that does not care how charming the Slack bot is.

The linked issue, #96093, lays out the bug cleanly. model.usage was emitted in two paths: runReplyAgent for channel message loops and finalizeCronRun for scheduled jobs. HTTP ingress takes a different route: handleOpenResponsesHttpRequest → runResponsesAgentCommand → agentCommandFromIngress({ deliver: false }) → runAgentAttempt. That path returned usage in the HTTP response body and persisted usage in the session trajectory, but never emitted the diagnostics event Langfuse, OpenTelemetry, and Prometheus subscribers expected.

The response had the tokens. The observability pipeline did not.

The reproduction is the useful part. A POST /v1/responses call returned 200 with response usage including input_tokens: 17091, output_tokens: 1, and total_tokens: 25156. The session trajectory also persisted model.completed.usage with input, output, cache-read, and total breakdown. So the data existed. It was not a provider issue, not a tokenization mystery, and not a Langfuse subscriber outage. The HTTP handler simply did not emit the event that the rest of the diagnostics stack was built to consume.

That distinction matters because observability bugs often get misdiagnosed as dashboard bugs. “Langfuse has no trace” sounds like an integration problem until you follow the event contract. The issue reporter did the right thing: verify the response body carried usage, verify the subscriber received nothing, verify other webchat traces still worked, and identify the runtime path that bypassed event emission. This is the kind of evidence operators should demand before accepting “the dashboard is flaky” as an explanation.

PR #96227 fixes the gap by extracting usage from result.meta.agentMeta.usage after the agent run completes in the OpenResponses HTTP handler and emitting model.usage with the same normalizeUsage and estimateUsageCost helpers used by the channel paths. That is the right design choice. It preserves one accounting contract across ingress paths instead of inventing HTTP-specific cost plumbing that every exporter would need to special-case.

Partial cost data is worse than no cost data

The dangerous thing about this bug is that it fails quietly. If your dashboard shows chat and cron costs, the system appears instrumented. If your production volume is mostly HTTP API calls, the dashboard becomes a partial truth machine. It is not merely incomplete; it is misleading in the direction operators least want. It undercounts the path most likely to scale.

That is especially important in coding-agent systems because cost is not linear in the way teams intuitively expect. Long-context prompts, cache reads, retries, fallback models, subagent fan-out, compaction, tool-result bloat, and provider-specific token accounting all distort spend. A single HTTP call can represent a deep agent run with multiple model calls underneath. If the usage event is missing, budget alerts, tenant accounting, rate limiting, and post-incident analysis all inherit the blind spot.

Usage-based billing is also moving from “nice to know” into governance. Engineering leaders want to know which agent, workspace, route, user, job, or product surface created spend. Security teams want correlation between side effects and model calls. Platform teams want Prometheus metrics that map to invoices. Finance wants fewer surprises. None of that works if one ingress path emits cost and another relies on whoever happens to inspect the response body.

For practitioners, the checklist is direct: test observability by runtime path, not by demo path. Send traffic through local chat, Slack or Discord, CLI, cron, HTTP /v1/responses, HTTP /v1/chat/completions, delegated subagents, native Codex or Copilot bridges, and any embedded gateway mode you expose. For each path, verify the same usage event appears with provider, model, session or run identifiers, input tokens, output tokens, cache reads, total tokens, estimated cost, and enough route metadata to explain where the request came from.

Then test failure and fallback paths. If the first provider fails and the agent retries on another model, does usage capture both attempts or only the successful one? If a subagent performs work on behalf of an HTTP request, is that cost attributed to the parent run, the child run, or nowhere? If context compaction runs before the real task, is that cost visible? Agent spend hides in exactly these edges.

The PR’s limitation is that end-to-end Langfuse/OTEL subscriber testing was not performed because it requires external services. That is understandable for a focused patch, but operators should not stop at unit tests. The real acceptance test is a live subscriber seeing a model.usage event from the HTTP API path and attributing it correctly. If you run OpenClaw as a gateway, build that test into your deployment checklist.

The broader market lesson is that “agent observability” cannot mean pretty traces for chat turns. It has to mean complete accounting across every route by which software asks an agent to do work. OpenAI-compatible APIs make agents easier to integrate, which means they also make blind spots easier to scale. Counting tokens where the billable traffic enters the system is table stakes. OpenClaw is patching the right seam.

The headline is not that a diagnostic event was added. The headline is that enterprise agent gateways cannot be trusted if their API traffic is invisible to cost tooling. If operators spend real money through a path, that path needs real telemetry. Anything else is observability cosplay.

Sources: OpenClaw PR #96227, OpenClaw issue #96093, OpenClaw PR files, OpenClaw plugin hooks docs