Skip to content

GraphQL API

Claw Insights exposes a GraphQL API for querying gateway data and subscribing to real-time changes.

Endpoint

  • URL: POST /graphql
  • Auth: Bearer token (Authorization: Bearer <token>) or session cookie

Query Structure

All queries go through a source resolver with a selector:

graphql
query {
  source(selector: { category: AGENT, provider: OPENCLAW }) {
    ... on AgentNamespace {
      sessions { key model totalTokens turnCount status }
    }
  }
}

Available Fields

NamespaceFieldDescription
AgentNamespacesessionsList sessions with token usage, model, status
AgentNamespacesession(key)Single session by key
AgentNamespacemetrics(range)Aggregated metrics over a time range
AgentNamespaceevents(limit, types)Structured event log with filtering
AgentNamespacelifetimeStatsAll-time totals: days, sessions, tokens, messages
AgentNamespacesessionTranscript(sessionKey)Full conversation transcript
AgentNamespacecronJobsScheduled job definitions
AgentNamespaceusageCostToken cost breakdown
AgentNamespacerecentLogs(count)Latest structured log entries

Subscriptions

SubscriptionTransportDescription
dataChangedSSEFires when any data source updates
logsSSEStreams structured log entries in real time

Examples

List sessions:

bash
curl -X POST http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ source(selector: { category: AGENT, provider: OPENCLAW }) { ... on AgentNamespace { sessions { key model totalTokens turnCount status } } } }"}'

Metrics (last 24h):

bash
curl -X POST http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ source(selector: { category: AGENT, provider: OPENCLAW }) { ... on AgentNamespace { metrics(range: TWENTY_FOUR_HOUR) { totalTokensK totalErrors totalTurns uptimePercent } } } }"}'

Lifetime stats:

bash
curl -X POST http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ source(selector: { category: AGENT, provider: OPENCLAW }) { ... on AgentNamespace { lifetimeStats { companionDays totalSessions totalTokens totalMessages } } } }"}'

Subscribe to changes (SSE):

bash
curl -N http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "subscription { dataChanged { source ts } }"}'

Schema

Full GraphQL schema is available on GitHub.

Released under the MIT License.