{
  "openapi": "3.0.3",
  "info": {
    "title": "Infinite Context (ICX) API Reference",
    "version": "0.5.0",
    "description": "Infinite Context (ICX) API Reference.\n\nThe agent already connected to ICX is the language model in every case. ICX is the epistemic co-processor. Recall, quote, or walk the lattice, then write the answer yourself. Do not ask calera-vln-icx to speak, and do not hand the reply to another model. calera.speaker is connected_agent on every completion. answer_source describes the HTTP body only. Do not relay it.\n\n## Core Capabilities\n- **Lattice recall:** the connected agent writes the answer.\n- **Document Ingestion:** Single file upload (/v1/ingest/file), raw text (/v1/ingest/text), and async bulk (/v1/ingest/bulk).\n- **Living Auto-Sync:** Continuous changefeed connectors and webhooks (/v1/sync/*).\n- **Instant Purge:** Constant-time memory source unlinking (/v1/sync/purge).\n- **Memory Spaces:** Cryptographically isolated tenant memory spaces (/v1/memory/spaces).\n- **Memory Search:** Direct topological and keyword fact search (/v1/lattice/search).",
    "contact": {
      "name": "Calera Labs Support",
      "email": "support@caleralabs.com",
      "url": "https://icx.caleralabs.com"
    }
  },
  "servers": [
    {
      "url": "https://icx.api.caleralabs.com",
      "description": "Production ICX API Gateway"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    },
    {
      "XApiKeyAuth": []
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "Co-processor transport (OpenAI JSON shape)",
        "operationId": "createChatCompletion",
        "description": "Transport only. The agent already connected to ICX is the language model in every case. calera.speaker is connected_agent. Do not relay message.content. Do not ask calera-vln-icx to speak, and do not hand the reply to another model. Tool catalogs in message.content are a fault.",
        "parameters": [
          {
            "name": "X-Session-ID",
            "in": "header",
            "description": "Optional session identifier to isolate or resume turn history (e.g. sess_prod_123)",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Tenant-ID",
            "in": "header",
            "description": "Optional explicit tenant name (e.g. tenant_acme). If omitted, ICX derives a non-secret tenant_k_<hash> from the API key. Raw API keys are never stored in fact keys or echoed in payloads.",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Space-ID",
            "in": "header",
            "description": "Optional isolated memory space within the tenant (e.g. legal_vault_2026).",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-LLM-Provider",
            "in": "header",
            "description": "Optional BYOK LLM provider override: openai, anthropic, gemini, deepseek, qwen, vllm, ollama",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-LLM-API-Key",
            "in": "header",
            "description": "Optional third-party provider API key for BYOK generation (e.g. sk-proj-...)",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-LLM-Model",
            "in": "header",
            "description": "Optional model override on BYOK provider (e.g. gpt-4o, claude-3-5-sonnet, gemini-1.5-pro)",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CaleraLabs-OrgId",
            "in": "header",
            "description": "Enterprise organization ID routing header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-ICX-Geodesic-Ribbon",
            "in": "header",
            "description": "Optional boolean header (default false). When true, enables Epistemic Geodesic Navigation to extract and inject a 1D holographic ribbon into the prompt viewport, dropping context injection from 2,000+ tokens down to an 80-token crystal chain.",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful chat completion response (JSON or SSE stream)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing ICX API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable - Lattice node maintenance or loading",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List Available ICX Models",
        "operationId": "listModels",
        "description": "Lists calera-vln-icx, the epistemic co-processor, plus gpt-4 and gpt-3.5-turbo as aliases of that id. The aliases are not OpenAI models. Each entry includes calera_kind.",
        "responses": {
          "200": {
            "description": "List of available models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "example": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ModelObject"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/embeddings": {
      "post": {
        "summary": "Create Embeddings",
        "operationId": "createEmbedding",
        "description": "Generates topological vector representations on the Volumetric Lattice Network.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "calera-vln-icx"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string",
                        "example": "Contractual indemnity terms"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  }
                },
                "required": [
                  "model",
                  "input"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Embedding vector response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "example": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "object": {
                            "type": "string",
                            "example": "embedding"
                          },
                          "index": {
                            "type": "integer",
                            "example": 0
                          },
                          "embedding": {
                            "type": "array",
                            "items": {
                              "type": "number"
                            }
                          }
                        }
                      }
                    },
                    "model": {
                      "type": "string",
                      "example": "calera-vln-icx"
                    },
                    "usage": {
                      "type": "object",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer"
                        },
                        "total_tokens": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/ingest/text": {
      "post": {
        "summary": "Ingest Raw Text Document",
        "operationId": "ingestTextV1",
        "description": "Ingest raw text into tenant isolated VLN memory space for sub-quadratic associative recall.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "description": "Target memory space ID",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextIngestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document successfully ingested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/ingest/text": {
      "post": {
        "summary": "Ingest Raw Text Document (API Alias)",
        "operationId": "ingestTextApi",
        "description": "Ingest raw text into tenant isolated VLN memory space.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextIngestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document successfully ingested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ingest/file": {
      "post": {
        "summary": "Upload and Ingest Document File",
        "operationId": "ingestFileV1",
        "description": "Upload `.pdf`, `.md`, `.txt`, `.json`, `.csv`, `.docx`, `.xlsx`, `.eml`, `.html`, or code files for simplicial lattice crystallization.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "description": "Target memory space ID",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The document file to upload and ingest"
                  },
                  "space_id": {
                    "type": "string",
                    "description": "Target memory space ID (overridden by X-Space-ID if present)"
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File successfully ingested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/ingest/file": {
      "post": {
        "summary": "Upload and Ingest Document File (API Alias)",
        "operationId": "ingestFileApi",
        "description": "Upload document file for lattice crystallization.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "space_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File successfully ingested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ingest/bulk": {
      "post": {
        "summary": "Submit High-Throughput Bulk Document / Dialogue Ingestion",
        "operationId": "submitBulkIngestV1",
        "description": "Submit high-throughput batch ingestion for multi-turn conversations, structured document batches with family scoping, and large corpora in a single HTTP request.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Tenant-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sync": {
                    "type": "boolean",
                    "description": "Whether to ingest synchronously (default: true for immediate indexing) or asynchronously"
                  },
                  "family": {
                    "type": "string",
                    "description": "Default domain taxonomy label for all records/turns in this batch"
                  },
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Document text content"
                        },
                        "family": {
                          "type": "string",
                          "description": "Scoped recall family taxonomy label"
                        },
                        "filename": {
                          "type": "string",
                          "description": "Document filename or identifier"
                        },
                        "seq": {
                          "type": "integer",
                          "description": "Optional sequence number"
                        }
                      },
                      "required": [
                        "text"
                      ]
                    },
                    "description": "Array of structured document records with family taxonomy"
                  },
                  "turns": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "user": {
                          "type": "string",
                          "description": "User message text"
                        },
                        "assistant": {
                          "type": "string",
                          "description": "Assistant response text"
                        },
                        "family": {
                          "type": "string",
                          "description": "Turn family (defaults to user text)"
                        },
                        "filename": {
                          "type": "string",
                          "description": "Turn filename identifier"
                        }
                      }
                    },
                    "description": "Array of multi-turn dialogue pairs"
                  },
                  "corpus": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Array of raw document text bodies (backward compatible)"
                  },
                  "folder_path": {
                    "type": "string",
                    "description": "Server-side folder path for folder ingestion"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bulk ingestion completed synchronously",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "completed"
                    },
                    "job_id": {
                      "type": "string",
                      "example": "bulk_1786897200000"
                    },
                    "total_documents": {
                      "type": "integer"
                    },
                    "facts_learned": {
                      "type": "integer"
                    },
                    "size_bytes": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Bulk ingestion job accepted asynchronously",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job_id": {
                      "type": "string",
                      "example": "job_8f92ab12"
                    },
                    "status": {
                      "type": "string",
                      "example": "queued"
                    },
                    "total_documents": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/ingest/bulk/{job_id}": {
      "get": {
        "summary": "Get Bulk Ingestion Job Status",
        "operationId": "getBulkStatusV1",
        "description": "Poll the progress of an asynchronous bulk ingestion job.",
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Bulk job status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "example": "completed"
                    },
                    "processed_count": {
                      "type": "integer"
                    },
                    "total_count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/memory/spaces": {
      "get": {
        "summary": "List Active Memory Spaces",
        "operationId": "listMemorySpaces",
        "description": "List all active partitioned memory spaces for the authenticated tenant.",
        "responses": {
          "200": {
            "description": "List of active memory spaces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "spaces": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MemorySpace"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create Isolated Memory Space",
        "operationId": "createMemorySpace",
        "description": "Create and initialize a new named memory space with cryptographic isolation.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemorySpaceCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Memory space created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MemorySpace"
                }
              }
            }
          }
        }
      }
    },
    "/v1/memory/quote": {
      "post": {
        "summary": "Quote one stored register by family",
        "operationId": "quoteMemoryRegister",
        "description": "Return the exact stored register body for a caller-supplied family label and 1-based index (or stored seq). No LLM. Spaces ingested before family/seq was stored must be re-ingested. ICX does not infer family from the user question.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "family"
                ],
                "properties": {
                  "family": {
                    "type": "string",
                    "example": "msa.indemnity"
                  },
                  "index": {
                    "type": "integer",
                    "description": "1-based position within the family in ingest order",
                    "example": 3
                  },
                  "seq": {
                    "type": "integer",
                    "description": "0-based stored ingest sequence",
                    "example": 2
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Exact register body",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "quoted": {
                      "type": "boolean",
                      "example": true
                    },
                    "text": {
                      "type": "string"
                    },
                    "family": {
                      "type": "string"
                    },
                    "index": {
                      "type": "integer"
                    },
                    "seq": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Family not stored in this space (re-ingest required) or index/seq out of range"
          }
        }
      }
    },
    "/v1/memory/spaces/{space_id}": {
      "get": {
        "summary": "Get Memory Space Details",
        "operationId": "getMemorySpace",
        "description": "Retrieve node count, token usage, and metadata for a specific memory space.",
        "parameters": [
          {
            "name": "space_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memory space details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MemorySpace"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete & Flush Memory Space",
        "operationId": "deleteMemorySpace",
        "description": "Permanently flush and purge all crystallized facts in the target memory space.",
        "parameters": [
          {
            "name": "space_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memory space purged",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "deleted"
                    },
                    "space_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/session": {
      "get": {
        "summary": "Retrieve Active Session History",
        "operationId": "getSession",
        "parameters": [
          {
            "name": "X-Session-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session history details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session_id": {
                      "type": "string"
                    },
                    "turn_count": {
                      "type": "integer"
                    },
                    "history": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChatMessage"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Reset Session Turn History",
        "operationId": "deleteSession",
        "description": "Resets dialogue turn history for the tenant while preserving underlying lattice memory.",
        "parameters": [
          {
            "name": "X-Session-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session successfully reset",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "reset_complete"
                    },
                    "session_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/session/reset": {
      "post": {
        "summary": "Reset Session Turn History (POST Alias)",
        "operationId": "resetSessionPost",
        "description": "Resets conversation turn history while preserving underlying VLN lattice knowledge.",
        "parameters": [
          {
            "name": "X-Session-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session successfully reset",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "reset_complete"
                    },
                    "session_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions": {
      "get": {
        "summary": "List Registered Tenant Sessions",
        "operationId": "listSessions",
        "responses": {
          "200": {
            "description": "List of active session identifiers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/query": {
      "post": {
        "summary": "Topological Similarity & Basis Telemetry Query",
        "operationId": "queryLatticeTopologyV1",
        "description": "Similarity search over the caller's memory space. Returns matched facts, a similarity score, and a proof token. Substrate topology is not included.",
        "parameters": [
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-License-Key",
            "in": "header",
            "description": "Account license key",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Search query or concept string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 10,
                    "description": "Maximum number of topological matches to return"
                  },
                  "min_similarity": {
                    "type": "number",
                    "default": 0.0,
                    "description": "Minimum similarity threshold in [0, 1]"
                  },
                  "space_id": {
                    "type": "string",
                    "description": "Optional target memory space ID"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matched facts for the caller. Substrate topology is omitted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "query": {
                      "type": "string"
                    },
                    "tenant_id": {
                      "type": "string"
                    },
                    "sovereign_license_verified": {
                      "type": "boolean"
                    },
                    "tier": {
                      "type": "string"
                    },
                    "matches": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "content": {
                            "type": "string"
                          },
                          "similarity_score": {
                            "type": "number"
                          },
                          "topological_distance": {
                            "type": "integer"
                          },
                          "cis_token": {
                            "type": "string"
                          },
                          "voronoi_id": {
                            "description": "Withheld on the hosted API"
                          },
                          "sovereign_license_verified": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "count": {
                      "type": "integer"
                    },
                    "notice": {
                      "type": "string"
                    },
                    "timestamp": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/lattice/query": {
      "post": {
        "summary": "Topological Similarity & Basis Telemetry Query (API Alias)",
        "operationId": "queryLatticeTopologyApi",
        "description": "API alias for /v1/lattice/query.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer"
                  },
                  "min_similarity": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Topological matches"
          }
        }
      }
    },
    "/v1/lattice/search": {
      "get": {
        "summary": "Tokenized Simplicial Fact Search",
        "operationId": "searchLatticeV1",
        "description": "Rank decoded lattice facts, provenance records, and entity relations by query-token overlap on the A\u2084 simplicial manifold. Missing query tokens lower the fact score rather than zeroing the entire hit. Stopwords are down-weighted.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Search query terms",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "space_id",
            "in": "query",
            "required": false,
            "description": "Optional memory space filter",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "tenant_id": {
                      "type": "string"
                    },
                    "total_matches": {
                      "type": "integer"
                    },
                    "matches": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "content": {
                            "type": "string"
                          },
                          "confidence": {
                            "type": "number",
                            "description": "Query-relative retrieval confidence in [0, 1]"
                          },
                          "document_id": {
                            "type": "string"
                          },
                          "location": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/lattice/search": {
      "get": {
        "summary": "Tokenized Simplicial Fact Search (API Alias)",
        "operationId": "searchLatticeApi",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "space_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "total_matches": {
                      "type": "integer"
                    },
                    "matches": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/stats": {
      "get": {
        "summary": "Retrieve Lattice Statistics",
        "operationId": "getLatticeStatsV1",
        "description": "Returns node count, memory crystallization bytes, and simplicial connectivity.",
        "responses": {
          "200": {
            "description": "Lattice topology statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_nodes": {
                      "type": "integer"
                    },
                    "memory_crystallized_bytes": {
                      "type": "integer"
                    },
                    "active_spaces": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/lattice/stats": {
      "get": {
        "summary": "Retrieve Lattice Statistics (API Alias)",
        "operationId": "getLatticeStatsApi",
        "responses": {
          "200": {
            "description": "Lattice topology statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_nodes": {
                      "type": "integer"
                    },
                    "memory_crystallized_bytes": {
                      "type": "integer"
                    },
                    "active_spaces": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/nodes": {
      "get": {
        "summary": "List & Paginate Lattice Nodes",
        "operationId": "listLatticeNodes",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "space_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of lattice nodes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "nodes": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/nodes/{id}": {
      "get": {
        "summary": "Get Node Detail & 20 A4 Neighbor Edges",
        "operationId": "getNodeDetail",
        "description": "Returns full state coordinates and all 20 directed A4 simplicial neighbor synapses for a node.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Node details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/lattice/edges": {
      "get": {
        "summary": "List Active Directed Synapses",
        "operationId": "listLatticeEdges",
        "parameters": [
          {
            "name": "min_weight",
            "in": "query",
            "schema": {
              "type": "number",
              "default": 0.01
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of active synapse edges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "edges": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/lattice/preview": {
      "get": {
        "summary": "Preview Sanitized Lattice Topology",
        "operationId": "previewTopology",
        "description": "Fetch sanitized node coordinates and synapse edges for frontend lattice visualizers (D3, Three.js).",
        "responses": {
          "200": {
            "description": "Sanitized lattice topology preview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "summary": {
                      "type": "object"
                    },
                    "nodes": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "edges": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/contradictions": {
      "get": {
        "summary": "Query Detected Contradictions",
        "operationId": "getLatticeContradictions",
        "description": "Query contradiction detection records across ingested facts and topological subgraphs.",
        "responses": {
          "200": {
            "description": "List of contradiction records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contradictions": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/metering/usage": {
      "get": {
        "summary": "Tenant Metering & Quota Usage",
        "operationId": "getMeteringUsage",
        "responses": {
          "200": {
            "description": "Metering metrics and remaining tokens/calls",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tier": {
                      "type": "string"
                    },
                    "tokens_stored": {
                      "type": "integer"
                    },
                    "tokens_limit": {
                      "type": "integer"
                    },
                    "calls_used": {
                      "type": "integer"
                    },
                    "calls_limit": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/key/state": {
      "get": {
        "summary": "API Key Entitlement State",
        "operationId": "getAPIKeyState",
        "responses": {
          "200": {
            "description": "Key status and active tier features",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "active": {
                      "type": "boolean"
                    },
                    "tier": {
                      "type": "string"
                    },
                    "features": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/telemetry": {
      "get": {
        "summary": "Real-Time Telemetry Metrics",
        "operationId": "getTelemetry",
        "responses": {
          "200": {
            "description": "Service telemetry metrics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_requests": {
                      "type": "integer"
                    },
                    "total_tokens": {
                      "type": "integer"
                    },
                    "uptime_seconds": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "Check Health Status",
        "operationId": "checkHealth",
        "responses": {
          "200": {
            "description": "Service health summary",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/ready": {
      "get": {
        "summary": "Check Readiness Status",
        "operationId": "checkReady",
        "responses": {
          "200": {
            "description": "Readiness indicator",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ready"
                    },
                    "ready": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ops/slo": {
      "get": {
        "summary": "Retrieve Service SLO Benchmarks",
        "operationId": "checkSLO",
        "responses": {
          "200": {
            "description": "SLO benchmark metrics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ready"
                    },
                    "p95_latency_ms": {
                      "type": "number",
                      "example": 0.45
                    },
                    "availability": {
                      "type": "number",
                      "example": 0.9999
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/webhook/{provider}": {
      "post": {
        "summary": "Ingest Continuous Changefeed Webhook Event",
        "operationId": "ingestSyncWebhook",
        "description": "Receives continuous repository commits, document revisions, issue state transitions, or database DDL events from cloud providers (GitHub, GitLab, Notion, Google Drive, Linear, Slack, Postgres). Automatically extracts deltas and crystallizes facts into the tenant memory lattice in sub-2ms on CPU.",
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "description": "Webhook provider identifier (`github`, `gitlab`, `notion`, `google_drive`, `linear`, `slack`, `postgres`, `generic`)",
            "schema": {
              "type": "string",
              "enum": [
                "github",
                "gitlab",
                "notion",
                "google_drive",
                "linear",
                "slack",
                "postgres",
                "generic"
              ]
            }
          },
          {
            "name": "X-Hub-Signature-256",
            "in": "header",
            "required": false,
            "description": "HMAC-SHA256 signature header for GitHub webhook payloads",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Notion-Signature",
            "in": "header",
            "required": false,
            "description": "HMAC-SHA256 signature header for Notion webhook payloads",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Space-ID",
            "in": "header",
            "required": false,
            "description": "Target memory space ID partition",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook processed and deltas crystallized into memory lattice",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncWebhookResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/connectors": {
      "get": {
        "summary": "List Active Changefeed Connectors",
        "operationId": "listSyncConnectors",
        "description": "List all active cloud changefeed connectors and sync status for the authenticated tenant.",
        "responses": {
          "200": {
            "description": "List of active connectors",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connectors": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConnectorRegistration"
                      }
                    },
                    "total": {
                      "type": "integer",
                      "example": 3
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Register a Cloud Changefeed Connector",
        "operationId": "createSyncConnector",
        "description": "Register a new cloud changefeed connector (GitHub, GitLab, Notion, Google Drive, Linear, Slack, Postgres) with zero-knowledge AES-256-GCM secret vaulting.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConnectorCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connector registered successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectorRegistration"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/connectors/{id}": {
      "get": {
        "summary": "Get Connector Details",
        "operationId": "getSyncConnector",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connector detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectorRegistration"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete Connector & Execute O(1) Instant Epistemic Purge",
        "operationId": "deleteSyncConnector",
        "description": "Deletes the connector and executes O(1) instant memory unlinking of all simplices and facts learned from this source without model retraining.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connector deleted and memory unlinked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "purged"
                    },
                    "connector_id": {
                      "type": "string",
                      "example": "conn_github_01"
                    },
                    "simplices_unlinked": {
                      "type": "integer",
                      "example": 240
                    },
                    "duration_ms": {
                      "type": "number",
                      "example": 0.18
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/connectors/{id}/trigger": {
      "post": {
        "summary": "Trigger Incremental Sync on Connector",
        "operationId": "triggerSyncConnector",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sync job initiated or executed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "synced"
                    },
                    "connector_id": {
                      "type": "string",
                      "example": "conn_github_01"
                    },
                    "deltas_crystallized": {
                      "type": "integer",
                      "example": 14
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/connectors/{id}/facts": {
      "get": {
        "summary": "Retrieve Grounded Facts Tracked for Connector",
        "operationId": "getConnectorFacts",
        "description": "Inspect all simplicial facts and statements currently tracked in Volumetric Memory for this registered connector.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Grounded facts list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connector_id": {
                      "type": "string"
                    },
                    "tenant_id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    },
                    "total_facts": {
                      "type": "integer"
                    },
                    "facts": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/connectors/file": {
      "get": {
        "summary": "Fetch On-Demand Document Content from Connected Source",
        "operationId": "getConnectorDocument",
        "description": "Fetches the full text, markdown, or code content of a connected document, file, page, or issue (Google Drive doc, Notion page, GitHub/GitLab file, Linear ticket).",
        "parameters": [
          {
            "name": "file_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "connector_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Document content retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "file_id": {
                      "type": "string"
                    },
                    "connector_id": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    },
                    "content": {
                      "type": "string"
                    },
                    "length": {
                      "type": "integer"
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/ephemeral": {
      "post": {
        "summary": "Ingest Ephemeral Memory with Dynamic TTL Decay",
        "operationId": "ingestEphemeralMemory",
        "description": "Ingest temporary context, debug logs, or transient meeting notes into the lattice with an automatic expiration time-to-live (TTL).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EphemeralIngestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ephemeral memory crystallized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EphemeralIngestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/audit": {
      "get": {
        "summary": "Retrieve Sync Audit Trail",
        "operationId": "getSyncAuditTrail",
        "description": "Retrieve historical sync events, deltas processed, facts learned/invalidated, and latency logs for compliance.",
        "responses": {
          "200": {
            "description": "Sync audit entries",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncAuditResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sync/purge": {
      "post": {
        "summary": "Instantly Purge and Unlink Memory Source",
        "operationId": "purgeMemorySource",
        "description": "Unlinks all crystallized memory nodes and edges associated with a source_id in constant O(1) time.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "space_id": {
                    "type": "string",
                    "example": "legal_contracts"
                  },
                  "source_id": {
                    "type": "string",
                    "example": "contract_acme_2026"
                  }
                },
                "required": [
                  "source_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Memory source successfully purged",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "purged"
                    },
                    "space_id": {
                      "type": "string",
                      "example": "legal_contracts"
                    },
                    "source_id": {
                      "type": "string",
                      "example": "contract_acme_2026"
                    },
                    "nodes_unlinked": {
                      "type": "integer",
                      "example": 1420
                    },
                    "purge_latency_ms": {
                      "type": "number",
                      "example": 1.12
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/lattice/geodesic": {
      "post": {
        "summary": "Calculate Stationary Action Geodesic Ribbon",
        "operationId": "calculateLatticeGeodesic",
        "description": "Calculates the continuous stationary least-action path (delta S = 0) across the 4D simplicial memory manifold between a premise and target entity, serializing a 1D holographic milestone ribbon. Substrate coordinates are masked on public hosted tiers.",
        "tags": [
          "Lattice"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LatticeGeodesicRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Geodesic ribbon successfully calculated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LatticeGeodesicResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input parameters (premise and target required)"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Calera API key (`clabs_live_...` from the dashboard, or `clabs_live_agent_...` from claim `api_key`). Send exactly one auth header. The server reads X-License-Key, then X-API-Key, then Authorization. On MCP, Bearer is accepted when the key starts with `clabs_`, `calera_`, or `vln_` and the other two headers are absent. The claim field `license_key` does not authenticate."
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-License-Key",
        "description": "Same Calera API key as `api_key` (`clabs_live_...`). The only header to send on MCP. Do not also send Authorization or X-API-Key. Do not send the claim field `license_key`."
      },
      "XApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Same Calera API key as `api_key` (`clabs_live_...`), with no Bearer prefix. Send this only when X-License-Key and Authorization are absent."
      }
    },
    "schemas": {
      "ChatMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ],
            "example": "user"
          },
          "content": {
            "type": "string",
            "example": "Recall exact contractual indemnity cap across all enterprise MSAs."
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "ChatCompletionRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "example": "calera-vln-icx"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "example": false
          },
          "temperature": {
            "type": "number",
            "default": 0.7,
            "example": 0.7
          },
          "max_tokens": {
            "type": "integer",
            "example": 2048
          },
          "space_id": {
            "type": "string",
            "description": "Target memory space ID",
            "example": "legal_vault_2026"
          },
          "enable_geodesic_ribbon": {
            "type": "boolean",
            "description": "Optional flag (default false). When true, enables Epistemic Geodesic Navigation to extract and inject a 1D holographic ribbon into the prompt viewport, dropping context injection from 2,000+ tokens down to an 80-token crystal chain.",
            "default": false,
            "example": false
          }
        },
        "required": [
          "model",
          "messages"
        ]
      },
      "ChatCompletionChoice": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer",
            "example": 0
          },
          "message": {
            "$ref": "#/components/schemas/ChatMessage"
          },
          "finish_reason": {
            "type": "string",
            "example": "stop"
          }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "chatcmpl-icx-998a12"
          },
          "object": {
            "type": "string",
            "example": "chat.completion"
          },
          "created": {
            "type": "integer",
            "example": 1770000000
          },
          "model": {
            "type": "string",
            "description": "calera-vln-icx when no X-LLM-API-Key is set. The upstream model id when answer_source is upstream_llm.",
            "example": "calera-vln-icx"
          },
          "calera": {
            "type": "object",
            "description": "Who ICX is and who wrote choices[].message.content. Read this before treating the assistant string as a chat-model reply.",
            "properties": {
              "product": { "type": "string", "example": "ICX" },
              "kind": { "type": "string", "example": "epistemic_coprocessor" },
              "answer_source": {
                "type": "string",
                "enum": ["upstream_llm", "local_generator", "mock_surface", "degraded_lattice_facts", "unspecified"],
                "example": "mock_surface"
              },
              "prompt_authority": {
                "type": "string",
                "enum": ["connected_agent"],
                "example": "connected_agent"
              },
              "speaker": {
                "type": "string",
                "enum": ["connected_agent"],
                "example": "connected_agent"
              },
              "requested_model": { "type": "string", "example": "calera-vln-icx" },
              "remediation": { "type": "string" }
            },
            "required": ["product", "kind", "answer_source", "prompt_authority", "speaker", "remediation"]
          },
          "choices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatCompletionChoice"
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer",
                "example": 45
              },
              "completion_tokens": {
                "type": "integer",
                "example": 128
              },
              "total_tokens": {
                "type": "integer",
                "example": 173
              }
            }
          },
          "vln_telemetry": {
            "type": "object",
            "description": "VLN recall performance metrics, citations, and grounding confidence. citations[].confidence is the per-query retrieval score in [0, 1].",
            "properties": {
              "recall_latency_ms": {
                "type": "number",
                "example": 0.42
              },
              "facts_retrieved": {
                "type": "integer",
                "example": 12
              },
              "facts_learned": {
                "type": "integer",
                "example": 0
              },
              "grounding_score": {
                "type": "number",
                "example": 0.965
              },
              "llm_status": {
                "type": "string",
                "example": "ready"
              },
              "llm_source": {
                "type": "string",
                "description": "Code path that wrote the text: byok, local_bridge, mock_custom, mock_default, unavailable. answer_source is the caller-facing name of that path.",
                "example": "byok"
              },
              "substrate": {
                "type": "string",
                "example": "epistemic_coprocessor"
              },
              "answer_source": {
                "type": "string",
                "example": "upstream_llm"
              },
              "prompt_authority": {
                "type": "string",
                "example": "connected_agent"
              },
              "speaker": {
                "type": "string",
                "example": "connected_agent"
              },
              "remediation": {
                "type": "string"
              },
              "citations": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "document_id": {
                      "type": "string",
                      "example": "doc_msa_2026_q2"
                    },
                    "document_title": {
                      "type": "string",
                      "example": "Master Service Agreement 2026"
                    },
                    "location": {
                      "type": "string",
                      "example": "Section 14.2 (Indemnification Cap)"
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Query-relative retrieval score in [0, 1]",
                      "example": 0.98
                    }
                  }
                }
              },
              "geodesic_ribbon": {
                "type": "string",
                "description": "Optional 1D holographic ribbon injected when opted in via enable_geodesic_ribbon or X-ICX-Geodesic-Ribbon",
                "example": "[nav:ribbon premise=\"AAPL_REV\" target=\"FREE_CASH_FLOW\" steps=5 action=5.66]\nAAPL_REV -> OPERATING_INCOME -> TAX_EXPENSE -> NOPAT -> FREE_CASH_FLOW"
              },
              "ribbon_tokens": {
                "type": "integer",
                "description": "Token count of the serialized 1D ribbon",
                "example": 84
              },
              "action_cost": {
                "type": "number",
                "description": "Stationary action cost of the geodesic path",
                "example": 5.66
              },
              "ttft_reduction_pct": {
                "type": "number",
                "description": "Percentage reduction in Time-To-First-Token achieved by ribbon compaction",
                "example": 88.5
              }
            }
          }
        }
      },
      "ModelObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "calera-vln-icx"
          },
          "object": {
            "type": "string",
            "example": "model"
          },
          "created": {
            "type": "integer",
            "example": 1770000000
          },
          "owned_by": {
            "type": "string",
            "example": "calera-computing"
          },
          "calera_kind": {
            "type": "string",
            "enum": ["epistemic_coprocessor", "alias_of_calera-vln-icx"],
            "example": "epistemic_coprocessor"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "TextIngestRequest": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "example": "Acme Corp Master Agreement Section 14: Indemnity cap is $10M."
          },
          "filename": {
            "type": "string",
            "example": "vendor_agreement.pdf.txt"
          },
          "space_id": {
            "type": "string",
            "example": "legal_vault_2026"
          },
          "family": {
            "type": "string",
            "description": "Opaque caller label grouping near-duplicate registers. Not inferred from the user question.",
            "example": "msa.indemnity"
          },
          "seq": {
            "type": "integer",
            "description": "Ignored on ingest. Server assigns 0-based seq per (space, family) ingest order so quote(index=k) is the k-th member. Echoed in the response.",
            "example": 2
          }
        },
        "required": [
          "text"
        ]
      },
      "IngestResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "success"
          },
          "filename": {
            "type": "string",
            "example": "vendor_agreement.pdf"
          },
          "tokens_ingested": {
            "type": "integer",
            "example": 42
          },
          "document_id": {
            "type": "string",
            "example": "doc_8f1a23"
          },
          "seq": {
            "type": "integer",
            "description": "Server-assigned 0-based sequence for this register. Per (space, family) ingest order when family is set.",
            "example": 2
          },
          "family": {
            "type": "string",
            "example": "msa.indemnity"
          }
        }
      },
      "MemorySpace": {
        "type": "object",
        "properties": {
          "space_id": {
            "type": "string",
            "example": "legal_vault_2026"
          },
          "name": {
            "type": "string",
            "example": "Legal Agreements Vault"
          },
          "description": {
            "type": "string",
            "example": "2026 Enterprise customer MSAs and NDAs"
          },
          "active_tokens": {
            "type": "integer",
            "example": 150000
          },
          "node_count": {
            "type": "integer",
            "example": 842
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MemorySpaceCreateRequest": {
        "type": "object",
        "properties": {
          "space_id": {
            "type": "string",
            "example": "legal_vault_2026"
          },
          "name": {
            "type": "string",
            "example": "Legal Agreements Vault"
          },
          "description": {
            "type": "string",
            "example": "2026 Enterprise customer MSAs and NDAs"
          }
        },
        "required": [
          "space_id"
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string",
                "example": "Invalid API key provided"
              },
              "type": {
                "type": "string",
                "example": "invalid_request_error"
              },
              "code": {
                "type": "string",
                "example": "invalid_api_key"
              }
            }
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "healthy"
          },
          "service": {
            "type": "string",
            "example": "vln-icx"
          },
          "version": {
            "type": "string",
            "example": "0.5.0"
          },
          "uptime": {
            "type": "string",
            "example": "124h30m"
          }
        }
      },
      "SyncWebhookResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "processed"
          },
          "provider": {
            "type": "string",
            "example": "github"
          },
          "event": {
            "type": "string",
            "example": "push"
          },
          "deltas_crystallized": {
            "type": "integer",
            "example": 8
          },
          "facts_learned": {
            "type": "integer",
            "example": 24
          },
          "duration_ms": {
            "type": "number",
            "example": 1.42
          }
        }
      },
      "ConnectorRegistration": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "conn_github_01"
          },
          "tenant_id": {
            "type": "string",
            "example": "tenant_k_8f12a"
          },
          "type": {
            "type": "string",
            "example": "github"
          },
          "name": {
            "type": "string",
            "example": "Production Monorepo"
          },
          "target_uri": {
            "type": "string",
            "example": "https://github.com/acme/core-engine"
          },
          "webhook_url": {
            "type": "string",
            "example": "https://icx.api.caleralabs.com/v1/sync/webhook/github"
          },
          "status": {
            "type": "string",
            "example": "active"
          },
          "facts_count": {
            "type": "integer",
            "example": 1420
          },
          "last_sync_at": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ConnectorCreateRequest": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "github",
              "gitlab",
              "notion",
              "google_drive",
              "linear",
              "slack",
              "postgres",
              "generic"
            ],
            "example": "github"
          },
          "name": {
            "type": "string",
            "example": "Production Monorepo"
          },
          "target_uri": {
            "type": "string",
            "example": "https://github.com/acme/core-engine"
          },
          "webhook_secret": {
            "type": "string",
            "example": "whsec_98fa201b"
          },
          "access_token": {
            "type": "string",
            "example": "ghp_secureToken123"
          }
        },
        "required": [
          "type",
          "name",
          "target_uri"
        ]
      },
      "EphemeralIngestRequest": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "example": "Sprint planning action items and temporary deployment notes."
          },
          "ttl": {
            "type": "string",
            "description": "TTL duration (e.g. 30m, 4h, 24h)",
            "example": "4h"
          },
          "space_id": {
            "type": "string",
            "example": "sprint_tmp"
          },
          "source_id": {
            "type": "string",
            "example": "slack_thread_991"
          }
        },
        "required": [
          "text",
          "ttl"
        ]
      },
      "EphemeralIngestResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "crystallized_ephemeral"
          },
          "facts_learned": {
            "type": "integer",
            "example": 12
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "ttl": {
            "type": "string",
            "example": "4h"
          }
        }
      },
      "SyncAuditResponse": {
        "type": "object",
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "example": "audit_8fa12"
                },
                "connector_id": {
                  "type": "string",
                  "example": "conn_github_01"
                },
                "connector_type": {
                  "type": "string",
                  "example": "github"
                },
                "event_name": {
                  "type": "string",
                  "example": "push"
                },
                "deltas_processed": {
                  "type": "integer",
                  "example": 4
                },
                "facts_learned": {
                  "type": "integer",
                  "example": 12
                },
                "duration_ms": {
                  "type": "number",
                  "example": 0.85
                },
                "timestamp": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "LatticeGeodesicRequest": {
        "type": "object",
        "description": "Request payload for calculating a 1D Geodesic Ribbon between premise and target",
        "properties": {
          "premise": {
            "type": "string",
            "description": "Starting premise concept or entity identifier",
            "example": "AAPL_REV"
          },
          "target": {
            "type": "string",
            "description": "Target conclusion concept or entity identifier",
            "example": "FREE_CASH_FLOW"
          },
          "max_steps": {
            "type": "integer",
            "description": "Maximum intermediate hops allowed (default: 10, max: 50)",
            "example": 10
          },
          "max_action": {
            "type": "number",
            "description": "Variational action cutoff ceiling",
            "example": 1000.0
          },
          "space_id": {
            "type": "string",
            "description": "Optional memory space partition",
            "example": "finsec_vault"
          }
        },
        "required": [
          "premise",
          "target"
        ]
      },
      "LatticeGeodesicMilestone": {
        "type": "object",
        "description": "Intermediate crystallized waypoint along the stationary geodesic trajectory",
        "properties": {
          "index": {
            "type": "integer",
            "description": "0-based milestone index along the path",
            "example": 0
          },
          "concept_id": {
            "type": "string",
            "description": "Semantic concept identifier for this milestone",
            "example": "AAPL_REV"
          },
          "action_cost": {
            "type": "number",
            "description": "Cumulative action expenditure from the premise",
            "example": 0.0
          },
          "curvature": {
            "type": "number",
            "description": "Topological manifold curvature at this waypoint",
            "example": 0.0
          }
        },
        "required": [
          "index",
          "concept_id",
          "action_cost"
        ]
      },
      "LatticeGeodesicResponse": {
        "type": "object",
        "description": "Continuous stationary geodesic ribbon serialization across 4D simplicial memory",
        "properties": {
          "status": {
            "type": "string",
            "example": "success"
          },
          "premise": {
            "type": "string",
            "example": "AAPL_REV"
          },
          "target": {
            "type": "string",
            "example": "FREE_CASH_FLOW"
          },
          "steps": {
            "type": "integer",
            "example": 5
          },
          "action_cost": {
            "type": "number",
            "example": 5.66
          },
          "ribbon": {
            "type": "string",
            "example": "[nav:ribbon premise=\"AAPL_REV\" target=\"FREE_CASH_FLOW\" steps=5 action=5.66]\nAAPL_REV -> OPERATING_INCOME -> TAX_EXPENSE -> NOPAT -> FREE_CASH_FLOW"
          },
          "milestones": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LatticeGeodesicMilestone"
            }
          },
          "duration_ms": {
            "type": "number",
            "example": 0.82
          },
          "stationary_action": {
            "type": "boolean",
            "example": true
          },
          "notice": {
            "type": "string",
            "example": "Substrate topology is not included in API responses."
          }
        },
        "required": [
          "status",
          "premise",
          "target",
          "steps",
          "action_cost",
          "ribbon",
          "milestones",
          "duration_ms",
          "stationary_action"
        ]
      }
    }
  }
}