openclaw - 💡(How to fix) Fix [Feature]: HTTP API endpoint for real-time session statistics [1 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#69742Fetched 2026-04-22 07:48:50
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add a REST API endpoint /api/sessions to the OpenClaw gateway for real-time access to session statistics (context tokens, costs, models, etc.) for external dashboards and monitoring tools.

Root Cause

Add a REST API endpoint /api/sessions to the OpenClaw gateway for real-time access to session statistics (context tokens, costs, models, etc.) for external dashboards and monitoring tools.

Code Example

GET /api/sessions

---

{
  "sessions": [
    {
      "key": "agent:main:main",
      "model": "anthropic/claude-sonnet-4-6",
      "contextTokens": 94000,
      "contextPct": 47,
      "totalCost": 0.15,
      "updatedAt": "2026-04-21T14:27:00Z"
    }
  ]
}
RAW_BUFFERClick to expand / collapse

Summary

Add a REST API endpoint /api/sessions to the OpenClaw gateway for real-time access to session statistics (context tokens, costs, models, etc.) for external dashboards and monitoring tools.

Problem to solve

Currently, external tools need to parse JSONL session files to get statistics, which:

  • Becomes expensive with large session histories
  • Shows inaccurate data after compactions (JSONL has historical tokens, not current context)
  • Requires file system access instead of HTTP requests
  • Doesn't scale well for multiple monitoring tools

Proposed solution

Add HTTP endpoint to gateway:

GET /api/sessions

Expected response:

{
  "sessions": [
    {
      "key": "agent:main:main",
      "model": "anthropic/claude-sonnet-4-6",
      "contextTokens": 94000,
      "contextPct": 47,
      "totalCost": 0.15,
      "updatedAt": "2026-04-21T14:27:00Z"
    }
  ]
}

Benefits

  • Live data access without file parsing
  • Accurate post-compaction context sizes
  • Better performance for dashboard auto-refresh
  • Enables external monitoring integrations
  • Browser-compatible (with CORS)

Use case

Building external monitoring tools that need real-time session statistics instead of parsing potentially large JSONL files.

Implementation notes

  • Could reuse existing session manager APIs
  • Needs CORS headers for browser dashboards
  • Optional: Authentication for production deployments

Happy to contribute a PR if this aligns with the roadmap! 🚀

extent analysis

TL;DR

Implementing the proposed /api/sessions endpoint with proper CORS headers and optional authentication will provide real-time access to session statistics for external dashboards and monitoring tools.

Guidance

  • Review the existing session manager APIs to determine if they can be reused for the new endpoint, reducing development effort and ensuring consistency.
  • Implement CORS headers to enable browser-compatible access, allowing for a wider range of monitoring tools and dashboards to utilize the endpoint.
  • Consider adding authentication mechanisms for production deployments to ensure secure access to session statistics.
  • Test the endpoint with various monitoring tools and dashboards to verify its functionality and performance.

Example

No code snippet is provided as the issue does not contain sufficient technical details for a specific implementation example.

Notes

The proposed solution assumes that the existing session manager APIs can provide the necessary data for the new endpoint. If this is not the case, additional development may be required to gather the necessary session statistics.

Recommendation

Apply the proposed workaround by implementing the /api/sessions endpoint, as it addresses the current limitations of parsing JSONL session files and provides a scalable solution for real-time access to session statistics.

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

openclaw - 💡(How to fix) Fix [Feature]: HTTP API endpoint for real-time session statistics [1 participants]