openclaw - 💡(How to fix) Fix Local model token usage not passed through to session logs [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52181Fetched 2026-04-08 01:14:40
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1locked ×1renamed ×1
  • Gateway version: 2026.3.8
  • Local models running on omlx server on network
  • Anthropic model token tracking works correctly

Root Cause

  • Gateway version: 2026.3.8
  • Local models running on omlx server on network
  • Anthropic model token tracking works correctly

Code Example

{"usage": {"prompt_tokens": 14, "completion_tokens": 10, "total_tokens": 24}}

---

{"usage": {"input": 0, "output": 0, "totalTokens": 0}}
RAW_BUFFERClick to expand / collapse

Problem

When the gateway proxies requests to local models (e.g. oMLX on machinename), the usage object in session JSONL files shows all zeros for token counts, even though the upstream server returns valid prompt_tokens, completion_tokens, and total_tokens.

Evidence

oMLX response includes correct usage:

{"usage": {"prompt_tokens": 14, "completion_tokens": 10, "total_tokens": 24}}

But the session JSONL records:

{"usage": {"input": 0, "output": 0, "totalTokens": 0}}

Expected

The gateway should map the OpenAI-format usage fields from local model responses into the session log usage object, the same way it does for Anthropic models.

Context

  • Gateway version: 2026.3.8
  • Local models running on omlx server on network
  • Anthropic model token tracking works correctly

Impact

No visibility into local model token consumption. Can't track usage, compare model efficiency, or monitor load on the local inference server.

extent analysis

Fix Plan

To resolve the issue, we need to update the gateway to correctly map the OpenAI-format usage fields from local model responses into the session log usage object.

Steps:

  • Update the gateway's request proxying logic to parse the usage object from the local model response.
  • Map the prompt_tokens, completion_tokens, and total_tokens fields to the corresponding fields in the session log usage object.
  • Ensure the gateway correctly handles cases where the local model response may not include all usage fields.

Example Code:

# Assuming the gateway uses Python and a similar request/response handling framework
def proxy_request(request):
    # ... (existing code)

    # Parse the local model response
    response_json = response.json()
    usage = response_json.get('usage', {})

    # Map the usage fields
    session_usage = {
        'input': usage.get('prompt_tokens', 0),
        'output': usage.get('completion_tokens', 0),
        'totalTokens': usage.get('total_tokens', 0)
    }

    # Update the session log usage object
    session_log['usage'] = session_usage

    # ... (existing code)

Verification

To verify the fix, test the gateway with a local model request and check the session JSONL logs for correct usage data.

Extra Tips

  • Ensure the gateway handles cases where the local model response may not include all usage fields to avoid errors.
  • Consider adding logging or monitoring to track any issues with usage data mapping or parsing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING