If an OKX private call fails, the response body almost always carries a five-digit code starting with 501. Each one points at a different part of the request, so reading the code first saves a lot of guessing about keys and secrets.
| Code | What OKX is telling you | First thing to check |
|---|---|---|
| 50101 | The API key does not match the current environment | Demo key without the demo header, or a live key with it |
| 50102 | Timestamp request expired | Your machine’s clock, and how long the request sat in a queue after signing |
| 50104 / 50105 | Passphrase missing / passphrase incorrect | You sent the passphrase set when the key was created, not your login password |
| 50110 | Your IP is not on the key’s whitelist | The real egress IP of the server or proxy |
| 50111 | Invalid OK-ACCESS-KEY | The key string itself (stray spaces, a deleted key) |
| 50112 | Invalid OK-ACCESS-TIMESTAMP | The timestamp format: ISO 8601 with milliseconds, e.g. 2026-11-10T12:00:00.000Z |
| 50113 | Invalid signature | The prehash string and the bytes you actually sent |
| 50119 | The API key does not exist | Usually a regional mismatch: an EEA or US key sent to the global domain |
| 50120 | The key has no permission for this function | Add the Trade (or Read) permission to the key |
50113: invalid signature
OKX signs timestamp + METHOD + requestPath + body with HMAC-SHA256 and Base64. The usual slips:
- Leaving the query string out of
requestPathon a GET, or encoding it differently from the URL you request. - Signing one JSON string and letting the HTTP client serialise the body again.
- Lowercase method names, or a hex digest where Base64 is expected.
- Using a different timestamp in the signature from the one sent in
OK-ACCESS-TIMESTAMP.
50101: demo key, live environment (or the other way round)
Demo trading keys are created separately, inside Demo Trading, and every demo request must carry x-simulated-trading: 1. A live key with that header, or a demo key without it, returns 50101. The key is fine; the environment is not.
50119: the key “does not exist”
If the key definitely exists, check where it was created. Keys from my.okx.com (EEA) or app.okx.com (US) are not valid on the global www.okx.com API, and the reverse is also true.
Let the SDK handle the request details
Most of these codes come from hand-built requests. The okx-api package (MIT, Node.js, JavaScript and TypeScript) builds and signs each request, sets the timestamp format, adds the demo header when you ask for demo trading, and routes to the right regional domain. Disclosure: we maintain this SDK.
npm install okx-api
import { RestClient } from 'okx-api';
const client = new RestClient({
apiKey: process.env.OKX_API_KEY,
apiSecret: process.env.OKX_API_SECRET,
apiPass: process.env.OKX_API_PASS, // the passphrase set when you created the key
demoTrading: true, // demo key? the SDK adds x-simulated-trading: 1 for you
// market: 'EEA', // key created on my.okx.com
// market: 'US', // key created on app.okx.com
});
async function main() {
// Public, no key needed: compare with Date.now() if you see 50102
const serverTime = await client.getServerTime();
console.log('clock drift (ms):', Date.now() - serverTime);
try {
const balances = await client.getBalance();
console.log(JSON.stringify(balances, null, 2));
} catch (e: any) {
// OKX error bodies look like {"msg":"Invalid OK-ACCESS-KEY","code":"50111"}
console.error('OKX error:', e?.body ?? e);
}
}
main();
A made-up key returns {"msg":"Invalid OK-ACCESS-KEY","code":"50111"} in e.body, so you can branch on the code instead of parsing messages.
Private WebSocket channels use the same rules. Pass the key as an account and set demoTrading there too:
import { WebsocketClient } from 'okx-api';
const ws = new WebsocketClient({
accounts: [
{
apiKey: process.env.OKX_API_KEY!,
apiSecret: process.env.OKX_API_SECRET!,
apiPass: process.env.OKX_API_PASS!,
},
],
demoTrading: true,
});
ws.on('update', (data) => console.log(JSON.stringify(data)));
ws.on('exception', (err) => console.error('ws error', err));
ws.subscribe({ channel: 'account' });
A quick checklist
- Read the code, not just the HTTP status.
- 50101 or 50119: match the key to its environment (demo or live) and region.
- 50102 or 50112: sync the clock with NTP and sign right before sending.
- 50105: use the key’s passphrase.
- 50113: stop hand-signing, or compare your prehash string byte for byte with the request.
More on the SDK: the OKX JavaScript SDK quickstart and the OKX API JavaScript tutorial for Node.js and TypeScript.

