← Back to changelog

Public API: Per-Message Cost and Tokens

If you drive Nairi from code, you can now see exactly what each turn costs and how many tokens the agent burned, straight from the message itself.

What's new

  • cost_usd on every assistant message — the total cost of the turn in US dollars, with 10-decimal precision.
  • Token breakdowninput_tokens, output_tokens, cache_read_tokens, and cache_write_tokens so you can see where the cost went.
  • model — the exact model identifier the agent used for that turn (e.g. claude-opus-4-7).
  • Returned on both message endpointsGET /api/public/v1/messages/{message_id} and GET /api/public/v1/conversations/{job_id}/messages both expose the same fields, so polling and history reads both get cost.

All fields are populated by Claude Code and OpenCode agents. They're omitted on messages produced by Cursor (which doesn't expose per-call usage) and on older messages from before this rolled out, so check before reading them.

See the message reference for field semantics.

Also in this update

  • Tool fields on progress messagesprogress events now expose tool_use_id, parent_tool_use_id, progress_type, tool_name, and tool_status as top-level fields on the message response. You can correlate a tool_use with its tool_result without parsing the JSON content blob. See the progress message fields reference.
  • API jobs now auto-archive on completion — when an agent signals it's done with an API-driven job (for example after a merged PR), the job is now marked completed and the reason is appended to the conversation as a system message. Previously API jobs stayed active forever and the agent remained assigned to them.