agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

LLM token usage and cost returned by the provider are discarded

Open Rex57 opened this issue 1 month ago • 1 comments

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/status shows the totals under provider.
  • Responses without usage change 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).

Rex57 avatar Oct 08 '26 06:10 Rex57