← All articles

KuCoin API 400005 “Invalid KC-API-SIGN” and other auth errors in Node.js: what each code means

If your KuCoin integration returns {"code":"400005","msg":"Invalid KC-API-SIGN"}, KuCoin rebuilt the signature from your request and got a different answer. The key is usually fine. Something in the bytes you signed differs from the bytes you sent, or one of the other auth headers is wrong.

KuCoin’s authentication errors sit next to each other, so it helps to read them as a checklist:

Code What KuCoin is telling you First thing to check
400002 KC-API-TIMESTAMP is invalid or too far from server time Your machine’s clock (compare with the public server time)
400003 The API key does not exist, or the site does not match (KuCoin’s own wording) The key itself, and whether it belongs to the region you are calling
400004 KC-API-PASSPHRASE is invalid You sent the API passphrase you chose when creating the key, signed for key version 2
400005 KC-API-SIGN is invalid The prehash string: timestamp, uppercase method, path with query, exact JSON body
400006 Your IP is not on the key’s whitelist The egress IP of the server or proxy actually making the call

Why 400005 happens

KuCoin signs timestamp + METHOD + endpoint + body with HMAC-SHA256 and Base64. The common slips are:

  • Signing GET for a request that is really a POST, or using lowercase post.
  • Leaving the query string out of the signed path on a GET, or URL-encoding it differently from what you sign.
  • Calling JSON.stringify once for the signature and letting your HTTP client serialise the body again with different spacing or key order.
  • Using a hex digest where Base64 is expected.

Why 400004 happens

Two things trip people up. The passphrase is the one you typed when you created the API key, not your account login or trading password. And with key version 2 (the default today), KC-API-PASSPHRASE is not sent as plain text: it is HMAC-SHA256 of the passphrase with your secret, Base64-encoded, and KC-API-KEY-VERSION must say 2.

Let the SDK do the signing

Hand-rolled signing is where nearly all of these errors start. The kucoin-api package (MIT, Node.js, JavaScript and TypeScript) builds the prehash string, signs the body it actually sends, signs the passphrase for version 2 keys and adds the region header when needed. Disclosure: we maintain this SDK.

npm install kucoin-api
import { SpotClient } from 'kucoin-api';

const client = new SpotClient({
  apiKey: process.env.KUCOIN_API_KEY!,
  apiSecret: process.env.KUCOIN_API_SECRET!,
  // The passphrase you set when creating the key, not your account password
  apiPassphrase: process.env.KUCOIN_API_PASSPHRASE!,
  // Optional: defaults to '2'. Check the version on KuCoin's API management page
  apiKeyVersion: '2',
  // Optional: 'global' (default), 'EU' or 'AU'. Use the region the key was created on
  apiRegion: 'global',
});

async function checkAuth() {
  // Public call, no signature: compare KuCoin's clock with yours (rules out 400002)
  const serverTime = await client.getServerTime();
  console.log('Clock drift (ms):', Date.now() - serverTime.data);

  // Signed, read-only call: if this works, your key, secret, passphrase and IP are fine
  const summary = await client.getAccountSummary();
  console.log('Auth OK:', summary.code);

  const balances = await client.getBalances();
  console.log('Accounts:', balances.data.length);
}

checkAuth().catch((e) => {
  // On auth failures the SDK throws an object with KuCoin's response in e.body,
  // e.g. { code: '400003', msg: 'The API key does not exist or site mismatch.' }
  console.error('KuCoin request failed:', e.body ?? e);
});

Start with a read-only call like this before you touch orders. If it passes, any later 400005 on an order is about that request’s parameters, not your credentials.

If it still fails

  • 400002 with a clean clock: check that the process is not reusing a timestamp captured at startup. The SDK creates a fresh one per request.
  • 400003 on a valid key: EU and Australian keys need apiRegion: 'EU' or apiRegion: 'AU'. Futures calls go through FuturesClient, which takes the same credentials.
  • 400006: whitelist the IP your requests leave from. Behind a proxy or in a container platform that is not your laptop’s IP.
  • Still 400004: create a fresh key and copy the passphrase carefully. It cannot be recovered later.

The full walkthrough, from install to a test order that never reaches the matching engine, WebSocket streams and regional hosts, is the KuCoin API JavaScript tutorial for Node.js. The SDK overview and method reference live in the KuCoin JavaScript SDK docs, and if you work with several exchanges, the general guide to debugging exchange request signatures covers the same problem across venues.