API Reference
Portal relay exposes one control-plane API. Frontends, SDK clients, peer relays,
and operators all talk to this API, but each group has a small owned surface.
Local agent endpoints under /agent/* are not part of the relay API.
JSON Envelope
Matched JSON control endpoints return this envelope:
{
"ok": true,
"data": {}
} Error responses use the same envelope with error instead of data:
{
"ok": false,
"error": {
"code": "unauthorized",
"message": "unauthorized"
}
} data is omitted on error. error is omitted on success.
The envelope does not apply to streaming or delegated endpoints:
| Path | Format |
|---|---|
/llms.txt | Markdown-formatted plain-text relay and tunnel connection guide |
/sdk/connect | HTTP/1.1 connection hijack |
/v1/sign | keyless TLS signer protocol |
/api/x402/* | relay-owned x402 facilitator response |
/api/install.sh, /api/install.ps1, /api/install/bin/* | script or binary bytes |
Unknown routes may be handled by the frontend fallback or return a normal HTTP 404 outside the envelope.
Auth Schemes
| Name | Used by | How it is sent |
|---|---|---|
| None | public and challenge endpoints | no credential |
| Admin bearer | admin API | Authorization: Bearer <access_token> |
| Lease token header | keyless signer and static cache | X-Portal-Access-Token: <access_token> |
| Reverse capability header | reverse stream | X-Portal-Reverse-Capability: <capability> |
| Lease token body | lease renew/reverse/unregister | JSON field access_token |
| Signed descriptor | relay discovery announce | signed RelayDescriptor body |
The QUIC datagram backhaul carries the lease access token in a JSON message on its first stream, rather than an HTTP header. Cache endpoints can return plain-text HTTP errors for unsupported methods or exhausted request slots.
Admin auth and SDK lease auth issue different tokens and are not interchangeable. SDK lease registration uses SIWE; relay admin access uses the configured admin token.
Endpoint Groups
Public
| Method | Path | Auth | Response |
|---|---|---|---|
GET | / | None | selected SPA index.html |
GET/HEAD | /llms.txt | None | relay and tunnel connection guide |
GET | /api/healthz | None | { "status": "ok" } |
GET | /api/state | None | PublicStateResponse |
GET | /api/services | None | ServiceDiscoveryResponse, optional identity filter |
GET | /api/services/comments?address=0x...&name=... | None | Bounded, read-only remote comments |
POST | /api/reputation/vote | None | reputation summary |
GET/HEAD | /api/install.sh, /api/install.ps1 | None | install script |
GET/HEAD | /api/install/bin/{slug} | None | install binary or redirect |
The reputation vote body is { "hostname": "...", "vote": "up" | "down" | "clear" }. clear removes the caller’s vote; repeating the same action is idempotent.
The response includes vote counts and the caller’s viewer_vote.
Detailed contracts: SDK API and Admin and Policy API.
Public service locations
GET /api/services without query parameters browses observed public services.
An optional EVM address limits results to one owner. With an address, optional name filters one normalized service identity; name= selects the unnamed
service. Results group by both normalized name and address.
The response contains services (name, address, descriptive metadata, locations), partial, relays_checked, and relays_skipped. Each location
contains relay_url, optional preferred url, alias_url, canonical_url, current_relay, reported_ready, observed_at, expires_at, and verification: "relay-reported". A remote location may include reputation: {up, down}; absence is unknown, not zero. Repeated voters across
relays are not deduplicated. Readiness is a relay claim, not a live probe.
Unavailable canonical certificates do not produce canonical links. A location
can still appear without an HTTP URL, for example for a raw TCP service or an
older HTTP lease with only a retired canonical hostname or no hostname at all.
Results are observed public services, never an exhaustive address inventory or cryptographic proof of ownership. Remote metadata is relay-reported; remote thumbnails are omitted. Hidden, expired, malformed, and ineligible entries are excluded. Remote visibility changes can take up to the observation TTL to appear.
Lookup reads the local directory directly, reuses valid eligible relay snapshots, and refreshes a rotating window of at most eight known, verified, eligible public HTTPS relays per request. It does not expand the relay graph. Repeated requests advance through the eligible set rather than always selecting its first entries; this is shared observation coverage, not exhaustive pagination for one search. There are at most four outbound requests across all service lookups, a two-second per-relay deadline starting after slot acquisition and five-second lookup deadline including queue waits, a 1 MiB decoded response limit, 1,000 leases per remote response, and 100 returned service identities. Overflow, failed requests, and expired lookup deadlines produce partial results. Busy request slots wait within the caller’s deadline. Concurrent requests for one relay share its in-flight lookup; pending work is never returned as a cached failure. Caller cancellation is not negative-cached as a remote failure. Observations are cached per relay for 30 seconds, failures for 10 seconds, with at most 32 cache entries. Expired observations are not served on failure; current eligibility is reapplied before returning cached locations. Requests use the Discovery public-IP dialer, disable proxies, and reject redirects.
This endpoint is additive: /discovery, its protocol version, and signed relay
descriptors are unchanged. Older relays can contribute public /api/state entries through validated friendly aliases; legacy one-label canonical URLs
are not promoted to links. A failed remote directory does not change Discovery
health or block the existing local /api/state endpoint.
SDK
GET /sdk/domain keeps protocol_version as the default SDK tunnel contract
for shipped clients with exact-version checks. The optional supported_protocol_versions array is authoritative for newer SDKs: an absent
or null list falls back to exact equality; an empty list accepts no protocols.
Feature support remains separate (namespaces, replicas, cache, and tenant_certificate_issuance). Additive fields do not change old defaults.
New SDKs send their selected protocol_version in POST /sdk/register/challenge; omission retains the default contract.
Unsupported explicit selections return HTTP 426 with protocol_incompatible and instructions to upgrade the SDK or choose a compatible relay. A requested
Local TLS namespace requires explicit support and is never silently downgraded.
The current relay reports default 10 and supported ["10"], preserving
main’s protocol negotiation behavior. SDK v2.7.3 and v2.7.4 pass the version
check but require the removed canonical response field during registration.
Their registration limitation remains; see the rollout instructions.
Discovery protocol versions and signed descriptors have separate contracts.
| Method | Path | Auth | Body | Response |
|---|---|---|---|---|
GET | /sdk/domain | None | none | DomainResponse |
POST | /sdk/register/challenge | None | RegisterChallengeRequest | RegisterChallengeResponse |
POST | /sdk/register | SIWE signature body | RegisterRequest | RegisterResponse |
POST | /sdk/renew | lease token body | RenewRequest | RenewResponse |
POST | /sdk/reverse | lease token body | ReverseEndpointRequest | ReverseEndpoint |
POST | /sdk/unregister | lease token body | UnregisterRequest | {} |
GET | /sdk/connect | reverse capability header | none | hijacked stream |
POST | /sdk/cache | lease token header | StaticCacheManifest JSON | StaticCacheStatus |
PUT | /sdk/cache | lease token header | manifest and file bytes as multipart | StaticCacheStatus |
DELETE | /sdk/cache | lease token header | none | StaticCacheStatus |
POST | /v1/tenant-certificate | lease token header | TenantCertificateRequest | TenantCertificateResponse |
Admin
| Method | Path | Auth | Body | Response |
|---|---|---|---|---|
POST | /api/admin/auth/login | None | AdminAuthLoginRequest | AdminAuthLoginResponse |
GET | /api/admin/auth/status | Optional admin bearer | none | AdminAuthStatusResponse |
POST | /api/admin/auth/logout | Admin bearer | none | {} |
/admin itself is a frontend route, not a relay API endpoint.
Payments
Relay /api/x402/* endpoints are optional relay-owned control-plane
facilitator endpoints. Enable them with X402_ENABLED=true when a relay
operator wants to reserve support for relay resources such as future tunnel
registration fees, lease renewal fees, raw TCP/UDP port allocation, or premium
capacity. They are served by the embedded gosuda/x402-facilitator handler and
do not use the Portal JSON envelope. Portal selects Sui mainnet by default and
Sui testnet when X402_TESTNET=true. Portal accepts only USDC gasless
stablecoin address-balance payments. X402_PAY_TO is the relay-owned payment
recipient.
Relay x402 settings do not affect tunnel paid routes. Tunnel payment recipients and payment networks are local tunnel configuration and are not part of the relay lease API.
Paid routed HTTP tunnels additionally expose /x402/prepare and /x402/client.js on the public tunnel origin. Those are tunnel-owned helper
endpoints for app frontends, not relay API routes, and they do not use the /api prefix. /x402/client.js and the transaction-building prepare response
are Sui-only. Casper clients consume the protected resource’s 402 requirements,
sign with an external Casper x402 SDK, and retry with PAYMENT-SIGNATURE or X-PAYMENT; Portal then delegates verification and settlement to the configured
Casper facilitator.
| Method | Path | Auth | Body | Response |
|---|---|---|---|---|
GET | /api/x402/supported | None | none | x402 supported kinds |
POST | /api/x402/verify | None | x402 verify request | x402 verify response |
POST | /api/x402/settle | None | x402 settle request | x402 settle response |
Policy
| Method | Path | Auth | Body | Response |
|---|---|---|---|---|
GET | /api/policy | Admin bearer | none | PolicySettings |
POST | /api/policy | Admin bearer | PolicySettings | PolicySettings |
GET | /api/policy/state | Admin bearer | none | PolicyStateResponse |
POST | /api/policy/leases | Admin bearer | LeasePolicyUpdate | {} |
Relay
| Method | Path | Auth | Response |
|---|---|---|---|
GET | /discovery | None | DiscoveryResponse |
POST | /discovery/announce | Signed descriptor | DiscoveryAnnounceResponse |
POST | /v1/sign | Lease token header | keyless signer response |
Observed remote comments
GET /api/services/comments?address=0x...&name=... reads public comments for
one service identity. It observes at most eight eligible relays with fresh
locations and returns one bounded sample of at most 20 recent rows per source,
newest first. There is no pagination; each request is a new live observation,
not a stable global snapshot. Each row contains relay_url, id, text, created_at and optional deleted. Treat IDs
and timestamps as source claims. Partial coverage is explicit; the endpoint
does not accept writes or forward visitor credentials.
Origins return the service address and name alongside their comment list;
the reader checks both against the requested identity. Legacy responses without
identity are accepted only through an identity-bound canonical hostname. Alias
comments from those origins are skipped with partial coverage because cached
alias ownership cannot bind comments across an ownership change.
The overall deadline is 22 seconds, including directory discovery and slot
waits; each remote fetch has a two-second timeout after acquiring a slot.
Shared Types
Timestamps are JSON-encoded Go time.Time values.
Identity:
| Field | Type | Notes |
|---|---|---|
name | string | DNS label used by the lease |
address | string | Ethereum address |
LeaseMetadata:
| Field | Type | Notes |
|---|---|---|
description | string | optional |
owner | string | optional |
thumbnail | string | optional URL or data value |
tags | string[] | optional |
hide | boolean | hidden leases are omitted from the public state |
Lease:
| Field | Type |
|---|---|
name | string |
address | string |
expires_at, first_seen_at, last_seen_at | string |
hostname, canonical_hostname | string |
namespace | string, optional; local-tls-v1 selects the new canonical policy |
canonical_ready | boolean, optional; Local TLS material availability, not reverse transport count |
udp_enabled, tcp_enabled | boolean |
tcp_addr | string |
metadata | LeaseMetadata |
ready | number |
For local-tls-v1, only advertise the canonical as usable when canonical_ready is true and ready is positive. Otherwise use an available
friendly URL as a separate origin. For legacy namespaces, ready retains its existing meaning. The hostname fields identify routes even while
their endpoints are unavailable.
PolicyLease extends Lease with:
| Field | Type |
|---|---|
lease_id | string |
identity_key | string |
bps | number |
client_ip, reported_ip | string |
is_approved, is_banned, is_denied | boolean |
explicitly_approved | boolean (saved identity decision, independent of auto approval) |
PublicStateResponse:
| Field | Type |
|---|---|
leases | Lease[] |
PolicyStateResponse:
| Field | Type |
|---|---|
policy | PolicySettings |
leases | PolicyLease[] |
pending | Optional array of authenticated requests. Each contains identity_key, first_seen_at, last_seen_at, and expires_at. |
PolicyPortSettings:
| Field | Type | Notes |
|---|---|---|
enabled | boolean | enables the transport |
max_leases | number | 0 means unlimited |
PolicySettings:
| Field | Type |
|---|---|
approval_mode | "auto" or "manual" |
udp | PolicyPortSettings |
tcp_port | PolicyPortSettings |
LeasePolicyUpdate:
| Field | Type | Notes |
|---|---|---|
identity_key | string | normalized name:address key |
is_banned | boolean | optional |
is_approved | boolean | optional |
is_denied | boolean | optional; true also revokes approval |
bps | number | optional individual bytes/second override; 0 explicitly permits unlimited traffic; omission preserves the setting |
reset_bps | boolean | true removes the override and restores the relay default; cannot be combined with bps |
DiscoveryResponse:
| Field | Type | Notes |
|---|---|---|
protocol_version | string | discovery protocol version of the serving relay |
generated_at | string | when the response was generated |
relays | RelayDescriptor[] | signed, routable relay descriptors |
incompatible_relays | IncompatibleRelayEntry[] | optional; relays contacted directly whose discovery protocol version differs |
release_version | string | optional; release of the serving relay itself |
relay_release_versions | map (peer URL → release) | optional; releases directly observed from each peer’s own /discovery |
release_version and relay_release_versions are optional, unsigned observation metadata: they never affect routing, trust, signature verification, or compatibility, and older relays omit them. Signed relay identity stays in RelayDescriptor.
Common Errors
| Code | Meaning |
|---|---|
invalid_json | request body is not valid JSON |
invalid_request | request shape or value is invalid |
method_not_allowed | endpoint does not accept the method |
unauthorized | credential is missing, expired, or invalid |
feature_unavailable | feature is unavailable; automatic tenant ACME errors may be temporary |
protocol_incompatible | explicit SDK protocol selection is unsupported; HTTP 426, upgrade the SDK or choose a compatible relay |
tenant_issuance_disabled | the relay does not offer automatic tenant certificate issuance |
tenant_issuance_not_approved | the service lacks explicit approval for automatic tenant certificate issuance |
rate_limited | request was throttled |
hostname_conflict | canonical hostname is inconsistently bound; routing fails closed |
replica_conflict | a replica cannot join a live exclusive lease or retained cache entry; retryable |
lease_not_found | lease token or identity has no active lease |
lease_rejected | lease is not approved to route yet |
approval_queue_full | signed registration could not be queued; retry after the supplied delay |
lease_denied | relay denied or banned the lease |
source_not_allowed | relay does not accept tunnels from the caller’s network |
invalid_address | address path or body value is invalid |
invalid_mode | approval mode is not auto or manual |
http11_only | endpoint requires HTTP/1.1 |
hijack_unsupported, hijack_failed | reverse stream setup failed |
udp_disabled, udp_capacity_exceeded, udp_port_exhausted | UDP lease cannot be allocated |
tcp_port_disabled, tcp_port_capacity_exceeded, tcp_port_exhausted | TCP port lease cannot be allocated |
transport_mismatch | request does not match the active lease transport |
internal | unexpected server failure |
Go Tenant TLS API
sdk.WithAutomaticTLS(stateDir, requireLocal) opts into exact per-hostname
CSR issuance, persistence, and renewal. stateDir is required at the SDK level;
the CLI/agent resolve their identity-based defaults before calling it. Private
leaf keys stay in that directory and are reused across restarts and renewals.
Both automatic TLS modes require a namespace-capable relay. With requireLocal = false, a granted alias can satisfy WaitReady while issuance
is pending. With it enabled, WaitReady waits for a usable canonical certificate. Public issuance needs relay opt-in, explicit service
approval, and durable shared budgets; see the issuance endpoint contract.
sdk.WithTLSCertificate(certFile, keyFile) selects manual local signing for
native, uncached HTTPS exposures. sdk.Expose reads and validates the pair
before registering with any relay. Missing, malformed, mismatched, expired,
or unsupported certificate material returns an error immediately. It never
falls back to relay-backed signing.
Automatic and manual modes are mutually exclusive, require the native runtime,
and reject raw TCP. The CLI/agent additionally reject UDP with Local TLS.
At the lease-protocol level any cache opt-in remains on the separate
friendly alias; the canonical is never cache eligible. Manual mode requires
a namespace-capable relay. sdk.RunHTTP enables canonical HTTP/2 with an actual
HTTP consumer; raw Expose/Proxy callers retain HTTP/1.1 and do not gain h2
translation.
The certificate must cover only the exact Local TLS canonical hostname assigned
by a selected relay. Friendly URLs still use Keyless. A coverage
failure stops that relay’s listener and appears in Exposure.Relays() with RelayFailureTerminal and an error wrapping localtls.ErrLocalCertificate;
covered relays remain usable. Ordinary network failures remain retryable. Discovery applies its existing terminal-failure
backoff policy and can select other relays.
Exposure.WaitReady reports when a relay can route traffic. With automatic TLS
and no require-local option, a granted alias can be ready while the new
canonical PublicURL remains empty. With require-local, WaitReady requires a
usable canonical certificate. If every selected relay has failed terminally or
refuses the required issuance, it returns the current errors. Issuance policy
refusals are also available in RelayStatus.CertificateError, without disabling
live aliases or an already valid canonical certificate. The exposure remains
open for policy recovery or another compatible relay.
Certificate installation and expiry update the same SDK status used by Relays(), Updates(), WaitReady(), and JSON lifecycle records. The records
include alias_url separately from the usable canonical public_url.
For local-tls-v1 public leases, canonical_ready reports usable local material; ready continues to count reverse transport connections. The tunnel reports local_tls_not_after through authenticated lease renewal on certificate changes,
and the relay withdraws canonical_ready at that expiry even without another
renewal. This is an owner-reported availability hint, not certificate validation
or identity proof. Friendly URLs remain separate compatibility origins.
Go source compatibility: direct users of portal/keyless.Client must
replace RelayCertPool() with TenantCertPool(). The returned snapshot trusts
the tenant certificate, not the relay control API. Use TenantTLSConfig() for
tenant probes that must keep working across certificate rotation, and keep
relay control-plane TLS trust separate. The old method name is not retained.