SageOx Notifications API

Read, manage, and stream real-time notifications. Supports SSE (Server-Sent Events) for live delivery, bulk operations (mark read, delete), and preference-based filtering. Notifications originate from workflows, recordings, and system events.

OpenAPI Specification

sageox-notifications-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: SageOx Admin Notifications 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: Notifications
  description: 'Read, manage, and stream real-time notifications. Supports SSE (Server-Sent Events) for live delivery, bulk operations (mark read, delete), and preference-based filtering. Notifications originate from workflows, recordings, and system events.

    '
paths:
  /api/v1/notifications:
    get:
      summary: List notifications
      description: Retrieves paginated list of notifications for the authenticated user
      operationId: getNotifications
      tags:
      - Notifications
      security:
      - bearerAuth: []
      parameters:
      - name: limit
        in: query
        description: Maximum number of notifications to return
        required: false
        schema:
          type: integer
          minimum: 1
          maximum: 100
          default: 50
          example: 20
      - name: offset
        in: query
        description: Number of notifications to skip for pagination
        required: false
        schema:
          type: integer
          minimum: 0
          default: 0
          example: 0
      responses:
        '200':
          description: Notifications retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - notifications
                - pagination
                properties:
                  notifications:
                    type: array
                    items:
                      $ref: '#/components/schemas/NotificationDTO'
                  pagination:
                    $ref: '#/components/schemas/PaginationMeta'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
    post:
      summary: Create notification
      description: Creates a new notification for the authenticated user
      operationId: createNotification
      tags:
      - Notifications
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - agentId
              - type
              - priority
              - title
              - message
              properties:
                agentId:
                  type: string
                  description: ID of the agent creating the notification
                  example: agent_5k6l7m8n9o0p1q2r
                type:
                  type: string
                  description: Notification type
                  example: info
                priority:
                  type: string
                  description: Notification priority level
                  enum:
                  - low
                  - medium
                  - high
                  - urgent
                  example: medium
                title:
                  type: string
                  description: Notification title
                  example: Task completed
                message:
                  type: string
                  description: Notification message body
                  example: Your task has been successfully completed
                metadata:
                  type: object
                  nullable: true
                  additionalProperties: true
                  description: Optional metadata associated with the notification
      responses:
        '200':
          description: Notification created successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - notification
                properties:
                  notification:
                    $ref: '#/components/schemas/NotificationDTO'
        '400':
          description: Bad request - invalid input parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/{id}:
    delete:
      summary: Delete notification
      description: Deletes a specific notification for the authenticated user
      operationId: deleteNotification
      tags:
      - Notifications
      security:
      - bearerAuth: []
      parameters:
      - name: id
        in: path
        description: Notification ID
        required: true
        schema:
          type: string
          example: notif_9h8g7f6e5d4c3b2a
      responses:
        '200':
          description: Notification deleted successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - deleted
                properties:
                  deleted:
                    type: boolean
                    description: Indicates successful deletion
                    example: true
        '400':
          description: Bad request - missing or invalid notification ID
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Notification not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/{id}/read:
    put:
      summary: Mark notification as read or unread
      description: Updates the read status of a specific notification
      operationId: updateNotificationRead
      tags:
      - Notifications
      security:
      - bearerAuth: []
      parameters:
      - name: id
        in: path
        description: Notification ID
        required: true
        schema:
          type: string
          example: notif_9h8g7f6e5d4c3b2a
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - read
              properties:
                read:
                  type: boolean
                  description: Read status to set
                  example: true
      responses:
        '200':
          description: Notification read status updated successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - updated
                properties:
                  updated:
                    type: boolean
                    description: Indicates successful update
                    example: true
        '400':
          description: Bad request - missing or invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Notification not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/stream:
    get:
      summary: Server-Sent Events stream for real-time notifications
      description: Establishes a persistent SSE connection to receive real-time notification updates
      operationId: streamNotifications
      tags:
      - Notifications
      security:
      - bearerAuth: []
      responses:
        '200':
          description: SSE stream established successfully
          content:
            text/event-stream:
              schema:
                type: string
                description: Server-Sent Events stream with JSON-encoded notification data
                example: 'data: {"type":"connected","message":"Connected to notification stream"}


                  data: {"id":"notif_9h8g7f6e5d4c3b2a","userId":"user_2n3k4m5l6j7h8g9f","agentId":"agent_5k6l7m8n9o0p1q2r","type":"info","priority":"medium","title":"Task completed","message":"Your task has been successfully completed","read":false,"timestamp":"2025-12-03T10:30:00Z"}


                  :keepalive

                  '
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error - streaming not supported or connection failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/stats:
    get:
      summary: Get notification statistics
      description: Returns aggregated statistics about user notifications including totals, unread counts, and breakdowns by type and priority
      operationId: getNotificationStats
      tags:
      - Notifications
      security:
      - bearerAuth: []
      responses:
        '200':
          description: Notification statistics retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - total
                - unread
                properties:
                  total:
                    type: integer
                    description: Total number of notifications
                    example: 15
                  unread:
                    type: integer
                    description: Number of unread notifications
                    example: 3
                  byType:
                    type: object
                    description: Notification counts grouped by type
                    additionalProperties:
                      type: integer
                    example:
                      info: 8
                      warning: 5
                      error: 2
                  byPriority:
                    type: object
                    description: Notification counts grouped by priority level
                    additionalProperties:
                      type: integer
                    example:
                      low: 5
                      medium: 7
                      high: 2
                      urgent: 1
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/read-all:
    post:
      summary: Mark all notifications as read
      description: Marks all notifications for the authenticated user as read in a single operation
      operationId: markAllNotificationsRead
      tags:
      - Notifications
      security:
      - bearerAuth: []
      responses:
        '200':
          description: All notifications marked as read successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - updated
                properties:
                  updated:
                    type: boolean
                    description: Indicates successful operation
                    example: true
                  count:
                    type: integer
                    description: Number of notifications marked as read
                    example: 5
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/grouped:
    get:
      summary: Get grouped notifications
      description: Retrieves notifications grouped by type and source for compact display
      operationId: getGroupedNotifications
      tags:
      - Notifications
      security:
      - bearerAuth: []
      parameters:
      - name: limit
        in: query
        description: Maximum number of notification groups to return
        required: false
        schema:
          type: integer
          minimum: 1
          maximum: 100
          default: 20
          example: 20
      - name: offset
        in: query
        description: Number of notification groups to skip for pagination
        required: false
        schema:
          type: integer
          minimum: 0
          default: 0
          example: 0
      - name: lookback_hours
        in: query
        description: Number of hours to look back for notifications (default 168 for 7 days)
        required: false
        schema:
          type: integer
          minimum: 1
          default: 168
          example: 72
      responses:
        '200':
          description: Grouped notifications retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - pagination
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      required:
                      - type
                      - count
                      properties:
                        type:
                          type: string
                          description: Notification type
                          example: task_completed
                        sourceType:
                          type: string
                          description: Source type for the notification group
                          example: agent
                        sourceId:
                          type: string
                          description: Source ID
                          example: agent_5k6l7m8n9o0p1q2r
                        count:
                          type: integer
                          description: Number of notifications in this group
                          example: 3
                        lastNotification:
                          type: string
                          description: Most recent notification timestamp in the group
                          format: date-time
                          example: '2025-12-03T10:30:00Z'
                  pagination:
                    $ref: '#/components/schemas/PaginationMeta'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/group-items:
    get:
      summary: Get notification group items
      description: Retrieves all individual notifications for a specific notification group (used for expanding/drilling into a group)
      operationId: getNotificationGroupItems
      tags:
      - Notifications
      security:
      - bearerAuth: []
      parameters:
      - name: type
        in: query
        description: Notification type to fetch items for
        required: true
        schema:
          type: string
          example: task_completed
      - name: source_type
        in: query
        description: Optional source type filter
        required: false
        schema:
          type: string
          example: agent
      - name: source_id
        in: query
        description: Optional source ID filter
        required: false
        schema:
          type: string
          example: agent_5k6l7m8n9o0p1q2r
      - name: limit
        in: query
        description: Maximum number of items to return
        required: false
        schema:
          type: integer
          minimum: 1
          maximum: 200
          default: 50
          example: 50
      - name: offset
        in: query
        description: Number of items to skip for pagination
        required: false
        schema:
          type: integer
          minimum: 0
          default: 0
          example: 0
      responses:
        '200':
          description: Notification group items retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - items
                - count
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/NotificationDTO'
                    description: Array of notifications in the group
                  count:
                    type: integer
                    description: Total number of items in the group
                    example: 5
        '400':
          description: Bad request - missing required type parameter
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/bulk:
    delete:
      summary: Bulk delete notifications
      description: Deletes multiple notifications identified by their IDs in a single operation
      operationId: bulkDeleteNotifications
      tags:
      - Notifications
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - notificationIds
              properties:
                notificationIds:
                  type: array
                  description: Array of notification IDs to delete
                  items:
                    type: string
                    example: notif_9h8g7f6e5d4c3b2a
                  minItems: 1
                  example:
                  - notif_9h8g7f6e5d4c3b2a
                  - notif_8g7f6e5d4c3b2a1z
                  - notif_7f6e5d4c3b2a1z0y
      responses:
        '200':
          description: Notifications deleted successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - deleted
                properties:
                  deleted:
                    type: integer
                    description: Number of notifications deleted
                    example: 3
        '400':
          description: Bad request - invalid or empty notificationIds array
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/preferences:
    get:
      summary: Get notification preferences
      description: Retrieves comprehensive notification preferences for the authenticated user including per-channel and per-type settings
      operationId: getNotificationPreferences
      tags:
      - Notifications
      security:
      - bearerAuth: []
      responses:
        '200':
          description: Notification preferences retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - version
                - channels
                - types
                properties:
                  version:
                    type: integer
                    description: Preference schema version
                    example: 1
                  channels:
                    type: object
                    description: Master channel preferences
                    required:
                    - email
                    - push
                    - inApp
                    properties:
                      email:
                        type: boolean
                        description: Email notifications enabled
                        example: true
                      push:
                        type: boolean
                        description: Push notifications enabled
                        example: true
                      inApp:
                        type: boolean
                        description: In-app notifications enabled
                        example: true
                  types:
                    type: object
                    description: Per-type notification preferences
                    additionalProperties:
                      type: object
                      required:
                      - key
                      - label
                      - preferences
                      properties:
                        key:
                          type: string
                          description: Notification type key
                          example: task_completed
                        label:
                          type: string
                          description: Human-readable label
                          example: Task Completed
                        description:
                          type: string
                          description: Description of the notification type
                          example: Notifications when tasks are completed
                        category:
                          type: string
                          description: Category this type belongs to
                          example: tasks
                        preferences:
                          type: object
                          description: Channel preferences for this type
                          properties:
                            email:
                              type: boolean
                            push:
                              type: boolean
                            inApp:
                              type: boolean
                        alwaysOn:
                          type: boolean
                          description: Whether this notification type cannot be disabled
                          example: false
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
    put:
      summary: Update notification preferences
      description: Updates notification preferences for channels and/or specific notification types
      operationId: updateNotificationPreferences
      tags:
      - Notifications
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                channels:
                  type: object
                  description: Master channel preferences to update
                  properties:
                    email:
                      type: boolean
                      description: Enable/disable email notifications
                    push:
                      type: boolean
                      description: Enable/disable push notifications
                    inApp:
                      type: boolean
                      description: Enable/disable in-app notifications
                types:
                  type: object
                  description: Per-type preferences to update
                  additionalProperties:
                    type: object
                    properties:
                      email:
                        type: boolean
                      push:
                        type: boolean
                      inApp:
                        type: boolean
              example:
                channels:
                  email: true
                  push: false
                  inApp: true
                types:
                  task_completed:
                    email: true
                    push: false
      responses:
        '200':
          description: Notification preferences updated successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - version
                - channels
                - types
                properties:
                  version:
                    type: integer
                    description: Preference schema version
                    example: 1
                  channels:
                    type: object
                    properties:
                      email:
                        type: boolean
                      push:
                        type: boolean
                      inApp:
                        type: boolean
                  types:
                    type: object
                    description: Updated per-type preferences
                    additionalProperties:
                      type: object
        '400':
          description: Bad request - invalid preference data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/notifications/preferences/master:
    get:
      summary: Get master notification toggles
      description: Returns the master enable/dis

# --- truncated at 32 KB (39 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/sageox/refs/heads/main/openapi/sageox-notifications-api-openapi.yml