{
  "openapi": "3.1.0",
  "info": {
    "title": "Ephemer.pw API",
    "version": "1.0.0",
    "summary": "Create self-destructing, end-to-end encrypted secret links.",
    "description": "Zero-knowledge API: you encrypt the secret yourself (AES-256-GCM, key derived with HKDF-SHA-256 from a random 32-byte key that goes in the link fragment). The server only ever stores ciphertext and cannot read anything. The encryption protocol is specified at https://ephemer.pw/developers#protocol; reference clients: https://ephemer.pw/cli/ephemer.mjs (Node.js), https://ephemer.pw/cli/ephemer.py (Python), https://ephemer.pw/cli/Ephemer.cs (C# / .NET) and https://ephemer.pw/cli/Ephemer.java (Java). No authentication: requests are rate limited per IP address.",
    "contact": {
      "url": "https://ephemer.pw/developers"
    },
    "license": {
      "name": "MIT (reference clients)",
      "identifier": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://ephemer.pw/api/v1"
    }
  ],
  "security": [],
  "paths": {
    "/secrets": {
      "post": {
        "operationId": "createSecret",
        "summary": "Store an encrypted secret",
        "description": "The secret link is then `https://ephemer.pw/s/{id}#{urlKey}` where urlKey is the base64url-encoded random key you generated. Never send urlKey to the API. Rate limit: 10 requests per minute per IP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSecretRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored.",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateSecretResponse"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_json` or `invalid_payload` (with `issues` per field).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`id_taken`: retry with a new random id (and re-encrypt, the id is authenticated data).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: wait `Retry-After` seconds.",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              },
              "Retry-After": {
                "$ref": "#/components/headers/Retry-After"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/secrets/{id}": {
      "get": {
        "operationId": "getSecretStatus",
        "summary": "Status of a secret (spends no view)",
        "description": "Returns whether the secret still exists, how many views are left and when it expires. Expired, exhausted and unknown secrets all return 404, indistinguishably. Rate limit: 60 requests per minute per IP.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/SecretId"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The secret is alive.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SecretStatus"
                }
              }
            }
          },
          "404": {
            "description": "`not_found`: expired, opened the maximum number of times, or never existed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Base64Url": {
        "type": "string",
        "pattern": "^[A-Za-z0-9_-]+$",
        "description": "Unpadded base64url (RFC 4648 §5)."
      },
      "SecretId": {
        "type": "string",
        "pattern": "^[A-Za-z0-9_-]{16}$",
        "description": "16 random characters from A-Z a-z 0-9 _ - (96 bits), generated by the client.",
        "examples": ["K_xEr7XyYQ22dxO_"]
      },
      "CreateSecretRequest": {
        "type": "object",
        "required": [
          "id",
          "ciphertext",
          "iv",
          "salt",
          "authToken",
          "views",
          "expiresIn"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/SecretId"
          },
          "ciphertext": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]+$",
            "minLength": 23,
            "maxLength": 131072,
            "description": "AES-256-GCM output (ciphertext followed by the 16-byte tag), base64url. At least 17 bytes decoded (23 characters): anything shorter cannot be ciphertext and is rejected, which catches secrets sent in clear by mistake. At most 98,304 bytes decoded; plaintext at most 65,536 bytes."
          },
          "iv": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16}$",
            "description": "12 random bytes, base64url."
          },
          "salt": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{22}$",
            "description": "16 random bytes, base64url. Used by HKDF (and Argon2id when a passphrase is set)."
          },
          "authToken": {
            "type": ["string", "null"],
            "pattern": "^[A-Za-z0-9_-]{43}$",
            "description": "32-byte HKDF output with info `ephemer:v1:auth`, base64url — only when a passphrase is required; otherwise null. The server stores its SHA-256."
          },
          "views": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "description": "How many times the link can be opened."
          },
          "expiresIn": {
            "type": "string",
            "enum": ["5m", "30m", "1h", "12h", "24h", "3d", "7d"],
            "description": "Lifetime. The secret is deleted after `views` openings or this delay, whichever comes first."
          }
        }
      },
      "CreateSecretResponse": {
        "type": "object",
        "required": ["id", "expiresAt", "viewsLeft"],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/SecretId"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "viewsLeft": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10
          }
        }
      },
      "SecretStatus": {
        "type": "object",
        "required": ["salt", "viewsLeft", "expiresAt", "hasPassphrase"],
        "properties": {
          "salt": {
            "$ref": "#/components/schemas/Base64Url"
          },
          "viewsLeft": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "hasPassphrase": {
            "type": "boolean"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_json",
              "invalid_payload",
              "id_taken",
              "rate_limited",
              "not_found"
            ]
          },
          "issues": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "description": "Only for invalid_payload: validation messages per field."
          }
        }
      }
    },
    "headers": {
      "X-RateLimit-Limit": {
        "description": "Requests allowed in the current window.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Remaining": {
        "description": "Requests left in the current window.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Reset": {
        "description": "Unix time (seconds) when the window resets.",
        "schema": {
          "type": "integer"
        }
      },
      "Retry-After": {
        "description": "Only on 429: seconds to wait.",
        "schema": {
          "type": "integer"
        }
      }
    }
  }
}
