{
  "components": {
    "schemas": {
      "ApiError": {
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      },
      "ConfigResponse": {
        "properties": {
          "allow_never": {
            "description": "Whether expires_in may be \"never\".",
            "type": "boolean"
          },
          "allow_server_encryption": {
            "description": "Whether the plaintext (server-side encryption) mode is enabled.",
            "type": "boolean"
          },
          "default_expiration": {
            "description": "Expiration used when expires_in is omitted.",
            "examples": [
              "1d"
            ],
            "type": "string"
          },
          "expirations": {
            "description": "Accepted values for expires_in (besides never, see allow_never).",
            "examples": [
              [
                "5m",
                "1h",
                "1d",
                "1w",
                "1mo"
              ]
            ],
            "items": {
              "type": "string"
            },
            "type": [
              "array",
              "null"
            ]
          },
          "max_size": {
            "description": "Maximum paste size in bytes (decoded ciphertext, or UTF-8 text in plaintext mode).",
            "examples": [
              1048576
            ],
            "format": "int64",
            "type": "integer"
          },
          "mcp_enabled": {
            "description": "Whether the hosted MCP endpoint /mcp is enabled.",
            "type": "boolean"
          },
          "version": {
            "description": "Server version.",
            "examples": [
              "1.0.0"
            ],
            "type": "string"
          }
        },
        "required": [
          "version",
          "max_size",
          "expirations",
          "default_expiration",
          "allow_never",
          "allow_server_encryption",
          "mcp_enabled"
        ],
        "type": "object"
      },
      "CreateResponse": {
        "properties": {
          "delete_token": {
            "description": "Secret token for DELETE (X-Delete-Token header). Returned only once.",
            "pattern": "^[A-Za-z0-9_-]{43}$",
            "type": "string"
          },
          "expires_at": {
            "description": "Expiry time, null if the paste never expires.",
            "format": "date-time",
            "type": [
              "null",
              "string"
            ]
          },
          "id": {
            "examples": [
              "AbC123xYz789"
            ],
            "pattern": "^[0-9A-Za-z]{12}$",
            "type": "string"
          },
          "server_encrypted": {
            "description": "True if the server encrypted the text (plaintext mode): not zero-knowledge.",
            "type": "boolean"
          },
          "url": {
            "description": "Share URL. Includes #\u003ckey\u003e only when server_encrypted is true.",
            "examples": [
              "https://paste.retyc.com/p/AbC123xYz789"
            ],
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "id",
          "url",
          "delete_token",
          "expires_at",
          "server_encrypted"
        ],
        "type": "object"
      },
      "EncryptedCreateBody": {
        "additionalProperties": false,
        "properties": {
          "burn_after_reading": {
            "description": "Delete the paste on its first read (bound in the AAD).",
            "type": "boolean"
          },
          "ciphertext": {
            "description": "base64url (no padding) of the AES-256-GCM ciphertext with its 16-byte tag appended. Decoded size at most max_size.",
            "examples": [
              "q83vEjRWeJA_Ilk8ZrLm1nGTPQ"
            ],
            "minLength": 22,
            "pattern": "^[A-Za-z0-9_-]+$",
            "type": "string"
          },
          "expires_in": {
            "description": "One of the configured expirations (GET /api/v1/config), or \"never\" if allowed. Omitted: default expiration.",
            "examples": [
              "1d"
            ],
            "type": "string"
          },
          "iv": {
            "description": "base64url (no padding) of the 12-byte IV.",
            "examples": [
              "yMnKy8zNzs_Q0dLT"
            ],
            "pattern": "^[A-Za-z0-9_-]{16}$",
            "type": "string"
          },
          "password": {
            "description": "True if the key is derived with a password (bound in the AAD).",
            "type": "boolean"
          },
          "salt": {
            "description": "base64url (no padding) of the 16-byte salt.",
            "examples": [
              "ZGVmZ2hpamtsbW5vcHFycw"
            ],
            "pattern": "^[A-Za-z0-9_-]{22}$",
            "type": "string"
          }
        },
        "required": [
          "ciphertext",
          "iv",
          "salt"
        ],
        "type": "object"
      },
      "ErrorBody": {
        "properties": {
          "code": {
            "description": "Stable snake_case error code.",
            "examples": [
              "not_found"
            ],
            "type": "string"
          },
          "message": {
            "description": "Human-readable message.",
            "examples": [
              "paste not found or expired"
            ],
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      },
      "PasteMetaResponse": {
        "properties": {
          "burn_after_reading": {
            "description": "The paste will be deleted by its first GET /api/v1/pastes/{id}.",
            "type": "boolean"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "expires_at": {
            "description": "Expiry time, null if the paste never expires.",
            "format": "date-time",
            "type": [
              "null",
              "string"
            ]
          },
          "id": {
            "examples": [
              "AbC123xYz789"
            ],
            "pattern": "^[0-9A-Za-z]{12}$",
            "type": "string"
          },
          "password": {
            "description": "A password is needed to decrypt.",
            "type": "boolean"
          },
          "version": {
            "description": "Crypto format version.",
            "enum": [
              1
            ],
            "type": "integer"
          }
        },
        "required": [
          "id",
          "version",
          "password",
          "burn_after_reading",
          "created_at",
          "expires_at"
        ],
        "type": "object"
      },
      "PasteResponse": {
        "properties": {
          "burn_after_reading": {
            "description": "The paste was deleted by this read.",
            "type": "boolean"
          },
          "ciphertext": {
            "description": "base64url (no padding) ciphertext with the GCM tag appended.",
            "pattern": "^[A-Za-z0-9_-]+$",
            "type": "string"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "expires_at": {
            "description": "Expiry time, null if the paste never expires.",
            "format": "date-time",
            "type": [
              "null",
              "string"
            ]
          },
          "id": {
            "examples": [
              "AbC123xYz789"
            ],
            "pattern": "^[0-9A-Za-z]{12}$",
            "type": "string"
          },
          "iv": {
            "description": "base64url (no padding) 12-byte IV.",
            "pattern": "^[A-Za-z0-9_-]{16}$",
            "type": "string"
          },
          "password": {
            "description": "A password is needed to decrypt.",
            "type": "boolean"
          },
          "salt": {
            "description": "base64url (no padding) 16-byte salt.",
            "pattern": "^[A-Za-z0-9_-]{22}$",
            "type": "string"
          },
          "version": {
            "description": "Crypto format version.",
            "enum": [
              1
            ],
            "type": "integer"
          }
        },
        "required": [
          "id",
          "version",
          "ciphertext",
          "iv",
          "salt",
          "password",
          "burn_after_reading",
          "created_at",
          "expires_at"
        ],
        "type": "object"
      },
      "PlaintextCreateBody": {
        "additionalProperties": false,
        "properties": {
          "burn_after_reading": {
            "description": "Delete the paste on its first read.",
            "type": "boolean"
          },
          "expires_in": {
            "description": "One of the configured expirations (GET /api/v1/config), or \"never\" if allowed. Omitted: default expiration.",
            "examples": [
              "1d"
            ],
            "type": "string"
          },
          "password": {
            "description": "Optional password.",
            "type": "string"
          },
          "text": {
            "description": "UTF-8 text to encrypt server-side (not zero-knowledge). At most max_size bytes.",
            "examples": [
              "hello"
            ],
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "text"
        ],
        "type": "object"
      },
      "RateLimitedError": {
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      }
    }
  },
  "externalDocs": {
    "description": "Source code and specification",
    "url": "https://github.com/retyc/retyc-paste"
  },
  "info": {
    "contact": {
      "name": "Retyc",
      "url": "https://retyc.com/"
    },
    "description": "Zero-knowledge, encrypted, expiring pastes.\n\nClients encrypt text locally (AES-256-GCM, crypto format v1, see docs/SPEC.md) and only upload ciphertext; the key travels in the share URL fragment (`#...`), which is never sent to the server. A plaintext mode lets the server encrypt instead (not zero-knowledge, can be disabled).\n\nErrors use the body `{\"error\": {\"code\": \"...\", \"message\": \"...\"}}`.",
    "license": {
      "identifier": "AGPL-3.0-only",
      "name": "AGPL-3.0-only"
    },
    "title": "retyc-paste",
    "version": "0.0.1"
  },
  "openapi": "3.1.0",
  "paths": {
    "/api/v1/config": {
      "get": {
        "tags": [
          "pastes"
        ],
        "summary": "Get the instance configuration",
        "description": "Limits and options a client needs before creating a paste.",
        "operationId": "getConfig",
        "responses": {
          "200": {
            "description": "Instance configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfigResponse"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed on this path (`method_not_allowed`); see the `Allow` header.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/openapi.json": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Get this OpenAPI document",
        "description": "",
        "operationId": "getOpenAPI",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 document.",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": {},
                  "type": [
                    "null",
                    "object"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/pastes": {
      "post": {
        "tags": [
          "pastes"
        ],
        "summary": "Create a paste",
        "description": "Three body shapes are accepted.\n\n**Raw text** (`Content-Type: text/plain`, simplest): the body is the UTF-8 text, taken verbatim. A missing Content-Type or `application/x-www-form-urlencoded` (curl's default for `--data-binary`) is treated the same way, never form-decoded. Options go in the query string (`expires`, `burn`) and the optional password in the `X-Paste-Password` header (never in the URL). The server encrypts it and answers with the share URL (including `#\u003ckey\u003e`) as a `text/plain` line, plus the `X-Delete-Token` and `X-Expires-At` headers; send `Accept: application/json` to get the JSON response instead. Example: `curl --data-binary @notes.txt https://paste.retyc.com/api/v1/pastes`.\n\n**Client-encrypted** JSON (zero-knowledge): send `ciphertext`, `iv` and `salt` produced with the v1 crypto format (AES-256-GCM, key in the URL fragment). The returned `url` has no key: append `#\u003ckey\u003e` yourself.\n\n**Plaintext** JSON (server-side encryption, detected by the `text` field): the server encrypts the text and returns a `url` that includes `#\u003ckey\u003e`, with `server_encrypted: true`.\n\nRaw text and plaintext JSON are **not** zero-knowledge (the server sees the text while encrypting it) and can be disabled by the operator (403). Cross-site browser requests are refused (403 `cross_origin`).",
        "operationId": "createPaste",
        "parameters": [
          {
            "name": "expires",
            "in": "query",
            "description": "text/plain body only: one of the configured expirations (GET /api/v1/config), or \"never\" if allowed. Omitted: default expiration.",
            "schema": {
              "description": "text/plain body only: one of the configured expirations (GET /api/v1/config), or \"never\" if allowed. Omitted: default expiration.",
              "examples": [
                "1d"
              ],
              "type": "string"
            }
          },
          {
            "name": "burn",
            "in": "query",
            "description": "text/plain body only: 1 or true to delete the paste on its first read.",
            "schema": {
              "description": "text/plain body only: 1 or true to delete the paste on its first read.",
              "enum": [
                "1",
                "true",
                "0",
                "false"
              ],
              "type": "string"
            }
          },
          {
            "name": "X-Paste-Password",
            "in": "header",
            "description": "text/plain body only: optional password, also needed to read the paste. Never put it in the URL.",
            "schema": {
              "description": "text/plain body only: optional password, also needed to read the paste. Never put it in the URL.",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "JSON: client-encrypted body, or plaintext body (server-side encryption). text/plain: the raw UTF-8 text, encrypted server-side.",
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/EncryptedCreateBody"
                  },
                  {
                    "$ref": "#/components/schemas/PlaintextCreateBody"
                  }
                ]
              }
            },
            "text/plain": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Paste created; the delete token is returned only once. JSON requests get the JSON body. Raw text requests get the share URL followed by a newline as `text/plain`, with the `X-Delete-Token` and `X-Expires-At` headers, unless they send `Accept: application/json`.",
            "headers": {
              "X-Delete-Token": {
                "style": "simple",
                "description": "text/plain response only: secret token for DELETE. Returned only once.",
                "schema": {
                  "description": "text/plain response only: secret token for DELETE. Returned only once.",
                  "type": "string"
                }
              },
              "X-Expires-At": {
                "style": "simple",
                "description": "text/plain response only: RFC 3339 expiry time, or never.",
                "schema": {
                  "description": "text/plain response only: RFC 3339 expiry time, or never.",
                  "examples": [
                    "2026-12-05T10:00:00Z"
                  ],
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResponse"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Server-side encryption is disabled (`server_encryption_disabled`), or cross-site browser request (`cross_origin`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed on this path (`method_not_allowed`); see the `Allow` header.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "Paste or request body larger than `max_size` (`too_large`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported Content-Type (`unsupported_media_type`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded for this client IP (`rate_limited`).",
            "headers": {
              "Retry-After": {
                "style": "simple",
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "description": "Seconds to wait before retrying.",
                  "examples": [
                    6
                  ],
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitedError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`internal`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/pastes/{id}": {
      "get": {
        "tags": [
          "pastes"
        ],
        "summary": "Get an encrypted paste",
        "description": "Returns the encrypted paste; decrypt it client-side with the key from the URL fragment. If `burn_after_reading` is true, this read atomically deletes the paste: only one reader ever gets it. Responses carry `Cache-Control: no-store`. `HEAD` is refused (405): only an explicit `GET` consumes a paste.",
        "operationId": "getPaste",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Paste identifier.",
            "required": true,
            "schema": {
              "description": "Paste identifier.",
              "examples": [
                "AbC123xYz789"
              ],
              "pattern": "^[0-9A-Za-z]{12}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The encrypted paste.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PasteResponse"
                }
              }
            }
          },
          "404": {
            "description": "Paste missing, expired, already burned, or invalid delete token (`not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed on this path (`method_not_allowed`); see the `Allow` header.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded for this client IP (`rate_limited`).",
            "headers": {
              "Retry-After": {
                "style": "simple",
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "description": "Seconds to wait before retrying.",
                  "examples": [
                    6
                  ],
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitedError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`internal`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "pastes"
        ],
        "summary": "Delete a paste",
        "description": "Deletes a paste with the delete token returned at creation. A missing paste and a wrong token both yield 404. Rate-limited with the create bucket (`RATE_CREATE`), not the read bucket: deletions are writes, and the stricter bucket also bounds delete token guessing.",
        "operationId": "deletePaste",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Paste identifier.",
            "required": true,
            "schema": {
              "description": "Paste identifier.",
              "examples": [
                "AbC123xYz789"
              ],
              "pattern": "^[0-9A-Za-z]{12}$",
              "type": "string"
            }
          },
          {
            "name": "X-Delete-Token",
            "in": "header",
            "description": "Delete token returned at creation.",
            "required": true,
            "schema": {
              "description": "Delete token returned at creation.",
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Paste deleted."
          },
          "404": {
            "description": "Paste missing, expired, already burned, or invalid delete token (`not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed on this path (`method_not_allowed`); see the `Allow` header.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded for this client IP (`rate_limited`).",
            "headers": {
              "Retry-After": {
                "style": "simple",
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "description": "Seconds to wait before retrying.",
                  "examples": [
                    6
                  ],
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitedError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`internal`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/pastes/{id}/meta": {
      "get": {
        "tags": [
          "pastes"
        ],
        "summary": "Get paste metadata without consuming it",
        "description": "Returns the flags and dates of a paste but not its ciphertext, and never consumes it, even with `burn_after_reading`. Clients use it to ask for confirmation (or a password) before the consuming `GET`, so that link scanners and previews cannot burn pastes. Rate-limited with the read bucket; responses carry `Cache-Control: no-store`.",
        "operationId": "getPasteMeta",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Paste identifier.",
            "required": true,
            "schema": {
              "description": "Paste identifier.",
              "examples": [
                "AbC123xYz789"
              ],
              "pattern": "^[0-9A-Za-z]{12}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The paste metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PasteMetaResponse"
                }
              }
            }
          },
          "404": {
            "description": "Paste missing, expired, already burned, or invalid delete token (`not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed on this path (`method_not_allowed`); see the `Allow` header.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded for this client IP (`rate_limited`).",
            "headers": {
              "Retry-After": {
                "style": "simple",
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "description": "Seconds to wait before retrying.",
                  "examples": [
                    6
                  ],
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitedError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`internal`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "tags": [
    {
      "name": "pastes",
      "description": "Create, read and delete encrypted pastes."
    },
    {
      "name": "meta",
      "description": "API description."
    }
  ]
}
