{
  "openapi": "3.1.0",
  "info": {
    "title": "SwarmV API",
    "version": "1.0.0",
    "description": "Edge vector memory with relationship-based access control. Every request except /v1/health needs `Authorization: Bearer <credential>`: a backend API key (`evx_live_…` / `evx_test_…`, keep it on your server) or a short-lived user token from /v1/auth/token (for agents and clients). Each key belongs to one index.",
    "contact": {
      "email": "contact@swarmv.dev",
      "url": "https://swarmv.dev"
    }
  },
  "servers": [
    {
      "url": "https://api.swarmv.dev"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "Vectors",
      "description": "Write, search and read records."
    },
    {
      "name": "Auth",
      "description": "Tokens for agents and clients."
    },
    {
      "name": "Access graph",
      "description": "Who can see and change which containers."
    },
    {
      "name": "Service",
      "description": "Status."
    }
  ],
  "paths": {
    "/v1/insert": {
      "post": {
        "operationId": "insert",
        "tags": [
          "Vectors"
        ],
        "summary": "Insert or update a vector",
        "description": "Writes one record. If the id exists it's replaced, but only within the same container: an id can't move to another container. Writes are accepted at once and become searchable everywhere within seconds to about a minute; use `fresh: true` on search or fetch to read them immediately.",
        "x-auth": "api_key_or_token",
        "x-scopes": [
          "vector:write"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VectorRecord"
              },
              "example": {
                "id": "4021",
                "vector": [
                  0.12,
                  -0.04,
                  0.33
                ],
                "metadata": {
                  "container_id": "container:handbook",
                  "text": "Employees get 25 days of paid leave."
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for writing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "example": {
                  "status": "accepted"
                }
              }
            }
          },
          "400": {
            "description": "Invalid id, vector or metadata; with a user token, metadata.container_id is missing; or a vector whose length differs from the index's (code dimension_mismatch).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "dimension_mismatch"
            ]
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing vector:write scope; the user can't edit the container; or the id already belongs to another container (code container_limit_exceeded when the user reaches over 1,000 containers).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "container_limit_exceeded"
            ]
          },
          "413": {
            "description": "Metadata over 8 KB, or the index is full (code index_full).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "index_full"
            ]
          },
          "503": {
            "description": "Temporary: the write backlog is full, the index is catching up with recent writes (code index_busy), or the index is being migrated (code migrating) or is frozen (code store_frozen). Retry after the Retry-After header.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "migrating",
              "store_frozen",
              "store_moved",
              "index_busy"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/insert \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"id\": \"4021\", \"vector\": [0.12, -0.04, 0.33], \"metadata\": {\"container_id\": \"container:handbook\", \"text\": \"Employees get 25 days of paid leave.\"}}'"
      }
    },
    "/v1/upsert-batch": {
      "post": {
        "operationId": "upsertBatch",
        "tags": [
          "Vectors"
        ],
        "summary": "Insert or update up to 500 vectors",
        "description": "Like insert, for up to 500 records at once. The batch is checked as a whole before anything is written: if any record is rejected, none are, and the error names the record (`index`). Also served at `/upsert-batch` for older clients. The SDKs' insertMany / insert_many use it.",
        "x-auth": "api_key_or_token",
        "x-scopes": [
          "vector:write"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "vectors"
                ],
                "properties": {
                  "vectors": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 500,
                    "items": {
                      "$ref": "#/components/schemas/VectorRecord"
                    }
                  }
                }
              },
              "example": {
                "vectors": [
                  {
                    "id": "4021",
                    "vector": [
                      0.12,
                      -0.04,
                      0.33
                    ],
                    "metadata": {
                      "container_id": "container:handbook"
                    }
                  },
                  {
                    "id": "4022",
                    "vector": [
                      0.12,
                      -0.04,
                      0.33
                    ],
                    "metadata": {
                      "container_id": "container:handbook"
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for writing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchAccepted"
                },
                "example": {
                  "success": true,
                  "inserted": 2
                }
              }
            }
          },
          "400": {
            "description": "A record is invalid; the response's `index` says which; or a vector whose length differs from the index's (code dimension_mismatch).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "dimension_mismatch"
            ]
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Same rules as insert, for any record in the batch.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "container_limit_exceeded"
            ]
          },
          "413": {
            "description": "More than 500 records, metadata over 8 KB, or the index is full (code index_full).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "index_full"
            ]
          },
          "503": {
            "description": "Temporary: the write backlog is full, the index is catching up with recent writes (code index_busy), or the index is being migrated (code migrating) or is frozen (code store_frozen). Retry after the Retry-After header.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "migrating",
              "store_frozen",
              "store_moved",
              "index_busy"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/upsert-batch \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"vectors\": [{\"id\": \"4021\", \"vector\": [0.12, -0.04, 0.33], \"metadata\": {\"container_id\": \"container:handbook\"}}]}'"
      }
    },
    "/v1/import": {
      "post": {
        "operationId": "importRecords",
        "tags": [
          "Vectors"
        ],
        "summary": "Bulk import up to 2,000 records per request",
        "description": "For loading large datasets: up to 2,000 records per request in a compact binary chunk, with the same checks and ownership rules as upsert-batch (if any record is rejected, none are). Imported records become searchable once merged, usually within a minute; they are not visible to `fresh` searches before that. Backend API keys only (not user tokens). Each record counts as one write.\n\nBody (`application/octet-stream`, little-endian): the 4 bytes `EVI1`, u32 dimension, u32 record count, then for each record: u32 id, the vector as f32 × dimension, u32 metadata length n, and n bytes of metadata as a UTF-8 JSON object (n = 0: no metadata). At most 16 MB. `scripts/bulk-load.ts` in the repository shows how to build chunks.",
        "x-auth": "api_key",
        "x-scopes": [
          "vector:write"
        ],
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/import \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/octet-stream\" \\\n  --data-binary @chunk-0001.evi",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted: the chunk will be merged",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "accepted"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "accepted": {
                      "type": "integer"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "accepted": 2000
                }
              }
            }
          },
          "400": {
            "description": "Not a valid chunk (code invalid_import), a record is invalid (the response's `index` says which), or a vector whose length differs from the index's (code dimension_mismatch).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "invalid_import",
              "dimension_mismatch"
            ]
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "403": {
            "description": "Missing vector:write scope, a user token (bulk import needs a backend API key), or a record id that already exists in a different container."
          },
          "413": {
            "description": "More than 500 records, metadata over 8 KB, or the index is full (code index_full).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "index_full"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Temporary: the write backlog is full, the index is catching up with recent writes (code index_busy), or the index is being migrated (code migrating) or is frozen (code store_frozen). Retry after the Retry-After header.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "migrating",
              "store_frozen",
              "store_moved",
              "index_busy"
            ]
          },
          "409": {
            "description": "`bulk_needs_new_index`: ?bulk on an index that already has records; `bulk_build_in_progress`: a bulk build is running for this index (other writes wait for it)."
          }
        },
        "parameters": [
          {
            "name": "bulk",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,64}$"
            },
            "description": "First load of a new index: stage this chunk under a bulk session instead of merging it. When every chunk is uploaded, POST /v1/import/commit builds the whole index in one pass (much faster for large loads). Only for an index with no records yet (409 `bulk_needs_new_index` otherwise)."
          }
        ]
      }
    },
    "/v1/delete": {
      "post": {
        "operationId": "delete",
        "tags": [
          "Vectors"
        ],
        "summary": "Delete a vector",
        "description": "Deletes one record by id. With a user token, pass the record's container in `metadata.container_id`; the user needs editor access to it.",
        "x-auth": "api_key_or_token",
        "x-scopes": [
          "vector:write"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteRequest"
              },
              "example": {
                "id": "4021",
                "metadata": {
                  "container_id": "container:handbook"
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "example": {
                  "status": "accepted"
                }
              }
            }
          },
          "400": {
            "description": "Invalid id; with a user token, metadata.container_id is missing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing vector:write scope, the record is in another container, or the user can't edit its container.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "container_limit_exceeded"
            ]
          },
          "404": {
            "description": "With a user token: no such document.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The document's owner changed while the request ran (it was deleted or claimed by another container). Retry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "conflict"
            ]
          },
          "503": {
            "description": "Temporary: the write backlog is full, or the index is being migrated (code migrating) or is frozen (code store_frozen). Retry after the Retry-After header.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "migrating",
              "store_frozen",
              "store_moved"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/delete \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"id\": \"4021\", \"metadata\": {\"container_id\": \"container:handbook\"}}'"
      }
    },
    "/v1/search": {
      "post": {
        "operationId": "search",
        "tags": [
          "Vectors"
        ],
        "summary": "Search by vector, keyword or both",
        "description": "Returns the best-matching records. `mode` picks how they're matched:\n\n- `vector` (default): the closest vectors to `query`.\n- `keyword`: records whose metadata `text` contains the words in `text` (BM25 ranking; accents and case ignored, common English and Portuguese words dropped). No embedding needed.\n- `hybrid`: both, fused with Reciprocal Rank Fusion; `keyword_weight` sets the balance.\n\nWith a user token (or `auth_user_id`), only records in containers that user can view are considered, in every mode: access control is applied inside the search, not by filtering results afterwards. Keyword and hybrid results carry `score` and `match`; vector results are unchanged. Keyword matching covers records once they're merged (seconds); `fresh: true` also matches writes that aren't merged yet. Counts as one read.",
        "x-auth": "api_key_or_token",
        "x-scopes": [
          "vector:read"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              },
              "example": {
                "query": [
                  0.12,
                  -0.04,
                  0.33
                ],
                "top_k": 5,
                "filter": {
                  "category": "hr",
                  "updated_at": {
                    "$gte": 1789000000
                  }
                },
                "fresh": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Closest records first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SearchResult"
                  }
                },
                "example": [
                  {
                    "id": "4021",
                    "distance": 0.084,
                    "metadata": {
                      "container_id": "container:handbook",
                      "text": "Employees get 25 days of paid leave."
                    }
                  }
                ]
              }
            }
          },
          "400": {
            "description": "Invalid query vector, a dimension mismatch with the index, an invalid filter (code invalid_filter), or an invalid `mode`, `text` (missing, or over 2,000 characters) or `keyword_weight`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "invalid_filter"
            ]
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "403": {
            "description": "Missing vector:read scope, auth_user_id without vector:impersonate, or the user reaches over 1,000 containers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "container_limit_exceeded"
            ]
          },
          "404": {
            "description": "The index has no data yet (plain text)."
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Keyword search is briefly unavailable (keyword mode only; hybrid falls back to vector results). Retry shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "507": {
            "description": "The index is too large to search at the edge (code index_too_large).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "index_too_large"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/search \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"query\": [0.12, -0.04, 0.33], \"top_k\": 5}'\n\n# Hybrid: vector + keywords\ncurl -X POST https://api.swarmv.dev/v1/search \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"mode\": \"hybrid\", \"query\": [0.12, -0.04, 0.33], \"text\": \"refund policy\", \"top_k\": 5}'\n\n# Keyword only: no embedding needed\ncurl -X POST https://api.swarmv.dev/v1/search \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"mode\": \"keyword\", \"text\": \"ERR_4021\", \"top_k\": 5}'"
      }
    },
    "/v1/fetch": {
      "post": {
        "operationId": "fetch",
        "tags": [
          "Vectors"
        ],
        "summary": "Get records by id",
        "description": "Returns up to 100 records by id, with their metadata and optionally their vectors. Same visibility as search: records the caller can't see are listed as missing, never as forbidden, so ids in other containers can't be probed. Includes writes that aren't merged yet. Counts as one read.",
        "x-auth": "api_key_or_token",
        "x-scopes": [
          "vector:read"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FetchRequest"
              },
              "example": {
                "ids": [
                  "4021",
                  "4022"
                ],
                "include_vector": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FetchResponse"
                },
                "example": {
                  "records": [
                    {
                      "id": "4021",
                      "metadata": {
                        "container_id": "container:handbook",
                        "text": "Employees get 25 days of paid leave."
                      }
                    }
                  ],
                  "missing": [
                    "4022"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "ids missing, empty or not 32-bit integers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing vector:read scope, auth_user_id without vector:impersonate, or the user reaches over 1,000 containers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "container_limit_exceeded"
            ]
          },
          "413": {
            "description": "More than 100 ids.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/fetch \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"ids\": [\"4021\", \"4022\"]}'"
      }
    },
    "/v1/auth/token": {
      "post": {
        "operationId": "createUserToken",
        "tags": [
          "Auth"
        ],
        "summary": "Create a user token",
        "description": "Creates a short-lived token (at most 1 hour) that acts as one user: it can only search, fetch and write within the containers that user can access. Call it from your backend with an API key, and give the token, not the key, to agents, MCP servers and browsers. Tokens can't create tokens.",
        "x-auth": "api_key",
        "x-scopes": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TokenRequest"
              },
              "example": {
                "user_id": "user:dave",
                "expires_in": 900,
                "scopes": [
                  "vector:read"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                },
                "example": {
                  "token": "eyJhbGciOiJIUzI1NiIs..."
                }
              }
            }
          },
          "400": {
            "description": "user_id isn't a user: id, or expires_in isn't a positive integer (plain text)."
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Called with a token, or asked for a scope the key doesn't have or that tokens can't hold (plain text)."
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/auth/token \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"user_id\": \"user:dave\", \"expires_in\": 900}'"
      }
    },
    "/v1/graph/edges": {
      "get": {
        "operationId": "listRelationships",
        "tags": [
          "Access graph"
        ],
        "summary": "List relationships",
        "description": "Pages through your account's relationships, optionally filtered.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:read"
        ],
        "parameters": [
          {
            "name": "subject",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only this subject."
          },
          {
            "name": "object",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only this object."
          },
          {
            "name": "relation",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "member",
                "viewer",
                "editor",
                "parent"
              ]
            },
            "description": "Only this relation."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Text search: part of a subject, relation or object."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "description": "Page size."
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "description": "Rows to skip."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RelationshipPage"
                },
                "example": {
                  "edges": [
                    {
                      "subject": "user:dave",
                      "relation": "member",
                      "object": "group:engineering"
                    }
                  ],
                  "total": 1,
                  "limit": 50,
                  "offset": 0
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:read (or graph:admin) scope, or called with a user token (plain text)."
          }
        },
        "x-curl": "curl -X GET https://api.swarmv.dev/v1/graph/edges?object=group:engineering \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\""
      }
    },
    "/v1/graph/edge": {
      "post": {
        "operationId": "addRelationship",
        "tags": [
          "Access graph"
        ],
        "summary": "Add a relationship",
        "description": "Adds one relationship, e.g. a user joining a group or a group becoming viewer of a folder. Permissions at the edge update within seconds. Re-sending an existing relationship is harmless and refreshes the affected permissions.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:admin"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Relationship"
              },
              "example": {
                "subject": "user:dave",
                "relation": "member",
                "object": "group:engineering"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RelationshipChange"
                },
                "example": {
                  "success": true,
                  "changed": true
                }
              }
            }
          },
          "400": {
            "description": "Missing fields, an unknown relation, or a node without a valid prefix (plain text)."
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:admin scope, or the plan's relationship limit is reached (code relationship_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "relationship_limit"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/graph/edge \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"subject\": \"user:dave\", \"relation\": \"member\", \"object\": \"group:engineering\"}'"
      },
      "delete": {
        "operationId": "removeRelationship",
        "tags": [
          "Access graph"
        ],
        "summary": "Remove a relationship",
        "description": "Removes one relationship. Access that depended on it ends everywhere within seconds.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:admin"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Relationship"
              },
              "example": {
                "subject": "user:dave",
                "relation": "member",
                "object": "group:engineering"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RelationshipChange"
                },
                "example": {
                  "success": true,
                  "changed": true
                }
              }
            }
          },
          "400": {
            "description": "Missing fields, an unknown relation, or a node without a valid prefix (plain text)."
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:admin scope (plain text)."
          }
        },
        "x-curl": "curl -X DELETE https://api.swarmv.dev/v1/graph/edge \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"subject\": \"user:dave\", \"relation\": \"member\", \"object\": \"group:engineering\"}'"
      }
    },
    "/v1/graph/check": {
      "post": {
        "operationId": "checkAccess",
        "tags": [
          "Access graph"
        ],
        "summary": "Check and explain access",
        "description": "Answers whether a subject can view (or edit) an object, and through which chain of relations. Reads the graph directly, so it reflects changes immediately.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:read"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessCheckRequest"
              },
              "example": {
                "subject": "user:dave",
                "object": "container:apollo",
                "relation": "viewer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccessCheck"
                },
                "example": {
                  "allowed": true,
                  "granted": "viewer",
                  "path": [
                    {
                      "node": "user:dave"
                    },
                    {
                      "node": "group:engineering",
                      "relation": "member"
                    },
                    {
                      "node": "folder:handbook",
                      "relation": "viewer"
                    },
                    {
                      "node": "container:apollo",
                      "relation": "parent"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid subject, object or relation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:read (or graph:admin) scope (plain text)."
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/graph/check \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"subject\": \"user:dave\", \"object\": \"container:apollo\"}'"
      }
    },
    "/v1/graph/edges/batch": {
      "post": {
        "operationId": "batchRelationships",
        "tags": [
          "Access graph"
        ],
        "summary": "Change many relationships at once",
        "description": "Adds and removes up to 500 relationships in one all-or-nothing step. Pro and Enterprise.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:admin"
        ],
        "x-plans": [
          "pro",
          "enterprise"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Retrying with the same key within 24 hours returns the first result instead of applying the change again."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RelationshipBatchRequest"
              },
              "example": {
                "operations": [
                  {
                    "op": "add",
                    "subject": "user:ana",
                    "relation": "member",
                    "object": "group:engineering"
                  },
                  {
                    "op": "remove",
                    "subject": "user:bob",
                    "relation": "member",
                    "object": "group:engineering"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RelationshipBatchResult"
                },
                "example": {
                  "success": true,
                  "dry_run": false,
                  "added": 1,
                  "removed": 1,
                  "unchanged": 0
                }
              }
            }
          },
          "400": {
            "description": "Invalid operations; `index` names the first bad one.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:admin scope, the Basic plan (code plan_feature), or the relationship limit (code relationship_limit). Nothing was changed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_feature",
              "relationship_limit"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/graph/edges/batch \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"operations\": [{\"op\": \"add\", \"subject\": \"user:ana\", \"relation\": \"member\", \"object\": \"group:engineering\"}]}'"
      }
    },
    "/v1/graph/sync": {
      "post": {
        "operationId": "syncRelationships",
        "tags": [
          "Access graph"
        ],
        "summary": "Make an object's members exactly a list",
        "description": "Sets who has one relation to one object, e.g. the full member list of a group from your directory: missing subjects are added, others removed. Safe to re-run. Pro and Enterprise.",
        "x-auth": "api_key",
        "x-scopes": [
          "graph:admin"
        ],
        "x-plans": [
          "pro",
          "enterprise"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Retrying with the same key within 24 hours returns the first result instead of applying the change again."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SyncRequest"
              },
              "example": {
                "object": "group:engineering",
                "relation": "member",
                "subjects": [
                  "user:ana",
                  "user:dave"
                ],
                "dry_run": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncResult"
                },
                "example": {
                  "success": true,
                  "dry_run": true,
                  "current": 2,
                  "would_add": 1,
                  "would_remove": 1
                }
              }
            }
          },
          "400": {
            "description": "Invalid object, relation or subjects.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "403": {
            "description": "Missing graph:admin scope, the Basic plan (code plan_feature), or the relationship limit (code relationship_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_feature",
              "relationship_limit"
            ]
          },
          "409": {
            "description": "The sync would remove more than 20% of the current subjects; resend with allow_large_removal: true (code large_removal).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "large_removal"
            ]
          }
        },
        "x-curl": "curl -X POST https://api.swarmv.dev/v1/graph/sync \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"object\": \"group:engineering\", \"relation\": \"member\", \"subjects\": [\"user:ana\", \"user:dave\"], \"dry_run\": true}'"
      }
    },
    "/v1/health": {
      "get": {
        "operationId": "health",
        "tags": [
          "Service"
        ],
        "summary": "Service health",
        "description": "Public, no key needed. The same data, for people, is at https://swarmv.dev/status. Checks each storage dependency and reports the last synthetic check, which writes a record and reads it back every 5 minutes. 200 when everything is fine, 503 otherwise. Rate-limited per IP; results are cached for 10 seconds.",
        "security": [],
        "x-auth": "none",
        "x-scopes": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "ok",
                  "checks": {
                    "kv": {
                      "ok": true,
                      "ms": 4
                    },
                    "r2": {
                      "ok": true,
                      "ms": 21
                    },
                    "d1": {
                      "ok": true,
                      "ms": 9
                    },
                    "catalog": {
                      "ok": true,
                      "ms": 6
                    }
                  },
                  "synthetic": {
                    "ok": true,
                    "at": 1792104837716,
                    "write_ms": 41,
                    "search_ms": 33
                  },
                  "time": "2026-10-15T22:54:06.906Z"
                }
              }
            }
          },
          "503": {
            "description": "Something is failing; the body names it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "x-curl": "curl https://api.swarmv.dev/v1/health"
      }
    },
    "/v1/records": {
      "get": {
        "operationId": "listRecords",
        "tags": [
          "Vectors"
        ],
        "summary": "List records",
        "description": "Pages through the index's records in id order (merged records: writes from the last few seconds may not be listed yet; deleted records are not listed). Backend API keys only, since the list isn't limited to a user's containers. Indexes created before October 2026 answer 404 (code not_clustered).",
        "x-auth": "api_key",
        "x-scopes": [
          "vector:read"
        ],
        "x-curl": "curl \"https://api.swarmv.dev/v1/records?limit=100\" \\\n  -H \"Authorization: Bearer $SWARMV_API_KEY\"",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/DocumentId"
            },
            "description": "List ids after this one (the previous page's `next`)."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "description": "Page size."
          },
          {
            "name": "container",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only records in this container."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordPage"
                },
                "example": {
                  "records": [
                    {
                      "id": "4021",
                      "container": "container:handbook"
                    },
                    {
                      "id": "4022",
                      "container": null
                    }
                  ],
                  "next": "4022"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired, rotated or revoked key or token (plain text body)."
          },
          "402": {
            "description": "No active plan (code plan_required), or the Basic plan's monthly reads or writes are used up (code plan_limit).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "plan_required",
              "plan_limit"
            ]
          },
          "403": {
            "description": "A user token, or a key without vector:read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The index uses the older format (code not_clustered).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "x-codes": [
              "not_clustered"
            ]
          },
          "429": {
            "description": "Too many requests for this key (6,000 per minute; plain text). Retry-After says how many seconds until the window resets.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/import/commit": {
      "post": {
        "operationId": "commitBulkImport",
        "tags": [
          "Vectors"
        ],
        "summary": "Build a new index from a bulk import session",
        "description": "Starts building the index from every chunk uploaded with `/v1/import?bulk=<session>`, in one pass: lists are trained for the whole load and written once, so large loads are searchable much sooner than through merges. Records with the same id keep their newest copy. The build runs in the background; poll `GET /v1/import/status`. Other writes to the index wait (409 `bulk_build_in_progress`) until it is done. Backend API keys only.",
        "x-auth": "api_key",
        "x-scopes": [
          "vector:write"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "session"
                ],
                "properties": {
                  "session": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{1,64}$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Build started",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "building"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid session, or no chunks uploaded for it (`bulk_empty`)"
          },
          "409": {
            "description": "`bulk_needs_new_index` or `bulk_build_in_progress`"
          }
        }
      }
    },
    "/v1/import/status": {
      "get": {
        "operationId": "bulkImportStatus",
        "tags": [
          "Vectors"
        ],
        "summary": "Progress of a bulk import build",
        "description": "State of the build started by `/v1/import/commit`: `building` (with `step` once records are searchable and keyword text is being indexed), `done` (with `records`), or `failed` (with `error`; commit the session again, or start a new one).",
        "x-auth": "api_key",
        "x-scopes": [
          "vector:write"
        ],
        "parameters": [
          {
            "name": "session",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Build state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "building",
                        "done",
                        "failed"
                      ]
                    },
                    "step": {
                      "type": "string"
                    },
                    "records": {
                      "type": "integer"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No build for this session"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API key (backend) or a user token (agents, clients)."
      }
    },
    "schemas": {
      "Metadata": {
        "type": "object",
        "description": "Flat key/value pairs (string, number or boolean), at most 8 KB in total, without the bytes \\x00-\\x02. Values come back as strings. `container_id` decides who can see the record.",
        "additionalProperties": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            }
          ]
        },
        "example": {
          "container_id": "container:handbook",
          "text": "Employees get 25 days of paid leave."
        }
      },
      "VectorRecord": {
        "type": "object",
        "required": [
          "id",
          "vector"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/DocumentId"
          },
          "vector": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 1,
            "description": "Finite numbers. Every vector in an index has the same length (set by the first insert)."
          },
          "metadata": {
            "$ref": "#/components/schemas/Metadata"
          },
          "auth_user_id": {
            "type": "string",
            "pattern": "^user:.+",
            "example": "user:dave",
            "description": "Write as this user (needs vector:impersonate). User tokens always write as their own user."
          }
        }
      },
      "DocumentId": {
        "type": "string",
        "pattern": "^[0-9]{1,10}$",
        "description": "Document id: an unsigned 32-bit integer (0 to 4294967295), sent as a string. \"007\" and \"7\" are the same document.",
        "example": "4021"
      },
      "Accepted": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted"
            ]
          }
        }
      },
      "BatchAccepted": {
        "type": "object",
        "required": [
          "success",
          "inserted"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "inserted": {
            "type": "integer"
          }
        }
      },
      "SearchRequest": {
        "type": "object",
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "vector",
              "keyword",
              "hybrid"
            ],
            "default": "vector",
            "description": "How records are matched. Sending `text` alone doesn't change the mode."
          },
          "text": {
            "type": "string",
            "maxLength": 2000,
            "example": "refund policy ERR_4021",
            "description": "The query as words. Required for `keyword` and `hybrid` modes. Matched against each record's metadata `text`."
          },
          "query": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 1,
            "description": "Query vector, same length as the index's vectors. Required for `vector` and `hybrid` modes."
          },
          "top_k": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 10
          },
          "nprobe": {
            "type": "integer",
            "minimum": 1,
            "maximum": 64,
            "default": 16,
            "description": "How many clusters to search in compressed indexes: higher is more accurate and slower. The SDKs send 4."
          },
          "filter": {
            "type": "object",
            "description": "Metadata conditions, all of which must hold. A plain value means equals; operators: `$eq`, `$ne`, `$in`, `$nin` (up to 100 values), `$gt`, `$gte`, `$lt`, `$lte`, `$exists`. `$or` takes up to 8 filters (other fields apply to every branch). Numbers compare numerically, text byte-wise (ISO-8601 dates sort correctly). `$ne` and `$nin` also match records without the field. Only values up to 128 bytes can be filtered.",
            "additionalProperties": true,
            "example": {
              "lang": "pt",
              "created_at": {
                "$gte": 1789000000
              },
              "status": {
                "$in": [
                  "published",
                  "review"
                ]
              }
            }
          },
          "include_metadata": {
            "type": "boolean",
            "default": true
          },
          "fresh": {
            "type": "boolean",
            "default": false,
            "description": "Also return writes that aren't in the edge index yet (read-your-own-writes), at a little extra latency."
          },
          "auth_user_id": {
            "type": "string",
            "pattern": "^user:.+",
            "example": "user:dave",
            "description": "Search as this user (needs vector:impersonate). User tokens always search as their own user."
          },
          "keyword_weight": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 0.5,
            "description": "Hybrid mode: how much keyword matches count against vector matches (0 = vector only, 1 = keyword only)."
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "distance": {
            "type": "number",
            "description": "Squared L2 distance between normalized vectors: lower is closer. Cosine similarity = 1 - distance / 2. Present for vector matches (always in vector mode)."
          },
          "score": {
            "type": "number",
            "description": "Keyword and hybrid modes: fused rank score (Reciprocal Rank Fusion), higher is better. Compare within one response only."
          },
          "match": {
            "type": "string",
            "enum": [
              "vector",
              "keyword",
              "both"
            ],
            "description": "Keyword and hybrid modes: which part of the search found this record."
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "FetchRequest": {
        "type": "object",
        "required": [
          "ids"
        ],
        "properties": {
          "ids": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentId"
            },
            "minItems": 1,
            "maxItems": 100
          },
          "include_metadata": {
            "type": "boolean",
            "default": true
          },
          "include_vector": {
            "type": "boolean",
            "default": false
          },
          "auth_user_id": {
            "type": "string",
            "pattern": "^user:.+",
            "example": "user:dave",
            "description": "Fetch as this user (needs vector:impersonate). User tokens always fetch as their own user."
          }
        }
      },
      "FetchedRecord": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "vector": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "description": "As stored: normalized for cosine indexes."
          },
          "vector_precision": {
            "type": "string",
            "enum": [
              "full",
              "approximate"
            ],
            "description": "\"approximate\": an 8-bit copy, from compressed segments of large indexes."
          }
        }
      },
      "FetchResponse": {
        "type": "object",
        "required": [
          "records",
          "missing"
        ],
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FetchedRecord"
            }
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Ids that don't exist, were deleted, or that the caller can't see."
          },
          "unavailable": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Ids that exist but couldn't be read right now (e.g. during a merge). Retry after the Retry-After header."
          }
        }
      },
      "DeleteRequest": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/DocumentId"
          },
          "metadata": {
            "type": "object",
            "properties": {
              "container_id": {
                "type": "string"
              }
            },
            "description": "The document's container. Required with user tokens (the user needs editor access to it)."
          },
          "auth_user_id": {
            "type": "string",
            "pattern": "^user:.+",
            "example": "user:dave",
            "description": "Delete as this user (needs vector:impersonate)."
          }
        }
      },
      "TokenRequest": {
        "type": "object",
        "required": [
          "user_id"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "pattern": "^user:.+",
            "example": "user:dave"
          },
          "expires_in": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3600,
            "default": 3600,
            "description": "Lifetime in seconds; longer values are capped at 3600."
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "vector:read",
                "vector:write"
              ]
            },
            "description": "A subset of the key's scopes. Defaults to the key's vector scopes. graph:*, vector:impersonate and keys:admin are never allowed in tokens."
          }
        }
      },
      "TokenResponse": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string",
            "description": "A JWT. Give it to the agent or client; it can only act as this user."
          }
        }
      },
      "Relationship": {
        "type": "object",
        "required": [
          "subject",
          "relation",
          "object"
        ],
        "properties": {
          "subject": {
            "type": "string",
            "maxLength": 256,
            "description": "A node with a type prefix: user:, group:, folder: or container:.",
            "example": "group:engineering"
          },
          "relation": {
            "type": "string",
            "enum": [
              "member",
              "viewer",
              "editor",
              "parent"
            ]
          },
          "object": {
            "type": "string",
            "maxLength": 256,
            "description": "A node with a type prefix: user:, group:, folder: or container:.",
            "example": "container:apollo"
          }
        }
      },
      "RelationshipPage": {
        "type": "object",
        "required": [
          "edges",
          "total",
          "limit",
          "offset"
        ],
        "properties": {
          "edges": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Relationship"
            }
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          }
        }
      },
      "RelationshipChange": {
        "type": "object",
        "required": [
          "success",
          "changed"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "changed": {
            "type": "boolean",
            "description": "false when the relationship already existed (add) or didn't exist (remove)."
          }
        }
      },
      "AccessCheckRequest": {
        "type": "object",
        "required": [
          "subject",
          "object"
        ],
        "properties": {
          "subject": {
            "type": "string",
            "maxLength": 256,
            "description": "A node with a type prefix: user:, group:, folder: or container:.",
            "example": "user:dave"
          },
          "object": {
            "type": "string",
            "maxLength": 256,
            "description": "A node with a type prefix: user:, group:, folder: or container:.",
            "example": "container:apollo"
          },
          "relation": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ],
            "default": "viewer"
          }
        }
      },
      "AccessCheck": {
        "type": "object",
        "required": [
          "allowed",
          "path"
        ],
        "properties": {
          "allowed": {
            "type": "boolean"
          },
          "granted": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "path": {
            "type": "array",
            "description": "The chain of relations that grants access, from the subject to the object.",
            "items": {
              "type": "object",
              "required": [
                "node"
              ],
              "properties": {
                "node": {
                  "type": "string"
                },
                "relation": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "RelationshipBatchRequest": {
        "type": "object",
        "required": [
          "operations"
        ],
        "properties": {
          "operations": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Relationship"
                },
                {
                  "type": "object",
                  "required": [
                    "op"
                  ],
                  "properties": {
                    "op": {
                      "type": "string",
                      "enum": [
                        "add",
                        "remove"
                      ]
                    }
                  }
                }
              ]
            }
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "RelationshipBatchResult": {
        "type": "object",
        "required": [
          "success",
          "dry_run",
          "added",
          "removed",
          "unchanged"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "dry_run": {
            "type": "boolean"
          },
          "added": {
            "type": "integer"
          },
          "removed": {
            "type": "integer"
          },
          "unchanged": {
            "type": "integer"
          }
        }
      },
      "SyncRequest": {
        "type": "object",
        "required": [
          "object",
          "relation",
          "subjects"
        ],
        "properties": {
          "object": {
            "type": "string",
            "maxLength": 256,
            "description": "A node with a type prefix: user:, group:, folder: or container:.",
            "example": "group:engineering"
          },
          "relation": {
            "type": "string",
            "enum": [
              "member",
              "viewer",
              "editor",
              "parent"
            ]
          },
          "subjects": {
            "type": "array",
            "maxItems": 10000,
            "items": {
              "type": "string",
              "maxLength": 256,
              "description": "A node with a type prefix: user:, group:, folder: or container:.",
              "example": "group:engineering"
            },
            "description": "The complete list: subjects not in it lose this relation."
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "allow_large_removal": {
            "type": "boolean",
            "default": false,
            "description": "Required when a sync would remove more than 20% of 10 or more current subjects."
          }
        }
      },
      "SyncResult": {
        "type": "object",
        "required": [
          "success",
          "dry_run",
          "current"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "dry_run": {
            "type": "boolean"
          },
          "current": {
            "type": "integer"
          },
          "added": {
            "type": "integer"
          },
          "removed": {
            "type": "integer"
          },
          "would_add": {
            "type": "integer"
          },
          "would_remove": {
            "type": "integer"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status",
          "checks",
          "synthetic",
          "time"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "down"
            ]
          },
          "checks": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "ok",
                "ms"
              ],
              "properties": {
                "ok": {
                  "type": "boolean"
                },
                "ms": {
                  "type": "number"
                },
                "error": {
                  "type": "string"
                }
              }
            }
          },
          "synthetic": {
            "type": "object",
            "description": "The last write-and-read-back check (every 5 minutes).",
            "properties": {
              "ok": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "at": {
                "type": "number"
              },
              "write_ms": {
                "type": "number"
              },
              "search_ms": {
                "type": "number"
              },
              "error": {
                "type": "string"
              },
              "note": {
                "type": "string"
              }
            }
          },
          "time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "description": "Machine-readable reason, when there is one (see the error table)."
          },
          "index": {
            "type": "integer",
            "description": "For batches: which record (position in `vectors`) was rejected."
          },
          "expected": {
            "type": "integer",
            "description": "With dimension_mismatch: the vector length the index uses."
          },
          "limit": {
            "type": [
              "integer",
              "string",
              "null"
            ],
            "description": "With limit errors: the limit that was reached."
          }
        }
      },
      "RecordPage": {
        "type": "object",
        "required": [
          "records",
          "next"
        ],
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "container"
              ],
              "properties": {
                "id": {
                  "$ref": "#/components/schemas/DocumentId"
                },
                "container": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "The record's container_id, if it has one."
                }
              }
            }
          },
          "next": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pass as `after` for the next page; null when there are no more records. A page can be short (or empty) with a container filter: keep following `next`."
          }
        }
      }
    }
  }
}