{
  "openapi": "3.1.0",
  "info": {
    "title": "pumaDB REST API",
    "version": "0.1.0",
    "description": "Agent memory API for server-side apps and agents. API keys are full-account bearer secrets and must be kept out of frontend bundles, static sites, mobile apps, public repos, and browser-executed code."
  },
  "externalDocs": {
    "description": "LLM-ready service instructions in Markdown",
    "url": "https://api.pumadb.ai/llms.md"
  },
  "servers": [
    {
      "url": "https://api.pumadb.ai"
    }
  ],
  "tags": [
    {
      "name": "Auth"
    },
    {
      "name": "Rows"
    },
    {
      "name": "Tables"
    },
    {
      "name": "Keys"
    }
  ],
  "paths": {
    "/auth/magic-link": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Request a magic link",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MagicLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Magic link requested.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MagicLinkResponse"
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/auth/verify": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Exchange magic-link token for API key",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyMagicLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "API key created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifyMagicLinkResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "get": {
        "tags": [
          "Rows"
        ],
        "summary": "Query rows",
        "parameters": [
          {
            "name": "filter",
            "in": "query",
            "required": false,
            "description": "JSON equality filter.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "description": "Sort field. Prefix with '-' for descending.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rows returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "rows"
                  ],
                  "properties": {
                    "rows": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "additionalProperties": true
                          },
                          {
                            "type": "object",
                            "required": [
                              "id",
                              "created_at",
                              "updated_at"
                            ],
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time"
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Add row",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Row returned.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "type": "object",
                      "additionalProperties": true
                    },
                    {
                      "type": "object",
                      "required": [
                        "id",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Rows"
        ],
        "summary": "Delete rows matching filter",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filter"
                ],
                "properties": {
                  "filter": {
                    "type": "object",
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rows deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "deleted"
                  ],
                  "properties": {
                    "deleted": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/upsert": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Insert or update by natural key",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key",
                  "row"
                ],
                "properties": {
                  "key": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  },
                  "row": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upsert result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "created",
                    "row"
                  ],
                  "properties": {
                    "created": {
                      "type": "boolean"
                    },
                    "row": {
                      "allOf": [
                        {
                          "type": "object",
                          "additionalProperties": true
                        },
                        {
                          "type": "object",
                          "required": [
                            "id",
                            "created_at",
                            "updated_at"
                          ],
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "created_at": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "updated_at": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/batch": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Run atomic same-table write operations",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "operations"
                ],
                "properties": {
                  "operations": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "required": [
                            "action",
                            "row"
                          ],
                          "properties": {
                            "action": {
                              "type": "string",
                              "enum": [
                                "add"
                              ]
                            },
                            "row": {
                              "type": "object",
                              "additionalProperties": true
                            },
                            "idempotencyKey": {
                              "type": "string"
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "action",
                            "key",
                            "row"
                          ],
                          "properties": {
                            "action": {
                              "type": "string",
                              "enum": [
                                "upsert"
                              ]
                            },
                            "key": {
                              "oneOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "array",
                                  "minItems": 1,
                                  "items": {
                                    "type": "string"
                                  }
                                }
                              ]
                            },
                            "row": {
                              "type": "object",
                              "additionalProperties": true
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "action",
                            "id",
                            "patch"
                          ],
                          "properties": {
                            "action": {
                              "type": "string",
                              "enum": [
                                "update_row"
                              ]
                            },
                            "id": {
                              "type": "string"
                            },
                            "patch": {
                              "type": "object",
                              "additionalProperties": true
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "action",
                            "filter",
                            "patch"
                          ],
                          "properties": {
                            "action": {
                              "type": "string",
                              "enum": [
                                "update_where"
                              ]
                            },
                            "filter": {
                              "type": "object",
                              "additionalProperties": {
                                "oneOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "number"
                                  },
                                  {
                                    "type": "boolean"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            },
                            "patch": {
                              "type": "object",
                              "additionalProperties": true
                            },
                            "allowMultiple": {
                              "type": "boolean",
                              "default": false
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "action",
                            "filter"
                          ],
                          "properties": {
                            "action": {
                              "type": "string",
                              "enum": [
                                "delete"
                              ]
                            },
                            "filter": {
                              "type": "object",
                              "additionalProperties": {
                                "oneOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "number"
                                  },
                                  {
                                    "type": "boolean"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch completed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "results"
                  ],
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "action",
                          "result"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "action": {
                            "type": "string",
                            "enum": [
                              "add",
                              "upsert",
                              "update_row",
                              "update_where",
                              "delete"
                            ]
                          },
                          "result": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/update_row": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Update one row by id",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "patch"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "patch": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wrapped row returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "row"
                  ],
                  "properties": {
                    "row": {
                      "allOf": [
                        {
                          "type": "object",
                          "additionalProperties": true
                        },
                        {
                          "type": "object",
                          "required": [
                            "id",
                            "created_at",
                            "updated_at"
                          ],
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "created_at": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "updated_at": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/update_where": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Update rows matching filter",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filter",
                  "patch"
                ],
                "properties": {
                  "filter": {
                    "type": "object",
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "patch": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "allowMultiple": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rows updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "updated",
                    "rows"
                  ],
                  "properties": {
                    "updated": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "rows": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "additionalProperties": true
                          },
                          {
                            "type": "object",
                            "required": [
                              "id",
                              "created_at",
                              "updated_at"
                            ],
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time"
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/count": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "get": {
        "tags": [
          "Rows"
        ],
        "summary": "Count rows",
        "parameters": [
          {
            "name": "filter",
            "in": "query",
            "required": false,
            "description": "JSON equality filter.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Count returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "count"
                  ],
                  "properties": {
                    "count": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/versions": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "get": {
        "tags": [
          "Rows"
        ],
        "summary": "List archived row versions",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Versions returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "versions"
                  ],
                  "properties": {
                    "versions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/RowVersion"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/{table}/restore": {
      "parameters": [
        {
          "name": "table",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          }
        }
      ],
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Restore archived row version",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "version"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wrapped row returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "row"
                  ],
                  "properties": {
                    "row": {
                      "allOf": [
                        {
                          "type": "object",
                          "additionalProperties": true
                        },
                        {
                          "type": "object",
                          "required": [
                            "id",
                            "created_at",
                            "updated_at"
                          ],
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "created_at": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "updated_at": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_tables": {
      "get": {
        "tags": [
          "Tables"
        ],
        "summary": "List tables",
        "responses": {
          "200": {
            "description": "Tables returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tables"
                  ],
                  "properties": {
                    "tables": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "name",
                          "rows"
                        ],
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "rows": {
                            "type": "integer",
                            "minimum": 0
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_export": {
      "get": {
        "tags": [
          "Tables"
        ],
        "summary": "Export all tables",
        "responses": {
          "200": {
            "description": "Tables exported.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tables"
                  ],
                  "properties": {
                    "tables": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "array",
                        "items": {
                          "allOf": [
                            {
                              "type": "object",
                              "additionalProperties": true
                            },
                            {
                              "type": "object",
                              "required": [
                                "id",
                                "created_at",
                                "updated_at"
                              ],
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "created_at": {
                                  "type": "string",
                                  "format": "date-time"
                                },
                                "updated_at": {
                                  "type": "string",
                                  "format": "date-time"
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_text_field_links": {
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Create text field viewer link",
        "description": "Create short-lived viewer/editor and raw download URLs for one string field from one stored row. Useful when Markdown, code, command, or config content should be inspected or manually edited outside the chat transcript.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTextFieldLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text field links created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateTextFieldLinkResponse"
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_row_links": {
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Create JSON row viewer link",
        "description": "Create short-lived viewer/editor and raw download URLs for one stored JSON row. Useful when large rows or long text fields should be inspected or manually edited outside the chat transcript.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRowLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Row links created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateRowLinkResponse"
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_query_links": {
      "post": {
        "tags": [
          "Rows"
        ],
        "summary": "Create query result viewer link",
        "description": "Create short-lived read-only viewer and raw download URLs for one table query result. Useful when several rows should be inspected outside the chat transcript through one link.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateQueryLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Query links created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateQueryLinkResponse"
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_keys": {
      "get": {
        "tags": [
          "Keys"
        ],
        "summary": "List API keys",
        "responses": {
          "200": {
            "description": "Keys returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "keys"
                  ],
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKey"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Keys"
        ],
        "summary": "Create named API key",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/_keys/{id}": {
      "delete": {
        "tags": [
          "Keys"
        ],
        "summary": "Revoke API key",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revocation result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "revoked"
                  ],
                  "properties": {
                    "revoked": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Request failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "PumaApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "puma_live_<accountid>_<secret>",
        "description": "Full-account API key. Keep this secret on the server."
      }
    },
    "schemas": {
      "MagicLinkRequest": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "MagicLinkResponse": {
        "type": "object",
        "required": [
          "ok",
          "expires_at"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "dev_magic_link": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "VerifyMagicLinkRequest": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string"
          }
        }
      },
      "VerifyMagicLinkResponse": {
        "type": "object",
        "required": [
          "api_key",
          "account_id"
        ],
        "properties": {
          "api_key": {
            "type": "string",
            "pattern": "^puma_live_"
          },
          "account_id": {
            "type": "string"
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "required": [
          "id",
          "account_id",
          "name",
          "prefix",
          "scope",
          "revoked_at",
          "created_at",
          "last_used_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "account_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "prefix": {
            "type": "string"
          },
          "scope": {
            "type": "string",
            "enum": [
              "*"
            ]
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "CreateApiKeyResponse": {
        "type": "object",
        "required": [
          "api_key",
          "id",
          "prefix",
          "scope"
        ],
        "properties": {
          "api_key": {
            "type": "string",
            "pattern": "^puma_live_"
          },
          "id": {
            "type": "string"
          },
          "prefix": {
            "type": "string"
          },
          "scope": {
            "type": "string",
            "enum": [
              "*"
            ]
          }
        }
      },
      "CreateTextFieldLinkRequest": {
        "type": "object",
        "required": [
          "table",
          "field"
        ],
        "properties": {
          "table": {
            "type": "string",
            "minLength": 1
          },
          "field": {
            "type": "string",
            "minLength": 1
          },
          "id": {
            "type": "string"
          },
          "filter": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "filename": {
            "type": "string"
          },
          "mimeType": {
            "type": "string"
          }
        },
        "anyOf": [
          {
            "required": [
              "id"
            ]
          },
          {
            "required": [
              "filter"
            ]
          }
        ]
      },
      "CreateTextFieldLinkResponse": {
        "type": "object",
        "required": [
          "viewer_url",
          "download_url",
          "expires_at",
          "filename",
          "mime_type",
          "table",
          "field",
          "safety"
        ],
        "properties": {
          "viewer_url": {
            "type": "string",
            "format": "uri"
          },
          "download_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "filename": {
            "type": "string"
          },
          "mime_type": {
            "type": "string"
          },
          "table": {
            "type": "string"
          },
          "field": {
            "type": "string"
          },
          "safety": {
            "type": "string"
          }
        }
      },
      "CreateRowLinkRequest": {
        "type": "object",
        "required": [
          "table",
          "id"
        ],
        "properties": {
          "table": {
            "type": "string",
            "minLength": 1
          },
          "id": {
            "type": "string",
            "minLength": 1
          },
          "filename": {
            "type": "string"
          }
        }
      },
      "CreateRowLinkResponse": {
        "type": "object",
        "required": [
          "viewer_url",
          "download_url",
          "expires_at",
          "filename",
          "mime_type",
          "table",
          "id",
          "safety"
        ],
        "properties": {
          "viewer_url": {
            "type": "string",
            "format": "uri"
          },
          "download_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "filename": {
            "type": "string"
          },
          "mime_type": {
            "type": "string",
            "enum": [
              "application/json"
            ]
          },
          "table": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "safety": {
            "type": "string"
          }
        }
      },
      "CreateQueryLinkRequest": {
        "type": "object",
        "required": [
          "table"
        ],
        "properties": {
          "table": {
            "type": "string",
            "minLength": 1
          },
          "filter": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "sort": {
            "type": "string"
          },
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "filename": {
            "type": "string"
          }
        }
      },
      "CreateQueryLinkResponse": {
        "type": "object",
        "required": [
          "viewer_url",
          "download_url",
          "expires_at",
          "filename",
          "mime_type",
          "table",
          "safety"
        ],
        "properties": {
          "viewer_url": {
            "type": "string",
            "format": "uri"
          },
          "download_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "filename": {
            "type": "string"
          },
          "mime_type": {
            "type": "string",
            "enum": [
              "application/json"
            ]
          },
          "table": {
            "type": "string"
          },
          "filter": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "sort": {
            "type": "string"
          },
          "limit": {
            "type": "integer"
          },
          "safety": {
            "type": "string"
          }
        }
      },
      "RowVersion": {
        "type": "object",
        "required": [
          "version",
          "archived_at",
          "deleted",
          "row"
        ],
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "archived_at": {
            "type": "string",
            "format": "date-time"
          },
          "deleted": {
            "type": "boolean"
          },
          "row": {
            "allOf": [
              {
                "type": "object",
                "additionalProperties": true
              },
              {
                "type": "object",
                "required": [
                  "id",
                  "created_at",
                  "updated_at"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "updated_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            ]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": true
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "PumaApiKey": []
    }
  ],
  "x-pumadb-limits": {
    "maxTables": 20,
    "maxRowsPerTable": 1000,
    "maxAccountBytes": 26214400,
    "maxRowBytes": 65536,
    "maxBatchOperations": 100,
    "readsPerMinute": 60,
    "writesPerMinute": 30,
    "maxQueryLimit": 1000,
    "maxVersionsPerRow": 10,
    "versionRetentionDays": 30
  }
}