Required request headers
Every request (except /v1/health) must carry these four headers. If any is missing or invalid, the server rejects with HTTP 401.
| Header | Format | Description |
|---|---|---|
KH-Key | kh_live_[A-Z0-9]{32} | Public key identifier. Not a secret, may appear in logs. |
KH-Timestamp | Unix seconds (10 digits) | Current timestamp. Tolerance window +-300s. |
KH-Nonce | 22-44 base64url chars | Single-use value per request. Cached for 600s, then reusable. |
KH-Signature | 64 hex | HMAC-SHA256(secret, signing_string), hex-encoded. |
Building the signing string
The string to sign is composed of five components joined by newline (\n).
signing_string = METHOD + "\n"
+ PATH + "\n"
+ TIMESTAMP + "\n"
+ NONCE + "\n"
+ SHA256_HEX(BODY)
signature = HEX( HMAC_SHA256(secret, signing_string) )
PATH includes the full request path including query string, but no host or fragment. BODY is the raw body bytes; for GET/DELETE without a body, BODY is the empty string whose SHA256 is the well-known constant e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.
Reference implementations
PHP:
$method = 'POST';
$path = '/v1/orders';
$body = json_encode(['product_id' => 42, 'billing_cycle' => 'monthly']);
$ts = (string) time();
$nonce = bin2hex(random_bytes(16));
$signing = "{$method}\n{$path}\n{$ts}\n{$nonce}\n" . hash('sha256', $body);
$sig = hash_hmac('sha256', $signing, $KH_SECRET);
$ch = curl_init('https://www.kernelhost.com/cp/kh_reseller_api/v1/orders');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
"KH-Key: {$KH_KEY}",
"KH-Timestamp: {$ts}",
"KH-Nonce: {$nonce}",
"KH-Signature: {$sig}",
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
],
]);
$res = curl_exec($ch);
Node.js:
import crypto from 'crypto';
const method = 'POST';
const path = '/v1/orders';
const body = JSON.stringify({ product_id: 42, billing_cycle: 'monthly' });
const ts = Math.floor(Date.now() / 1000).toString();
const nonce = crypto.randomBytes(16).toString('hex');
const bodyHash = crypto.createHash('sha256').update(body).digest('hex');
const signing = `${method}\n${path}\n${ts}\n${nonce}\n${bodyHash}`;
const sig = crypto.createHmac('sha256', KH_SECRET).update(signing).digest('hex');
const res = await fetch('https://www.kernelhost.com/cp/kh_reseller_api/v1/orders', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'KH-Key': KH_KEY,
'KH-Timestamp': ts,
'KH-Nonce': nonce,
'KH-Signature': sig,
'Idempotency-Key': crypto.randomBytes(16).toString('hex'),
},
body,
});
Replay protection
A successfully signed request CANNOT be replayed. The server stores every nonce for 600s in the database; a second request with the same nonce is rejected with replay_detected. Likewise a request whose timestamp deviates more than 300s from server time is rejected.
Scope model
Each key has an explicit scope list. Routes check the required scope; if missing, HTTP 403 forbidden_scope. Writing and sensitive scopes must be explicitly enabled at key creation.
read:products,read:orders,read:services,read:billing,read:webhooksread:credentials(Reading service credentials (root passwords, FTP, VNC). Produces an extra audit entry credentials.read per call.)write:orders(Place and pay orders.)write:services(Run service actions (start/stop/reboot/reinstall/terminate).)write:webhooks(Set webhook URL.)

