Skills & Usage

hm_tokens

Report one turn's AI token usage and what it was spent on

hm_tokens reports how many tokens one agent turn used, which model and tool it ran on, and what kind of work it was. HyperMemory turns these reports into the token usage views in your dashboard and, for organizations, across every member.

Agents call it once per turn, during end-of-turn finalization. The HyperMemory plugins do this for you through their memory-writer agent.

Parameters

ParameterTypeDescription
session_idstringRequired. The conversation’s id.
turn_sequenceintegerRequired. The turn’s number in the session, starting at 1. Together with session_id it makes a report unique; a repeated report is flagged as a duplicate, not counted twice.
ai_toolstringRequired. The client, e.g. claude_code, codex, cursor, claude_desktop, chatgpt.
providerstringRequired. The model provider, e.g. anthropic, openai, openrouter.
modelstringRequired. The exact model id.
measurement_qualitystringRequired. How the counts were obtained — see below.
segmentsarrayRequired. What the turn was spent on — see below.
input_tokens, output_tokens, total_tokensintegerToken counts.
cache_tokensintegerCached prompt tokens.
cache_accounting"separate" | "included_in_input"Whether cache_tokens are counted inside input_tokens. Default separate.
reasoning_tokensintegerReasoning tokens, when the model reports them.
billing_accountstringWhat the call was billed to — see below.
estimation_biaslow | neutral | highOnly with self_estimated: whether the estimate is likely low, about right, or high.
uncertainty_percentageintegerOnly with self_estimated: how far off it may be (0–100). Include only when you can justify it.
cost_usd, cost_qualitystringCost, if the client knows it. Omit both when unknown.
ai_account_id, provider_event_idstringOptional identifiers.

measurement_quality

ValueUse when
client_exactThe client exposes exact usage (API hooks, Codex app-server, SDKs).
self_estimatedThe agent estimates its own usage (Claude Desktop, ChatGPT and other consumer apps). Include estimation_bias.
provider_actualReserved for usage HyperMemory imports from a provider account. Agents never send it.
unavailableThe client can’t measure or estimate usage. Send no token counts or cost.

segments

Each segment is { "category": ..., "weight": 1–100 }. Categories must be unique and weights must total exactly 100. Make the turn’s real work the largest share.

Category
codingwritingresearch
reasoningplanningdesign
doc_processingcalculationsautomation
productivitychattingpersonal
memorycontextunmatched

Use memory only for HyperMemory’s own overhead and context only for reading. Deployment, testing and debugging count as coding.

billing_account

ValueMeaning
subscriptionA plan: Claude Pro/Max, ChatGPT Plus/Pro, or Codex/Claude Code on a plan.
api_key:<id>An API key id (OpenAI key_..., Anthropic apikey_..., an OpenRouter key hash).
project:<id>An OpenAI project.
workspace:<id>An Anthropic workspace.

When an administrator connects that provider account, HyperMemory imports the provider’s own usage and replaces the reports that declared the same billing account. Reports without a billing account stay counted beside the import — so totals are exact only when agents declare it.

Response

FieldDescription
event_idThe stored report’s id.
duplicatetrue when this session_id + turn_sequence was already reported.
provider_verifiedtrue once the report has been matched by usage imported from the provider.

The server records the time it received the report.

Example

{
  "session_id": "b2fc5ddb-3818-4894-9d1d-849f890c9926",
  "turn_sequence": 3,
  "ai_tool": "claude_code",
  "provider": "anthropic",
  "model": "claude-opus-5-5",
  "measurement_quality": "self_estimated",
  "input_tokens": 82000,
  "output_tokens": 3100,
  "total_tokens": 85100,
  "estimation_bias": "neutral",
  "billing_account": "subscription",
  "segments": [
    { "category": "coding", "weight": 70 },
    { "category": "research", "weight": 20 },
    { "category": "memory", "weight": 10 }
  ]
}

If validation fails, the error says which field is wrong. Correct the payload once; don’t retry it unchanged.

Equivalents

curl -X POST https://api.hypermemory.io/api/v1/memory/hm_tokens \
  -H "Authorization: Bearer $HYPERMEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -d @turn.json