HTTP API
You can manage your capsule from your own tooling (cURL, scripts, etc.) instead of the official captown client. Everything the client does is a small set of HTTPS calls to this API.
Base URL: https://api.capsule.town
All requests and responses are JSON (Content-Type: application/json).
Authentication
Endpoints that read or change a specific capsule require an api-key header set to the JWT access token you received when the capsule was created:
curl -H "api-key: $TOKEN" https://api.capsule.town/logs
A missing or invalid key returns HTTP 400:
{"message":"There was a problem with your request"}
Keep your token secret: anyone with it can publish, rename or delete your capsule. If you lose it, you can recover it (see Recover a lost token) provided you registered a verified email address.
Errors
Every error response has the same shape - a JSON object with a single message field and a 4xx or 5xx status:
{"message":"A capsule with this name already exists"}
Create a capsule
POST /capsule - no authentication.
Request:
{
"capsuleName": "mycapsule",
"email": "you@example.com"
}
capsuleName(required): the subdomain, 3-20 characters, letters and numbers only, and not a reserved word. It becomesgemini://mycapsule.capsule.town.email(required, but may be an empty string): an optional recovery address. If non-empty, a verification code is emailed to it (see Verify your email).
Response 200:
{"message":"Capsule created","accessToken":"eyJhbGciOi..."}
accessToken is what you send as api-key. It is shown only once - store it somewhere safe.
Errors 400: invalid or taken name, invalid email.
Publish (deploy) your capsule
PUT /capsule - requires api-key.
Request:
{
"capsuleArchive": "<base64>"
}
capsuleArchive is the base64 encoding of a gzipped tarball of your capsule's files. The tarball may contain subdirectories; a file named index.gmi is served as the capsule's homepage. To create the payload from a capsule/ directory:
tar -czf capsule.tar.gz -C capsule .
base64 -w0 capsule.tar.gz
Response 200:
{"message":"Your capsule was deployed","url":"gemini://mycapsule.capsule.town"}
Errors 400: the archive could not be decoded or unpacked.
Rename a capsule
PATCH /capsule - requires api-key.
Request:
{"capsuleName":"newname"}
The same naming rules as creation apply. Response 200:
{"message":"Your capsule has been renamed","url":"gemini://newname.capsule.town"}
Your token continues to work under the new name. Errors 400: invalid or taken name.
Delete a capsule
DELETE /capsule - requires api-key. No request body.
Response 200:
{"message":"Your capsule has been deleted"}
This removes the capsule, its content, and its data. It cannot be undone.
View access logs
GET /logs - requires api-key.
Response 200:
{"logs":[{"path":"/index.gmi","timestamp":1732000000}]}
The most recent 100 page views, newest first. timestamp is a Unix timestamp in seconds.
Verify your email
POST /verify - requires api-key.
Request:
{"code":"123456"}
code is the 6-digit code emailed to the address you supplied at creation. Response 200:
{"message":"Your email address has been verified"}
A verified email is what enables token recovery. Errors 400: the code is wrong or expired (codes last 15 minutes).
Rotate your access token
POST /token/rotate - requires api-key. No request body.
Response 200:
{"message":"Your access token has been rotated","accessToken":"eyJhbGciOi..."}
Use this if you suspect your token leaked. The old token stops working immediately; store the new one.
Recover a lost token
If you lost your token and registered a verified email, you can reset it in two steps.
Step 1 - request a code
POST /recover/request - no authentication.
Request:
{"capsuleName":"mycapsule","email":"you@example.com"}
The response is the same whether or not the details match, to avoid revealing whether a capsule or email exists:
{"message":"If the details match a verified capsule, a recovery code has been emailed to you."}
Codes expire after 15 minutes. Requests are rate-limited.
Step 2 - submit the code
POST /recover/confirm - no authentication.
Request:
{"capsuleName":"mycapsule","email":"you@example.com","code":"123456"}
Response 200:
{"message":"Your access token has been reset","accessToken":"eyJhbGciOi...","url":"gemini://mycapsule.capsule.town"}
The previous token is invalidated. Errors 400: the code is wrong or expired.
Worked example: create and publish with cURL
# Create a capsule and keep the token
TOKEN=$(curl -s https://api.capsule.town/capsule \
-H 'Content-Type: application/json' \
-d '{"capsuleName":"mycapsule","email":""}' | sed 's/.*"accessToken":"\([^"]*\)".*/\1/')
# Tarball + base64 the capsule directory
ARCHIVE=$(tar -czf - -C capsule . | base64 -w0)
# Publish it
curl -s -X PUT https://api.capsule.town/capsule \
-H "api-key: $TOKEN" \
-H 'Content-Type: application/json' \
-d "{\"capsuleArchive\":\"$ARCHIVE\"}"
# View logs
curl -s https://api.capsule.town/logs -H "api-key: $TOKEN"