{
 "openapi": "3.1.0",
 "info": {
  "title": "Served",
  "version": "1",
  "description": "Hosted SQLite. Each database is one ordinary SQLite file, reached over HTTP. Plain-text version of these docs: https://served.dev/llms.txt"
 },
 "servers": [
  {
   "url": "https://api.served.dev"
  }
 ],
 "security": [
  {
   "apiKey": []
  }
 ],
 "paths": {
  "/v1/account": {
   "get": {
    "operationId": "getAccount",
    "summary": "Plan state, storage used and storage limit.",
    "responses": {
     "200": {
      "description": "The account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Account"
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/databases": {
   "get": {
    "operationId": "listDatabases",
    "summary": "List databases.",
    "responses": {
     "200": {
      "description": "Every database on the account.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "databases": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Database"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "operationId": "createDatabase",
    "summary": "Create a database. Safe to repeat: an existing name returns 200 with created false.",
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "1 to 63 characters: lowercase letters, digits, - and _, starting with a letter or digit. Omit for a generated name."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Database"
        }
       }
      },
      "description": "The database already existed."
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "The name breaks the naming rule.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "Trial or subscription ended.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "201": {
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Database"
        }
       }
      },
      "description": "Created."
     },
     "503": {
      "description": "The server is short of disk space; reads still work. Retry later.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/databases/{name}": {
   "parameters": [
    {
     "name": "name",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
     },
     "description": "Database name."
    }
   ],
   "get": {
    "operationId": "getDatabase",
    "summary": "Size and last change of one database.",
    "responses": {
     "200": {
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Database"
        }
       }
      },
      "description": "The database."
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No database of that name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "deleteDatabase",
    "summary": "Delete a database. This cannot be undone.",
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "name": {
           "type": "string"
          },
          "deleted": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No database of that name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/databases/{name}/query": {
   "parameters": [
    {
     "name": "name",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
     },
     "description": "Database name."
    }
   ],
   "post": {
    "operationId": "query",
    "summary": "Run SQL.",
    "description": "The body is one statement with parameters, an array of statements run as ONE transaction, or bare SQL as text. A sql string may hold several statements separated by semicolons; the rows returned are those of the last statement that returns any. Each request uses a fresh connection, so connection settings and temporary tables do not carry over.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "$ref": "#/components/schemas/Statement"
         },
         {
          "type": "array",
          "minItems": 1,
          "items": {
           "$ref": "#/components/schemas/Statement"
          },
          "description": "Run as one transaction: all take effect or none."
         }
        ]
       }
      },
      "text/plain": {
       "schema": {
        "type": "string",
        "description": "Bare SQL."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "A Result for a single statement or bare SQL; {results: [...]} for an array.",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "$ref": "#/components/schemas/Result"
          },
          {
           "type": "object",
           "properties": {
            "results": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Result"
             }
            }
           }
          }
         ]
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "SQLite refused the statement (code SQLITE_*), or the request is malformed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "Trial or subscription ended.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "A refused statement: one that reaches outside the database.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No database of that name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "408": {
      "description": "Ran past the time limit.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Another request held a lock; retry.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "Request or result too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "507": {
      "description": "Storage limit reached.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The server is short of disk space; reads still work. Retry later.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/databases/{name}/download": {
   "parameters": [
    {
     "name": "name",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
     },
     "description": "Database name."
    }
   ],
   "get": {
    "operationId": "downloadDatabase",
    "summary": "The database as a SQLite file: a consistent copy from one moment.",
    "responses": {
     "200": {
      "description": "A SQLite database file.",
      "content": {
       "application/vnd.sqlite3": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No database of that name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/databases/{name}/upload": {
   "parameters": [
    {
     "name": "name",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
     },
     "description": "Database name."
    }
   ],
   "put": {
    "operationId": "uploadDatabase",
    "summary": "Replace the database with a SQLite file, or create it.",
    "requestBody": {
     "required": true,
     "content": {
      "application/vnd.sqlite3": {
       "schema": {
        "type": "string",
        "format": "binary"
       }
      },
      "application/octet-stream": {
       "schema": {
        "type": "string",
        "format": "binary"
       }
      }
     }
    },
    "responses": {
     "200": {
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Database"
        }
       }
      },
      "description": "Replaced or created."
     },
     "401": {
      "description": "Missing or invalid API key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests running at once on the account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "Not a valid SQLite database file, or a bad name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "Trial or subscription ended.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "507": {
      "description": "Storage limit reached.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The server is short of disk space; reads still work. Retry later.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "apiKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "An API key from https://app.served.dev/dashboard, starting with served_."
   }
  },
  "schemas": {
   "Value": {
    "description": "NULL is null; INTEGER and REAL are numbers; TEXT is a string; a BLOB is {\"base64\": \"...\"}.",
    "oneOf": [
     {
      "type": "null"
     },
     {
      "type": "number"
     },
     {
      "type": "string"
     },
     {
      "type": "boolean"
     },
     {
      "type": "object",
      "properties": {
       "base64": {
        "type": "string"
       }
      },
      "required": [
       "base64"
      ],
      "additionalProperties": false
     }
    ]
   },
   "Statement": {
    "type": "object",
    "required": [
     "sql"
    ],
    "properties": {
     "sql": {
      "type": "string"
     },
     "args": {
      "description": "An array for ? parameters, or an object for named ones (:name, @name or $name; the prefix is optional in keys).",
      "oneOf": [
       {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/Value"
        }
       },
       {
        "type": "object",
        "additionalProperties": {
         "$ref": "#/components/schemas/Value"
        }
       }
      ]
     }
    }
   },
   "Result": {
    "type": "object",
    "properties": {
     "columns": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "array",
       "items": {
        "$ref": "#/components/schemas/Value"
       }
      }
     },
     "rows_affected": {
      "type": "integer"
     },
     "last_insert_id": {
      "type": "integer"
     }
    }
   },
   "Database": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string"
     },
     "bytes": {
      "type": "integer"
     },
     "modified": {
      "type": "string",
      "format": "date-time"
     },
     "created": {
      "type": "boolean",
      "description": "Only in the response to creating."
     }
    }
   },
   "Account": {
    "type": "object",
    "properties": {
     "login": {
      "type": "string"
     },
     "state": {
      "type": "string",
      "enum": [
       "trial",
       "active",
       "locked"
      ]
     },
     "trial_ends": {
      "type": "string",
      "format": "date-time"
     },
     "usage_bytes": {
      "type": "integer"
     },
     "limit_bytes": {
      "type": "integer"
     }
    }
   },
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "description": "A stable code such as not_found, storage_full or SQLITE_CONSTRAINT."
       },
       "message": {
        "type": "string",
        "description": "What went wrong and what to do about it."
       },
       "statement": {
        "type": "integer",
        "description": "In a transaction, the index of the statement that failed, from 0."
       }
      }
     }
    }
   }
  }
 }
}
