SageOx LLM API
OpenAI-compatible chat completion endpoints. Proxies requests to configured LLM providers (Bedrock, OpenAI) with model routing, token usage tracking, and streaming support. Follows the OpenAI `/v1/chat/completions` format.
OpenAI-compatible chat completion endpoints. Proxies requests to configured LLM providers (Bedrock, OpenAI) with model routing, token usage tracking, and streaming support. Follows the OpenAI `/v1/chat/completions` format.
openapi: 3.1.0
info:
title: SageOx Admin LLM 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: LLM
description: 'OpenAI-compatible chat completion endpoints. Proxies requests to configured LLM providers (Bedrock, OpenAI) with model routing, token usage tracking, and streaming support. Follows the OpenAI `/v1/chat/completions` format.
'
paths:
/v1/models:
get:
operationId: listModels
summary: List available models
description: List all available LLM models that can be used for chat completions
tags:
- LLM
security:
- bearerAuth: []
responses:
'200':
description: List of available models
content:
application/json:
schema:
type: object
required:
- object
- data
properties:
object:
type: string
enum:
- list
example: list
data:
type: array
items:
type: object
required:
- id
- object
- created
- owned_by
properties:
id:
type: string
description: Model identifier
example: gpt-4
object:
type: string
enum:
- model
example: model
created:
type: integer
description: Unix timestamp of when the model was created
example: 1677610602
owned_by:
type: string
description: Organization that owns the model
example: sageox
'401':
description: Unauthorized - Invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
/v1/chat/completions:
post:
operationId: createChatCompletion
summary: Create chat completion
description: 'Create a chat completion using OpenAI-compatible API format.
Supports both streaming and non-streaming responses.
For streaming responses, set `stream: true` in the request body.
The response will be a text/event-stream with Server-Sent Events (SSE).
'
tags:
- LLM
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- model
- messages
properties:
model:
type: string
description: ID of the model to use
example: gpt-4
messages:
type: array
description: List of messages in the conversation
minItems: 1
items:
type: object
required:
- role
- content
properties:
role:
type: string
enum:
- system
- user
- assistant
description: Role of the message author
example: user
content:
type: string
description: Content of the message
example: Hello, how are you?
stream:
type: boolean
description: Whether to stream the response using SSE
default: false
example: false
temperature:
type: number
description: Sampling temperature between 0 and 2
minimum: 0
maximum: 2
default: 1
example: 0.7
max_tokens:
type: integer
description: Maximum number of tokens to generate
minimum: 1
example: 1000
top_p:
type: number
description: Nucleus sampling parameter
minimum: 0
maximum: 1
example: 1
frequency_penalty:
type: number
description: Frequency penalty between -2.0 and 2.0
minimum: -2
maximum: 2
default: 0
example: 0
presence_penalty:
type: number
description: Presence penalty between -2.0 and 2.0
minimum: -2
maximum: 2
default: 0
example: 0
stop:
oneOf:
- type: string
- type: array
items:
type: string
description: Up to 4 sequences where the API will stop generating
example:
- \n
n:
type: integer
description: Number of completions to generate
minimum: 1
maximum: 10
default: 1
example: 1
user:
type: string
description: Unique identifier for the end-user
example: user-12345
responses:
'200':
description: Chat completion response
content:
application/json:
schema:
type: object
required:
- id
- object
- created
- model
- choices
- usage
properties:
id:
type: string
description: Unique identifier for the completion
example: chatcmpl-abc123
object:
type: string
enum:
- chat.completion
example: chat.completion
created:
type: integer
description: Unix timestamp of when the completion was created
example: 1677858242
model:
type: string
description: Model used for the completion
example: gpt-4
choices:
type: array
description: List of completion choices
items:
type: object
required:
- index
- message
- finish_reason
properties:
index:
type: integer
description: Index of the choice
example: 0
message:
type: object
required:
- role
- content
properties:
role:
type: string
enum:
- assistant
example: assistant
content:
type: string
description: Generated message content
example: Hello! I'm doing well, thank you for asking.
finish_reason:
type: string
enum:
- stop
- length
- content_filter
- null
description: Reason why the completion finished
example: stop
usage:
type: object
required:
- prompt_tokens
- completion_tokens
- total_tokens
properties:
prompt_tokens:
type: integer
description: Number of tokens in the prompt
example: 10
completion_tokens:
type: integer
description: Number of tokens in the completion
example: 12
total_tokens:
type: integer
description: Total number of tokens used
example: 22
text/event-stream:
schema:
type: string
description: 'Server-Sent Events stream (when stream=true).
Each event is a JSON object representing a chunk of the completion.
Format:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1677858242,"model":"gpt-4","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}
The stream ends with:
data: [DONE]
'
example: 'data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1677858242,"model":"gpt-4","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1677858242,"model":"gpt-4","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1677858242,"model":"gpt-4","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1677858242,"model":"gpt-4","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
'
'400':
description: Bad request - Invalid parameters
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
example:
error:
message: Invalid request body
type: invalid_request_error
code: invalid_request
'401':
description: Unauthorized - Invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
example:
error:
message: Invalid authentication
type: invalid_request_error
code: invalid_api_key
'429':
description: Rate limit exceeded
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
example:
error:
message: Rate limit exceeded
type: rate_limit_error
code: rate_limit_exceeded
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/OpenAIError'
example:
error:
message: Internal server error
type: server_error
code: server_error
components:
schemas:
OpenAIError:
type: object
description: Error response following the OpenAI error format. Returned by LLM endpoints.
required:
- error
properties:
error:
type: object
description: Error details object.
required:
- message
- type
properties:
message:
type: string
description: Human-readable error description.
example: Invalid API key
type:
type: string
description: 'Error category. Common values: `invalid_request_error`, `authentication_error`, `rate_limit_error`.'
example: invalid_request_error
code:
type: string
nullable: true
description: Machine-readable error code for programmatic handling. `null` when no specific code applies.
example: invalid_api_key
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.
'