sculk.network
Nightly Stable docs
sculkwormnightly · 39a95aaView in Stable docs

HTTP Admin API

When SCULKWORM_TENANTS_FILE is set, sculkworm exposes a multi-tenant HTTP/1.1 admin API on SCULKWORM_API_ADDR (default 127.0.0.1:8080, or 0.0.0.0:8080 in Docker). The machine-readable schema lives in openapi.yaml. For TypeScript and JavaScript backends, use the official client SDK.

When SCULKWORM_TENANTS_FILE is unset, the HTTP admin API is disabled and no HTTP port is opened.

Authentication and tenancy#

Every /v1/* endpoint requires an Authorization header:

text
Authorization: Bearer <key>

The Bearer scheme is matched case-insensitively per RFC 7235. Keys are configured per tenant in SCULKWORM_TENANTS_FILE (at least 32 characters each, unique across tenants) and compared in constant time across all configured tenants without early exit. Missing or invalid credentials return 401 Unauthorized with WWW-Authenticate: Bearer:

sh
curl -sS -i http://127.0.0.1:8080/v1/routes
text
HTTP/1.1 401 Unauthorized
content-type: application/json
www-authenticate: Bearer
cache-control: no-store
content-length: 77
date: Thu, 26 Nov 2026 12:28:43 GMT

{"error":{"code":"unauthorized","message":"missing or invalid bearer token"}}

Each tenant is restricted to its configured domain scopes:

  • A tenant may manage hostname H if and only if H equals one of its domains or ends with . plus one of its domains.
  • A tenant can only list, read, update, or delete its own dynamic routes, agent tokens, connected agents, and revocations. Static routes and other tenants' routes are hidden from GET /v1/routes and GET /v1/agents, and return 404 not_found on GET, DELETE, POST .../agent-token, DELETE .../agent-token, and POST .../revoke-logins.
  • GET /healthz requires no authentication.

Limits and error format#

  • Request bodies are capped at 16 KiB (413 body_too_large).
  • Header reads and body reads each time out after 10 seconds (body timeout returns 408 body_timeout).
  • Concurrent API connections are capped at SCULKWORM_MAX_API_CONNECTIONS (default 64). Excess connections close immediately.
  • PUT /v1/routes/{host} and POST /v1/routes/{host}/revoke-logins require Content-Type: application/json (parameters such as ; charset=utf-8 are accepted). Any other or missing content type returns 415 unsupported_media_type.
  • Every response carries Cache-Control: no-store, so proxies never cache tenant data.
  • All error responses return Content-Type: application/json with this envelope:
json
{
  "error": {
    "code": "host_out_of_scope",
    "message": "host is outside tenant domain scope"
  }
}

Endpoints#

GET /healthz#

Unauthenticated liveness probe.

sh
curl -sS -i http://127.0.0.1:8080/healthz
text
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-store
content-length: 15
date: Thu, 26 Nov 2026 12:28:43 GMT

{"status":"ok"}

GET /v1/routes#

Lists all dynamic routes (both open and closed) owned by the calling tenant, sorted lexicographically by host. Static routes and other tenants' routes are never included.

sh
curl -sS -i \
  -H "Authorization: Bearer $KEY" \
  http://127.0.0.1:8080/v1/routes
text
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-store
content-length: 120
date: Thu, 26 Nov 2026 12:28:43 GMT

{"routes":[{"host":"survival.play.sculk.network","mode":"open","target":"host.docker.internal:25589","tenant":"sculk"}]}

GET /v1/routes/{host}#

Returns one dynamic route owned by the calling tenant. {host} is percent-decoded and normalized with Domain::parse (lowercased, at most one trailing dot stripped). Returns 404 not_found if the route does not exist, belongs to another tenant, or is defined in SCULKWORM_ROUTES_FILE.

Open route response:

json
{"host":"survival.play.sculk.network","mode":"open","target":"host.docker.internal:25589","tenant":"sculk"}

Closed route response:

json
{"host":"friends.play.sculk.network","mode":"closed","tenant":"sculk","authorizer":{"type":"oauth2","client":"discord-main","allow":{"discord_guild":"1234567890"}},"authorizer_id":"fedcba9876543210","agent_token":{"id":"0123456789abcdef","created_at":"2026-11-27T10:00:00Z"},"agent_connected":false,"active":true}
  • authorizer_id: 16 lowercase hex characters; rotates whenever the normalized authorizer changes.
  • agent_token: {"id","created_at"} or null when no token has been minted. The raw token and its SHA-256 hash are never returned here.
  • agent_connected: live indicator of whether an agent session is attached.
  • active: true when the closed route is usable, or false accompanied by inactive_reason (closed_mode_disabled, unknown_client, or client_tenant_mismatch).

PUT /v1/routes/{host}#

Creates or updates a dynamic route within the calling tenant's domain scope.

Request body (Content-Type: application/json, unknown fields rejected with 400 invalid_json):

Field Required Rules
mode No "open" (default) or "closed". Any other value returns 422 invalid_mode.
target open only Backend address in host:port or [ipv6]:port format with port 1..=65535. Must match the tenant's allowed_targets if configured. On mode: "closed", returns 422 invalid_target (a closed route has no target).
authorizer closed only Authorizer object (type: "oidc", "oauth2", or "fixed-list", plus client, optional scopes, and allow — including {"claim", "any_of"}, {"sculk_server"} for oidc, or {"field", "any_of"} / {"discord_guild"} for oauth2 — or subjects; see Closed routes: authorizer configuration). On mode: "open", returns 422 invalid_authorizer.

max_routes counts open and closed routes together. allowed_targets applies only to open routes. Creating or updating a closed route requires SCULKWORM_TUNNEL_LISTEN (and its companion variables) to be configured; otherwise the endpoint returns 503 closed_mode_disabled. On the public Minecraft port, closed routes answer status pings with the sculkworm.relay status JSON and reject login/transfer attempts with the sculkworm-connect Login Disconnect message (see Closed-route answers).

Responses:

  • 201 Created: route did not exist and was persisted and activated.
  • 200 OK: route already existed for this tenant and was updated, or already had the exact same normalized configuration (idempotent; no state file rewrite occurs and authorizer_id is preserved when unchanged).

Changes are persisted atomically to SCULKWORM_STATE_FILE before updating the in-memory route table. If writing the state file fails, sculkworm returns 500 persist_failed and leaves the in-memory table unchanged.

Create open route example:

sh
curl -sS -i -X PUT \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"target":"host.docker.internal:25589"}' \
  http://127.0.0.1:8080/v1/routes/survival.play.sculk.network

Create closed route example (OIDC claim rule):

sh
curl -sS -i -X PUT \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"closed","authorizer":{"type":"oidc","client":"mock-oidc","scopes":["openid","profile"],"allow":{"claim":"groups","any_of":["minecraft"]}}}' \
  http://127.0.0.1:8080/v1/routes/friends.play.example
text
HTTP/1.1 201 Created
content-type: application/json
cache-control: no-store

{"active":true,"agent_connected":false,"agent_token":null,"authorizer":{"allow":{"any_of":["minecraft"],"claim":"groups"},"client":"mock-oidc","scopes":["openid","profile"],"type":"oidc"},"authorizer_id":"a36e0b5c286c1fd2","host":"friends.play.example","mode":"closed","tenant":"sculk"}

Create closed route example (Discord guild):

sh
curl -sS -i -X PUT \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"closed","authorizer":{"type":"oauth2","client":"discord-main","allow":{"discord_guild":"1234567890"}}}' \
  http://127.0.0.1:8080/v1/routes/friends.play.sculk.network

Create closed route example (sculk.network server membership via OIDC):

sh
curl -sS -i -X PUT \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"closed","authorizer":{"type":"oidc","client":"sculk-main","allow":{"sculk_server":"6uabltcpud3qpiy5"}}}' \
  http://127.0.0.1:8080/v1/routes/friends.play.sculk.network

With allow.sculk_server, the relay automatically adds the sculk:servers scope and admits players whose userinfo sculk_servers array includes an entry with id == "<server id>" and is_player == true. See sculk.network as an authorizer for the full operator guide.

DELETE /v1/routes/{host}#

Deletes a dynamic route owned by the calling tenant. New Minecraft handshakes for {host} are rejected immediately with event=unknown_host, while existing spliced TCP connections remain connected until either side closes.

  • 204 No Content: route deleted and persisted.
  • 404 not_found: route does not exist, belongs to another tenant, or is a static route.

POST /v1/routes/{host}/agent-token#

Mints a new agent token (swa_<16-hex-id>_<base64url-32-bytes>) for a closed route owned by the caller, replacing any previous token. Any currently connected agent session on the route receives GOAWAY revoked and is disconnected immediately. The raw token is returned in this 201 Created response only; the relay stores only the token id, created_at, and the lowercase hex SHA-256 of the full token string.

sh
curl -sS -i -X POST \
  -H "Authorization: Bearer $KEY" \
  http://127.0.0.1:8080/v1/routes/friends.play.example/agent-token
text
HTTP/1.1 201 Created
content-type: application/json
cache-control: no-store

{"token":"swa_0123456789abcdef_<base64url-32-random-bytes>","id":"0123456789abcdef","created_at":"2026-11-27T10:00:00Z"}

Errors: 404 not_found, 409 route_not_closed, 500 persist_failed, 503 closed_mode_disabled.

DELETE /v1/routes/{host}/agent-token#

Revokes the current agent token for a closed route owned by the caller and sends GOAWAY revoked to any live agent session for that route.

  • 204 No Content: token removed and persisted.
  • 404 not_found: route does not exist, belongs to another tenant, or has no token.
  • 409 route_not_closed: route is in open mode.
  • 503 closed_mode_disabled: closed mode is disabled.

GET /v1/agents#

Lists connected agent sessions for the calling tenant's closed routes, sorted by host (and then session). When a replacement agent connects while the previous agent is still draining open player streams after GOAWAY replaced, both sessions appear until the draining session finishes.

sh
curl -sS -i \
  -H "Authorization: Bearer $KEY" \
  http://127.0.0.1:8080/v1/agents
text
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-store

{"agents":[{"connected_at":"2026-11-27T09:06:26Z","host":"friends.play.example","peer":"127.0.0.1:41278","session":"e8ddcfbf3c6af4e2","software":"sculkworm-agent/0.1","streams":0,"token_id":"0d35c60dc471b165"}]}

Returns 503 closed_mode_disabled while SCULKWORM_TUNNEL_LISTEN is unset.

POST /v1/routes/{host}/revoke-logins#

Records a login revocation on a closed route (Content-Type: application/json) and sends GOAWAY revoked (resetting open streams with code 6) to matching live connect sessions:

  • {} sets revoked_before to the current UTC timestamp and returns 200 {"host":"...","revoked_before":"..."}.
  • {"subject":"<id>"} records revoked_subjects[subject] to the current UTC timestamp and returns 200 {"host":"...","subject":"...","revoked_at":"..."}.

Errors: 400 invalid_json, 404 not_found, 409 route_not_closed, 415 unsupported_media_type, 422 invalid_subject (empty or over 255 bytes), 422 too_many_revocations (route already has 10000 revoked subjects), 500 persist_failed, 503 closed_mode_disabled.

Error codes#

Every error code returned by src/api.rs:

HTTP status error.code Extra headers Cause
400 invalid_body — Failed to read the request body stream.
400 invalid_json — Malformed JSON, wrong field type, missing target, or unknown field.
401 unauthorized WWW-Authenticate: Bearer Missing or invalid Authorization: Bearer <key> header.
403 host_out_of_scope — Host is outside the authenticated tenant's configured domains.
404 not_found — Unknown path, route not found, route owned by another tenant, missing agent token on DELETE, or static route on GET/DELETE.
405 method_not_allowed Allow Unsupported HTTP method on an API path.
408 body_timeout — Request body did not finish within 10 seconds.
409 route_is_static — PUT targeted a hostname defined in SCULKWORM_ROUTES_FILE.
409 route_owned_by_other — PUT targeted a dynamic hostname owned by another tenant.
409 route_not_closed — Agent token or login revocation endpoint called on an open route.
413 body_too_large — Request body exceeds 16 KiB.
415 unsupported_media_type — Missing or non-application/json Content-Type header on PUT or POST .../revoke-logins.
422 invalid_host — {host} path segment has invalid percent-encoding, non-UTF-8 bytes, invalid characters (including *: routes match one exact hostname and there are no wildcard routes), length > 255, or normalizes to empty.
422 invalid_mode — mode is neither "open" nor "closed".
422 invalid_target — target is not a valid host:port or [ipv6]:port with port 1..=65535, or target was provided with mode: "closed".
422 invalid_authorizer — Missing, disallowed, malformed, unknown-client, or failed-discovery authorizer (see section 6.4).
422 invalid_subject — subject in revoke-logins is empty or exceeds 255 bytes.
422 target_not_allowed — target does not match any entry in the tenant's allowed_targets.
422 too_many_routes — Creating a new route would exceed the tenant's max_routes limit.
422 too_many_revocations — Route already holds 10000 entries in revoked_subjects.
500 persist_failed — Atomic write of SCULKWORM_STATE_FILE failed; in-memory route table is unchanged.
503 closed_mode_disabled — mode: "closed" or a closed-route endpoint called while SCULKWORM_TUNNEL_LISTEN is unset.

Public HTTPS endpoints (tunnel listener)#

When SCULKWORM_TUNNEL_LISTEN is set, the TLS tunnel listener also serves the public HTTP/1.1 player login and ticket endpoints on ALPN http/1.1 (or no ALPN). Every response carries Cache-Control: no-store; HTML pages carry Content-Security-Policy, X-Content-Type-Options: nosniff, and Referrer-Policy: no-referrer, and JSON errors use the same {"error":{"code","message"}} envelope.

Method and path Auth / input Success Error codes
GET /healthz None 200 {"status":"ok"} 405 method_not_allowed
GET /login/start Query: route, redirect_uri (loopback /callback), state (16–128 base64url chars), code_challenge (43 base64url chars), code_challenge_method=S256 302 to IdP authorize URL 400 HTML, 404 HTML, 429 rate_limited, 503 HTML / busy
GET /login/callback Query from IdP: code, state, or error (plus __Host-swdevcb cookie for device flows) 302 to loopback redirect_uri with one-time swc_ code and state, or 200 HTML result page for device flows (clears __Host-swdevcb) 400 HTML, 403 HTML (not admitted or missing/mismatched __Host-swdevcb), 404 HTML, 503 HTML / busy
POST /login/device JSON {"route"} 200 {"device_code":"swd_...","user_code":"XXXX-XXXX","verification_uri","expires_in":600,"interval":5} 400 invalid_json, 404 unknown_route, 429 rate_limited, 503 busy
GET /login/device None (user_code query parameter ignored) 200 HTML form; sets __Host-swdev cookie (Path=/; Secure; HttpOnly; SameSite=Strict; Max-Age=600) 405 method_not_allowed
POST /login/device/approve Form body (application/x-www-form-urlencoded) user_code, csrf, optional confirm=1 or cancel=1, plus __Host-swdev cookie and Sec-Fetch-Site: same-origin Without confirm: 200 confirmation HTML page with phishing warning. With confirm=1: 302 to IdP (with prompt=consent for OIDC and Discord preset) and sets __Host-swdevcb cookie (SameSite=Lax). With cancel=1: 200 HTML page 403 HTML (cookie, csrf, or Sec-Fetch-Site check failed), 404 HTML (unknown/expired/already-claimed code), 429 HTML (per-IP, per-code, or global miss rate limit), 503 HTML
POST /login/token JSON {"grant_type":"authorization_code","code","code_verifier","redirect_uri"} or {"grant_type":"device_code","device_code"} 200 {"login":"swl_...","route","subject","name","expires_at"} 400 invalid_grant, 400 authorization_pending, 400 slow_down, 400 access_denied, 400 expired_token, 400 invalid_json, 408 body_timeout, 413 body_too_large, 429 slow_down
POST /tickets Authorization: Bearer swl_...; JSON {"route"} 200 {"ticket":"swt_...","expires_in":30} (plus "login":"swl_..." when rotated) 400 invalid_json, 401 login_invalid, 401 login_expired, 401 login_revoked, 403 not_admitted, 404 unknown_route, 409 route_mismatch, 429 rate_limited, 503 idp_unavailable, 503 busy
POST /logout Authorization: Bearer swl_... 204 No Content (persists lid in revoked_logins and kicks live connect sessions for that lid) 401 login_invalid, 429 rate_limited, 503 busy

See Closed routes: login flow and public HTTP endpoints for the full contract.

For configuration variables and the tenants, secrets, and state file schemas, see Configuration. For deployment examples, see Deploying sculkworm.