LLM token usage and cost returned by the provider are discarded
Current-main boundary
On main 007a1a7 (0.9.30), OpenAIProvider reads only choices[0].message from the response. The usage object (prompt, completion, cached and reasoning tokens) is dropped. OpenRouter now includes usage.cost in every response by default, so the exact charge of each background call is already in hand and thrown away.
The user problem
Compression, summaries, consolidation and graph extraction call the LLM in the background. To learn what they cost I have to read OpenRouter's /api/v1/key usage counter before and after a run and subtract, which also counts any other traffic on the key and lags by a few seconds. I cannot see which agentmemory function spends the money, or whether a model change (for example turning reasoning off) reduced output tokens.
Required behavior
- When a response carries
usage, agentmemory keeps running totals for the process: calls, prompt tokens, completion tokens, and cost when the provider reports it. GET /agentmemory/statusshows the totals underprovider.- Responses without
usagechange nothing; no extra request field is sent.
Acceptance checks
Provider tests with and without usage (and with and without cost); a status test that shows the totals.
Source and existing work
OpenAIProvider response handling.
Environment: agentmemory 0.9.30, Node v26.10.0, macOS 27.0.1 (arm64).