authentication
Perpl authenticates programmatic clients (bots, terminals, scripts) with API keys. An API key is an Ed25519 key pair — the server only ever stores the public key, and the private key never leaves your machine. There is no bearer token or session cookie to leak: every request is signed with the key's private key.
This page covers how to sign requests with a key you already have. To obtain a key, see Creating a key below.
Creating a key
Web UI — connect your wallet and create a key at mainnet https://app.perpl.xyz/apikeys or testnet https://testnet.perpl.xyz/apikeys. The UI hands you the
X-API-Keytoken and the private key.Programmatically — third-party integrations (e.g. trading terminals) can enroll keys directly. See Integrations for the wallet-signed enrollment flow.
Either way, you end up with two things, which the snippets below read from the environment (as the examples do):
API_KEY(fromPERPL_API_KEY) — the opaqueX-API-Keytoken.privateKey(fromPERPL_API_KEY_SECRET, hex of the 32-byte key) — the Ed25519 private key.
A key carries a scope (read, trade, or both; trade implies read). Withdrawals and transfers-out are never permitted via an API key. Scopes are chosen at enrollment — see Integrations → Scopes.
Authenticating REST requests
Sign a canonical string with the key and send four headers. No cookies.
The canonical string is these six fields joined by \n (newline):
<chain_id>
<HTTP_METHOD> e.g. GET, POST
<request-target> path + query string exactly as sent, e.g. /v1/trading/fills?count=100
<timestamp_ms> unix epoch milliseconds, decimal
<nonce> client-random, base64url (no padding)
<sha256(body) hex> hex of SHA-256 over the raw request body ("" body → sha256 of empty string)The signature is base64url(ed25519_sign(privateKey, canonical)) (base64url, no padding), sent in X-API-Signature.
X-API-Key
the opaque token from enrollment
X-API-Timestamp
timestamp_ms used in the canonical string
X-API-Nonce
nonce used in the canonical string
X-API-Signature
base64url(ed25519 signature)
WebSocket authentication
For the trading WebSocket (/ws/v1/trading), authenticate by sending an ApiKeySignIn frame (mt: 29) as the first message after the socket opens.
The signature covers the WS canonical string — four fields joined by \n:
A trade-scoped key may place orders over the socket; a read-scoped key receives snapshots/updates but order requests are rejected with close/status 403.
Signature validity and errors
Timestamp window:
X-API-Timestampmust be within 30 seconds of server time. Keep the client clock in sync.Nonce: single-use within the validity window — generate a fresh random
nonceper request (replays are rejected).Expiry / IP: requests are rejected once the key is past
expires_at, or when anip_cidrsallow-list is set and the caller's IP is not covered.
401
Missing/invalid headers, bad or stale signature, replayed nonce, revoked/expired key, IP not allowed
Re-sign with a fresh timestamp + nonce; check clock, key status and source IP
403
Scope insufficient (e.g. read key attempting to trade)
Enroll a trade-scoped key
WS 3401
WebSocket authentication failure
Re-send a fresh signed ApiKeySignIn frame and reconnect