SageOx Admin API
Administrative analytics, session management, and system operations. Includes active session counts, user analytics, and management endpoints restricted to admin roles.
Administrative analytics, session management, and system operations. Includes active session counts, user analytics, and management endpoints restricted to admin roles.
openapi: 3.1.0
info:
title: SageOx Admin API
version: 1.0.0
description: "# API Reference\n\n## Overview\n\nSageOx is a platform that captures team knowledge from discussions, decisions, and work context into a Ledger (per-repo historical record) and Team Context (team-wide shared knowledge). The SageOx API provides programmatic access to manage repositories, recordings, notifications, and team data with high performance and reliability.\n\n## Base URLs\n\n| Environment | URL |\n|---|---|\n| Local Development | `http://localhost:3000` |\n| Test | `https://test.sageox.ai` |\n| Production | `https://sageox.ai` |\n\n## Authentication\n\nAll requests to the SageOx API require authentication via JWT tokens issued by the Better Auth service.\n\nInclude your token in the `Authorization` header:\n```\nAuthorization: Bearer <token>\n```\n\n**Initial Auth Flow (CLI)**\n- CLI initiates device flow to obtain initial credentials\n- Exchange device code for JWT token\n- Store token securely for subsequent API requests\n- Refresh token when expired\n\n**Authenticated Endpoints**\n- Pass JWT in `Authorization: Bearer <token>` header\n- Tokens contain user identity and team membership\n- Invalid or expired tokens return 401 Unauthorized\n\n## Response Format\n\n### Success\nStandard response format with optional pagination metadata:\n```json\n{\n \"success\": true,\n \"data\": { ... }\n}\n```\n\n### Error\nAll errors follow a consistent format:\n```json\n{\n \"success\": false,\n \"error\": \"Human-readable error description\"\n}\n```\n\n**Status Codes**\n- `400` — Bad Request: Invalid parameters or malformed request\n- `401` — Unauthorized: Missing or invalid authentication token\n- `403` — Forbidden: Insufficient permissions for this resource\n- `404` — Not Found: Resource does not exist\n- `409` — Conflict: Request conflicts with current state (e.g., duplicate)\n- `429` — Rate Limited: Too many requests; retry with backoff\n- `500` — Internal Error: Server error; contact support if persistent\n\n## Pagination\n\nList endpoints support cursor-based pagination via query parameters:\n\n**Query Parameters**\n- `limit` — Number of results per page (default: 20, max: 100)\n- `offset` — Number of results to skip (default: 0)\n\n**Response Metadata**\nList responses include pagination info:\n```json\n{\n \"success\": true,\n \"data\": [ ... ],\n \"meta\": {\n \"total\": 150,\n \"limit\": 20,\n \"offset\": 0,\n \"hasMore\": true\n }\n}\n```\n\n## ID Formats\n\nResources use standardized ID formats for easy identification:\n\n| Resource | Format | Length | Example |\n|---|---|---|---|\n| Team | `team_<cuid2>` | 10 chars | `team_abc1234567` |\n| User | `usr_<cuid2>` | 10 chars | `usr_xyz9876543` |\n| Repository | `repo_<uuidv7>` | 36 chars | `repo_01934f5a-8b9c-7def-abcd-0123456789ab` |\n| Recording | `rec_<uuidv7>` | 36 chars | `rec_01934f5a-8b9c-7def-abcd-0123456789ab` |\n| Image | `img_<uuidv7>` | 36 chars | `img_01934f5a-8b9c-7def-abcd-0123456789ab` |\n| Notification | `notif_<cuid2>` | 14 chars | `notif_ab1cd2ef3g` |\n\nUse these IDs for all API operations. IDs are unique across environments.\n\n## Rate Limiting\n\nThe API applies rate limiting to protect against abuse and ensure fair access:\n\n**Authenticated Endpoints**\n- Limited per user: depends on subscription tier\n- Quota resets hourly\n\n**Unauthenticated Endpoints**\n- Limited per IP address\n- More restrictive than authenticated limits\n\nWhen rate limited, the API returns `429 Too Many Requests`. Retry requests with exponential backoff:\n```\nwait = min(2^attempt * 100ms, 10s)\n```\n\n## Timestamps\n\nAll timestamps in API responses use RFC 3339 / ISO 8601 format in UTC:\n```\n2025-12-03T10:30:00Z\n```\n\nUse this format when providing timestamps in requests as well. The API rejects timestamps in other formats.\n\n## SDKs & Tools\n\n- **OpenAPI Spec** — Full schema available at `/api/openapi.json`\n- **Postman Collection** — Import from `/api/postman.json` for interactive exploration\n- **CLI** — Use `ox` CLI for command-line access\n"
contact:
name: SageOx Team
license:
name: MIT
servers:
- url: http://localhost:3000
description: Devcontainer
- url: https://test.sageox.ai
description: Test
- url: https://sageox.ai
description: Production
security:
- bearerAuth: []
tags:
- name: Admin
description: 'Administrative analytics, session management, and system operations. Includes active session counts, user analytics, and management endpoints restricted to admin roles.
'
paths:
/api/v1/admin/sessions/top:
get:
tags:
- Admin
summary: Get top sessions by token usage
description: 'Returns the top 5 sessions ranked by total token consumption
in the last 7 days. Sessions are grouped by ox_sid and include
agent/model metadata.
'
operationId: getTopSessions
security:
- bearerAuth: []
responses:
'200':
description: Top sessions retrieved successfully
content:
application/json:
schema:
type: object
properties:
sessions:
type: array
items:
type: object
properties:
ox_sid:
type: string
description: Session identifier
example: oxsid_abc123xyz
total_tokens:
type: integer
format: int64
description: Total tokens consumed
example: 12450
path_count:
type: integer
format: int64
description: Number of path accesses
example: 23
duration_seconds:
type: integer
description: Session duration in seconds
example: 272
agent:
type: string
nullable: true
description: Coding agent platform
example: claude-code
model:
type: string
nullable: true
description: AI model used
example: claude-opus-4-5
first_access:
type: string
format: date-time
description: First access timestamp
last_access:
type: string
format: date-time
description: Last access timestamp
required:
- ox_sid
- total_tokens
- path_count
- duration_seconds
- first_access
- last_access
'401':
description: Authentication required
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: string
message:
type: string
'403':
description: Admin access required
content:
application/json:
schema:
$ref: '#/paths/~1api~1v1~1admin~1sessions~1top/get/responses/401/content/application~1json/schema'
/api/v1/admin/sessions/{sid}:
get:
tags:
- Admin
summary: Get session details
description: 'Returns detailed analytics for a specific session including
timeline of accesses, path exploration tree, and metadata.
'
operationId: getSessionDetail
security:
- bearerAuth: []
parameters:
- name: sid
in: path
required: true
schema:
type: string
description: Session ID (ox_sid)
example: oxsid_abc123xyz
responses:
'200':
description: Session details retrieved successfully
content:
application/json:
schema:
type: object
properties:
ox_sid:
type: string
user_id:
type: string
nullable: true
total_tokens:
type: integer
format: int64
path_count:
type: integer
format: int64
unique_paths:
type: integer
format: int64
duration_seconds:
type: integer
agent:
type: string
nullable: true
model:
type: string
nullable: true
first_access:
type: string
format: date-time
last_access:
type: string
format: date-time
timeline:
type: array
items:
type: object
properties:
path:
type: string
example: infra/aws/lambda
tokens:
type: integer
example: 450
timestamp:
type: string
format: date-time
metadata:
type: object
additionalProperties: true
nullable: true
path_tree:
type: array
items:
type: object
properties:
path:
type: string
segment:
type: string
tokens:
type: integer
access_count:
type: integer
children:
type: array
items:
$ref: '#/paths/~1api~1v1~1admin~1sessions~1%7Bsid%7D/get/responses/200/content/application~1json/schema/properties/path_tree/items'
'404':
description: Session not found
content:
application/json:
schema:
$ref: '#/paths/~1api~1v1~1admin~1sessions~1top/get/responses/401/content/application~1json/schema'
/api/v1/admin/paths/top:
get:
tags:
- Admin
summary: Get top paths by TF-IDF score
description: 'Returns the top 10 guidance paths weighted by TF-IDF score.
This highlights paths that are unexpectedly popular relative
to their baseline expectation (deeper paths get a bonus).
'
operationId: getTopPaths
security:
- bearerAuth: []
responses:
'200':
description: Top paths retrieved successfully
content:
application/json:
schema:
type: object
properties:
paths:
type: array
items:
type: object
properties:
path:
type: string
example: infra/aws/lambda/edge-functions
access_count:
type: integer
format: int64
example: 42
unique_sessions:
type: integer
format: int64
example: 15
total_tokens:
type: integer
format: int64
example: 8500
tfidf_score:
type: number
format: float
description: TF-IDF weighted score
example: 12.45
/api/v1/admin/agents/top:
get:
tags:
- Admin
summary: Get top agents by usage
description: 'Returns top coding agents (claude-code, cursor, windsurf, etc.)
ranked by total token usage in the last 7 days.
'
operationId: getTopAgents
security:
- bearerAuth: []
responses:
'200':
description: Top agents retrieved successfully
content:
application/json:
schema:
type: object
properties:
agents:
type: array
items:
type: object
properties:
agent:
type: string
example: claude-code
session_count:
type: integer
format: int64
example: 150
request_count:
type: integer
format: int64
example: 3200
total_tokens:
type: integer
format: int64
example: 450000
avg_tokens_per_request:
type: integer
example: 140
/api/v1/admin/models/top:
get:
tags:
- Admin
summary: Get top models by usage
description: 'Returns top AI models (claude-opus-4-5, gpt-4o, etc.)
ranked by total token usage in the last 7 days.
'
operationId: getTopModels
security:
- bearerAuth: []
responses:
'200':
description: Top models retrieved successfully
content:
application/json:
schema:
type: object
properties:
models:
type: array
items:
type: object
properties:
model:
type: string
example: claude-opus-4-5
session_count:
type: integer
format: int64
example: 120
request_count:
type: integer
format: int64
example: 2800
total_tokens:
type: integer
format: int64
example: 380000
avg_tokens_per_request:
type: integer
example: 135
/api/v1/admin/versions/top:
get:
tags:
- Admin
summary: Get top ox-cli versions by usage
description: 'Returns top ox-cli versions ranked by total token usage
in the last 7 days. Version is parsed from User-Agent header.
'
operationId: getTopCliVersions
security:
- bearerAuth: []
responses:
'200':
description: Top CLI versions retrieved successfully
content:
application/json:
schema:
type: object
properties:
versions:
type: array
items:
type: object
properties:
client_version:
type: string
description: ox-cli version from User-Agent header
example: 1.2.3
session_count:
type: integer
format: int64
example: 85
request_count:
type: integer
format: int64
example: 1900
total_tokens:
type: integer
format: int64
example: 280000
avg_tokens_per_request:
type: integer
example: 147
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: 'JWT token obtained from the auth service (/api/auth/token).
Token is validated using JWKS from the auth service.
Required claims: sub (user_id), email, name, tier.
'