SageOx Git API

Browse repository files, view commits, compare branches, and manage the Ledger. The Ledger stores historical context (decisions, discussions, AI-generated summaries) as version-controlled files in a GitLab-backed repository. Also handles repository uninstall and permanent deletion workflows.

OpenAPI Specification

sageox-git-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: SageOx Admin Git 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: Git
  description: 'Browse repository files, view commits, compare branches, and manage the Ledger. The Ledger stores historical context (decisions, discussions, AI-generated summaries) as version-controlled files in a GitLab-backed repository. Also handles repository uninstall and permanent deletion workflows.

    '
paths:
  /api/v1/repos/{repo_id}/tree:
    get:
      operationId: getRepoTree
      summary: Get repository file tree
      description: 'Returns the file and directory tree for a repository at the specified path and reference.


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Caching:** Responses are cached for 30 seconds to reduce GitLab API load.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: path
        in: query
        schema:
          type: string
          example: src/components
        description: Subdirectory path (default empty/root)
      - name: ref
        in: query
        schema:
          type: string
          example: main
        description: Branch, tag, or commit SHA (default HEAD)
      - name: recursive
        in: query
        schema:
          type: boolean
          example: false
        description: Return recursive tree (all nested entries)
      responses:
        '200':
          description: Repository tree retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - entries
                - ref
                - path
                properties:
                  entries:
                    type: array
                    items:
                      type: object
                      required:
                      - name
                      - type
                      - path
                      properties:
                        name:
                          type: string
                          example: package.json
                        type:
                          type: string
                          enum:
                          - file
                          - directory
                          example: file
                        path:
                          type: string
                          example: package.json
                        size:
                          type: integer
                          example: 1234
                        mode:
                          type: string
                          example: '100644'
                  ref:
                    type: string
                    example: main
                  path:
                    type: string
                    example: src/components
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Repository or path 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/repos/{repo_id}/files/{path}:
    get:
      operationId: getRepoFileOrBlame
      summary: Get file content or blame information
      description: 'Returns file content with metadata or blame information if the path ends with `/blame`.


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Caching:** File content responses are cached for 30 seconds.


        **Blame Annotation:** Append `/blame` to the file path to retrieve line-by-line author and commit information.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: path
        in: path
        required: true
        schema:
          type: string
          example: README.md
        description: 'File path (supports nested paths). Append `/blame` to get blame information.

          Example: `src/main.py/blame`

          '
      - name: ref
        in: query
        schema:
          type: string
          example: main
        description: Branch, tag, or commit SHA (default HEAD)
      responses:
        '200':
          description: File content retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - content
                - size
                - is_binary
                - is_renderable
                properties:
                  content:
                    type: string
                    example: '# Welcome to Project A\n\nThis project demonstrates...'
                  size:
                    type: integer
                    example: 2048
                  file_name:
                    type: string
                    example: README.md
                  content_type:
                    type: string
                    example: text/markdown
                  encoding:
                    type: string
                    example: utf-8
                  is_binary:
                    type: boolean
                    example: false
                  is_renderable:
                    type: boolean
                    example: true
                  render_type:
                    type: string
                    enum:
                    - markdown
                    - plaintext
                    - code
                    - image
                    - pdf
                    example: markdown
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: File or repository 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/repos/{repo_id}/files/{path}/blame:
    get:
      operationId: getRepoFileBlame
      summary: Get file blame information
      description: 'Returns blame information (line-by-line author and commit history) for a file.


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Caching:** Responses are cached for 30 seconds.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: path
        in: path
        required: true
        schema:
          type: string
          example: src/main.py
        description: File path
      - name: ref
        in: query
        schema:
          type: string
          example: main
        description: Branch, tag, or commit SHA (default HEAD)
      responses:
        '200':
          description: Blame information retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - ranges
                - file_path
                - ref
                properties:
                  ranges:
                    type: array
                    items:
                      type: object
                      required:
                      - start_line
                      - end_line
                      - commit
                      - author_name
                      - author_email
                      - commit_date
                      properties:
                        start_line:
                          type: integer
                          example: 1
                        end_line:
                          type: integer
                          example: 10
                        commit:
                          type: object
                          required:
                          - id
                          - message
                          properties:
                            id:
                              type: string
                              example: abc123def456789abc123def456789abc123def4
                            message:
                              type: string
                              example: Implement feature X
                        author_name:
                          type: string
                          example: Person A
                        author_email:
                          type: string
                          format: email
                          example: user@example.com
                        commit_date:
                          type: string
                          format: date-time
                          example: '2025-12-18T10:30:00Z'
                  file_path:
                    type: string
                    example: src/main.py
                  ref:
                    type: string
                    example: main
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: File or repository 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/repos/{repo_id}/commits:
    get:
      operationId: getRepoCommits
      summary: List repository commits
      description: 'Returns a paginated list of commits for the repository, optionally filtered by path.


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Pagination:** Uses page-based pagination with configurable page size (max 100).


        **Caching:** Responses are cached for 30 seconds.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: ref
        in: query
        schema:
          type: string
          example: main
        description: Branch, tag, or commit SHA (default HEAD)
      - name: path
        in: query
        schema:
          type: string
          example: src
        description: Filter commits by path
      - name: page
        in: query
        schema:
          type: integer
          minimum: 1
          example: 1
        description: Page number (default 1)
      - name: per_page
        in: query
        schema:
          type: integer
          minimum: 1
          maximum: 100
          example: 20
        description: Items per page (default 20, max 100)
      responses:
        '200':
          description: Commits retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - commits
                - page
                - per_page
                - has_more
                properties:
                  commits:
                    type: array
                    items:
                      type: object
                      required:
                      - id
                      - message
                      - author_name
                      - author_email
                      - authored_date
                      properties:
                        id:
                          type: string
                          example: abc123def456789abc123def456789abc123def4
                        message:
                          type: string
                          example: Implement feature X
                        author_name:
                          type: string
                          example: Person A
                        author_email:
                          type: string
                          format: email
                          example: user@example.com
                        authored_date:
                          type: string
                          format: date-time
                          example: '2025-12-18T10:30:00Z'
                        committed_date:
                          type: string
                          format: date-time
                          example: '2025-12-18T10:30:00Z'
                        parent_ids:
                          type: array
                          items:
                            type: string
                          example:
                          - parent_sha_1
                          - parent_sha_2
                  page:
                    type: integer
                    example: 1
                  per_page:
                    type: integer
                    example: 20
                  total_count:
                    type: integer
                    example: 150
                  has_more:
                    type: boolean
                    example: true
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Repository 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/repos/{repo_id}/commits/{sha}:
    get:
      operationId: getRepoCommit
      summary: Get commit details
      description: 'Returns detailed information for a specific commit including diffs and statistics.


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Caching:** Responses are cached for 30 seconds.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: sha
        in: path
        required: true
        schema:
          type: string
          example: abc123def456789abc123def456789abc123def4
        description: Commit SHA
      responses:
        '200':
          description: Commit details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - id
                - message
                - author_name
                - author_email
                - authored_date
                properties:
                  id:
                    type: string
                    example: abc123def456789abc123def456789abc123def4
                  message:
                    type: string
                    example: Implement feature X\n\nThis commit adds support for feature X...
                  author_name:
                    type: string
                    example: Person A
                  author_email:
                    type: string
                    format: email
                    example: user@example.com
                  authored_date:
                    type: string
                    format: date-time
                    example: '2025-12-18T10:30:00Z'
                  committed_date:
                    type: string
                    format: date-time
                    example: '2025-12-18T10:30:00Z'
                  parent_ids:
                    type: array
                    items:
                      type: string
                    example:
                    - parent_sha_1
                  additions:
                    type: integer
                    example: 42
                  deletions:
                    type: integer
                    example: 8
                  files_changed:
                    type: integer
                    example: 3
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Commit or repository 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/repos/{repo_id}/compare:
    get:
      operationId: getRepoCompare
      summary: Compare two references
      description: 'Returns the diff between two references (branches, tags, or commits).


        **Authentication:** Required (bearer token)


        **Access Control:** User must be a member of a team associated with the repository.


        **Caching:** Responses are cached for 30 seconds.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      - name: from
        in: query
        required: true
        schema:
          type: string
          example: main
        description: Base reference (branch, tag, or SHA)
      - name: to
        in: query
        required: true
        schema:
          type: string
          example: feature/new-api
        description: Compare-to reference (branch, tag, or SHA)
      responses:
        '200':
          description: Comparison retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - from
                - to
                properties:
                  from:
                    type: string
                    example: main
                  to:
                    type: string
                    example: feature/new-api
                  commits:
                    type: array
                    items:
                      type: object
                      required:
                      - id
                      - message
                      - author_name
                      - authored_date
                      properties:
                        id:
                          type: string
                          example: abc123def456789abc123def456789abc123def4
                        message:
                          type: string
                          example: Add new API endpoint
                        author_name:
                          type: string
                          example: Person A
                        authored_date:
                          type: string
                          format: date-time
                          example: '2025-12-18T10:30:00Z'
                  additions:
                    type: integer
                    example: 120
                  deletions:
                    type: integer
                    example: 15
                  files_changed:
                    type: integer
                    example: 7
        '400':
          description: Invalid request parameters (missing from or to)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not a member of any team associated with this repository
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Repository or references 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/repos/{repo_id}/ledger-status:
    get:
      operationId: getRepoLedgerStatus
      summary: Check repository Ledger status
      description: 'Returns the status of the Ledger repository for a given repository.


        **Authentication:** Required (bearer token)


        **Status Values:**

        - `ready` - Ledger exists and is ready to use

        - `pending` - Ledger creation is in progress

        - `unavailable` - GitLab integration is not configured


        **Anti-Entropy:** This endpoint triggers async Ledger creation if missing.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      responses:
        '200':
          description: Ledger status retrieved
          content:
            application/json:
              schema:
                type: object
                required:
                - status
                properties:
                  status:
                    type: string
                    enum:
                    - ready
                    - pending
                    - unavailable
                    example: ready
                  repo_url:
                    type: string
                    format: uri
                    example: http://localhost:8929/groups/team-abc123/projects/ledger-repo-abc123
                  repo_id:
                    type: integer
                    example: 42
                  created_at:
                    type: string
                    format: date-time
                    example: '2025-12-18T10:30:00Z'
                  message:
                    type: string
                    example: Ledger repository not yet created
        '400':
          description: Invalid repo_id format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Repository 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/repos/{repo_id}/create-ledger:
    post:
      operationId: createRepoLedger
      summary: Create repository Ledger
      description: 'Manually triggers creation of a Ledger repository for a given repository.


        **Authentication:** Required (bearer token)


        **Response Codes:**

        - `201 Created` - Ledger was created successfully

        - `200 OK` - Ledger already exists

        - `503 Service Unavailable` - GitLab not configured or creation failed


        **Idempotent:** If Ledger already exists, returns existing repo information.

        '
      tags:
      - Git
      security:
      - bearerAuth: []
      parameters:
      - name: repo_id
        in: path
        required: true
        schema:
          type: string
          pattern: ^repo_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          example: repo_01934f5a-8b9c-7def-b012-3456789abcde
        description: Repository identifier
      responses:
        '200':
          description: Ledger already exists
        

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