Guide
Authentication
HMAC-SHA256 request signing — every request, every time.
Every API request is signed with HMAC-SHA256. This proves you hold the secret and that the request hasn't been tampered with.
Required Headers
Every request needs these five headers:
| Header | Value |
|---|---|
X-Key-Id | Your API key ID (ak_test_... / ak_live_...) |
X-Timestamp | ISO-8601 UTC timestamp |
X-Nonce | Unique string per request (UUID works) |
X-Body-Hash | SHA-256 hex of the request body |
X-Signature | Base64-encoded HMAC-SHA256 signature |
How to Sign
1. Build the canonical string
Six values, joined by newlines:
{METHOD}\n{PATH}\n{SORTED_QUERY}\n{TIMESTAMP}\n{NONCE}\n{BODY_HASH}
| Part | Rules |
|---|---|
| METHOD | Uppercase: POST, GET |
| PATH | Leading /, no trailing / |
| SORTED_QUERY | Query params sorted by key (ASCII). Empty string if none. |
| TIMESTAMP | Same as X-Timestamp header |
| NONCE | Same as X-Nonce header |
| BODY_HASH | SHA-256 hex of body. No body = SHA-256 of empty string |
2. Sign it
signature = base64( hmac_sha256( base64_decode(secret), canonical_string ) )
Your secret is Base64-encoded. Decode it first, then use it as the HMAC key.
3. Send it
Include all five headers. Done.
Timestamps must be within 5 minutes of the server time. Each nonce can only be used once. This prevents replay attacks.
Example
POST/v1/checkout-sessions with body {"mode":"payment","amount":5000,"currency":"USD"}:
Code
1POST2/v1/checkout-sessions342026-04-07T18:30:00.000Z5550e8400-e29b-41d4-a716-4466554400006a3f2b8c1... ← SHA-256 hex of body
The empty third line = no query parameters.
Code Examples
Node.js
JavaScript
1import crypto from "crypto";23function signRequest({ method, path, body, keyId, secret }) {4 const timestamp = new Date().toISOString();5 const nonce = crypto.randomUUID();6 const bodyStr = body ? JSON.stringify(body) : "";7 const bodyHash = crypto.createHash("sha256").update(bodyStr).digest("hex");89 const canonical = [method, path, "", timestamp, nonce, bodyHash].join("\n");1011 const sig = crypto12 .createHmac("sha256", Buffer.from(secret, "base64"))13 .update(canonical)14 .digest("base64");1516 return {17 "Content-Type": "application/json",18 "X-Key-Id": keyId,19 "X-Timestamp": timestamp,20 "X-Nonce": nonce,21 "X-Body-Hash": bodyHash,22 "X-Signature": sig,23 };24}
Python
Python
1import hashlib, hmac, base64, json2from datetime import datetime, timezone3from uuid import uuid445def sign_request(method, path, body, key_id, secret):6 timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")7 nonce = str(uuid4())8 body_str = json.dumps(body) if body else ""9 body_hash = hashlib.sha256(body_str.encode()).hexdigest()1011 canonical = f"{method}\n{path}\n\n{timestamp}\n{nonce}\n{body_hash}"1213 sig = base64.b64encode(14 hmac.new(base64.b64decode(secret), canonical.encode(), hashlib.sha256).digest()15 ).decode()1617 return {18 "Content-Type": "application/json",19 "X-Key-Id": key_id,20 "X-Timestamp": timestamp,21 "X-Nonce": nonce,22 "X-Body-Hash": body_hash,23 "X-Signature": sig,24 }
PHP
PHP
1function signRequest(string $method, string $path, ?array $body, string $keyId, string $secret): array {2 $timestamp = gmdate('Y-m-d\TH:i:s.000\Z');3 $nonce = bin2hex(random_bytes(16));4 $bodyStr = $body ? json_encode($body) : '';5 $bodyHash = hash('sha256', $bodyStr);67 $canonical = implode("\n", [$method, $path, '', $timestamp, $nonce, $bodyHash]);89 $sig = base64_encode(hash_hmac('sha256', $canonical, base64_decode($secret), true));1011 return [12 'Content-Type' => 'application/json',13 'X-Key-Id' => $keyId,14 'X-Timestamp' => $timestamp,15 'X-Nonce' => $nonce,16 'X-Body-Hash' => $bodyHash,17 'X-Signature' => $sig,18 ];19}