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

Root Queries

The schema provides three root queries:

QueryDescription
systemSystem-level state: gateway status, resources, channels, health
sources(filter)List registered data sources with status and attributes
source(selector)Resolve a single data source namespace for detailed queries

system

Returns an OpenClawSystem namespace with gateway process status, resource usage, channel connectivity, and health checks.

graphql
query {
  system {
    ... on OpenClawSystem {
      gateway { running version appVersion uptime pid updateAvailable }
      resources { cpu memoryMB diskMB sampledAt }
      channels { provider name connected latencyMs }
      health { status checks { name status message } }
    }
  }
}

sources(filter)

List all registered data sources, optionally filtered by category, provider, status, or tags.

graphql
query {
  sources(filter: { category: AGENT }) {
    id name status
    attributes { category provider tags }
  }
}

SourceFilter input fields: category (AGENT | DASHBOARD), provider (OPENCLAW | CLAUDE_CODE | CODEX), status (INITIALIZING | CONNECTED | DISCONNECTED | ERROR), tags ([String!]).

source(selector)

Resolve a single source namespace by selector. Returns a SourceNamespace union (AgentNamespace | DashboardNamespace).

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

SourceSelector input fields: id, category, provider, tags.

All three root queries accept an optional context: QueryContext input for request tracing, display preferences, and default filters.

AgentNamespace Fields

FieldArgumentsDescription
sessions(filter)activeOnly, grouped, sortByList sessions with token usage, model, status
session(key)key: String!Single session by key
metrics(date, range)date: String, range: MetricsRangeAggregated metrics over a time range
events(from, to, types, limit)from/to: Int, types: [String!], limit: IntStructured event log with filtering
eventDensityHourly event density buckets with error/warning/restart flags
eventCounts(from, to)from/to: IntAggregate counts of errors, warnings, restarts
lifetimeStatsAll-time totals: days, sessions, tokens, messages
sessionTranscript(sessionKey, limit, before, after)sessionKey: String!, limit: Int, before/after: StringPaginated session transcript with cursor-based navigation
cronJobsScheduled job definitions
usageCostToken cost breakdown
recentLogs(count)count: IntLatest structured log entries

lifetimeStats Subfields

FieldTypeDescription
isReadyBoolean!Whether initial transcript scan has completed
createdAtString!ISO timestamp of earliest known activity
daysSinceCreationInt!Days since creation
totalSessionsInt!Count of transcript files on disk
totalInputTokensFloat!Cumulative input tokens
totalOutputTokensFloat!Cumulative output tokens
totalCacheReadTokensFloat!Cumulative cache read tokens
totalCacheWriteTokensFloat!Cumulative cache write tokens
totalTokensFloat!Sum of all token categories
totalUserMessagesInt!Total user messages across all sessions
totalAssistantMessagesInt!Total assistant messages across all sessions

Token fields use Float to avoid GraphQL Int32 overflow for large cumulative values.

sessionTranscript Return Type

FieldTypeDescription
sessionKeyString!Session key
displayNameString!Session display name
modelString!Model at session start
channelStringChannel provider
kindString!Session kind: direct / group / cron
thinkingLevelStringThinking level at session start
startedAtString!ISO timestamp
fileSizeInt!Transcript file size in bytes
totalTokensInt!Total tokens consumed
contextTokensInt!Approximate context window usage
durationMsInt!Session duration in milliseconds
isSubAgentBoolean!Whether this is a sub-agent session
parentDisplayNameStringParent session name (sub-agent only)
spawnPromptStringFirst user message (sub-agent spawn prompt)
messages[TranscriptMessage!]!Structured messages
totalMessagesInt!Total message count in file
pageInfoPageInfo!Cursor pagination info

Use limit, before, and after arguments for cursor-based pagination through messages.

Key Types

DataSource

graphql
type DataSource {
  id: String!
  name: String!
  status: SourceStatus!          # INITIALIZING | CONNECTED | DISCONNECTED | ERROR
  attributes: SourceAttributes!  # category, provider, tags
}

HealthStatus / HealthCheck

graphql
type HealthStatus {
  status: HealthLevel!    # HEALTHY | DEGRADED | UNHEALTHY
  checks: [HealthCheck!]!
}

type HealthCheck {
  name: String!
  status: CheckStatus!    # PASS | WARN | FAIL
  message: String
}

EventDensityBucket

graphql
type EventDensityBucket {
  hour: Int!
  count: Int!
  hasError: Boolean!
  hasWarning: Boolean!
  hasRestart: Boolean!
  errorCount: Int!
  warningCount: Int!
  restartCount: Int!
  epochStart: Int!
}

EventCounts

graphql
type EventCounts {
  error: Int!
  warning: Int!
  restart: Int!
}

Subscriptions

SubscriptionTransportDescription
dataChangedSSEFires when any data source updates (lightweight signal — client should refetch)
logs(filter)SSEStreams structured log entries in real time (level, module filters)

Examples

System status:

bash
curl -X POST http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ system { ... on OpenClawSystem { gateway { running version uptime } resources { cpu memoryMB } health { status checks { name status } } } } }"}'

List data sources:

bash
curl -X POST http://127.0.0.1:41041/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ sources { id name status attributes { category provider } } }"}'

Agent sessions and metrics:

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(range: TWENTY_FOUR_HOUR) { totalTokensK totalErrors 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 { isReady daysSinceCreation totalSessions totalTokens totalUserMessages totalAssistantMessages } } } }"}'

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.