← All articles

Bitget API 40009 “sign signature error” and other auth codes in Node.js

If a Bitget private call fails with {"code":"40009","msg":"sign signature error"}, Bitget rebuilt the signature from your headers and body and got a different answer. The key is usually fine. Something in the bytes you signed differs from the bytes you sent.

Bitget’s auth errors sit next to each other, so treat them as a checklist:

Code What Bitget is telling you First thing to check
40006 Invalid ACCESS-KEY The key string itself (spaces, wrong key, deleted key)
40008 Request timestamp expired Your machine clock vs getServerTime, and how long the request sat after signing
40009 Sign signature error The prehash string, and whether you URL-encoded the query or body before signing
40012 API key or passphrase incorrect The passphrase you chose when creating the key (not your login password)
40037 Apikey does not exist A typo, a revoked key, or a demo/live mismatch

Why 40009 happens

Bitget signs timestamp + METHOD + requestPath + body with HMAC-SHA256 and Base64. The usual slips:

  • URL-encoding the query string or JSON body before you sign it (Bitget’s own docs call this out, especially when coin names contain non-ASCII characters).
  • Signing one JSON string and letting the HTTP client serialise the body again with different spacing or key order.
  • Leaving the query string out of requestPath on a GET, or encoding it differently from the URL you send.
  • Using a hex digest where Base64 is expected, or a different timestamp in the signature from ACCESS-TIMESTAMP.

Why 40008 happens

Bitget rejects timestamps that drift too far from server time. Compare Date.now() with the public server time endpoint before you dig into signing. A slow queue after you sign can also push a request past the window.

Why 40037 and 40012 happen

40037 means Bitget does not recognise the key at all (typo, revoked, or the wrong environment). 40012 usually means the passphrase is wrong: it is the string you set when you created the API key, not your account password.

Demo trading vs live

Demo trading uses separate keys and a different base path. Mixing a live key with demo headers (or the reverse) often shows up as a missing or invalid key rather than a clean “wrong environment” message, so check which key you created and which client flag you set.

Let the SDK handle the request details

Most of these codes come from hand-built requests. The bitget-api package (MIT, Node.js, JavaScript and TypeScript) builds and signs each REST request, keeps the timestamp in sync, and can target demo trading when you ask for it. Disclosure: we maintain this SDK.

npm install bitget-api
import { RestClientV2 } from 'bitget-api';

const client = new RestClientV2({
  apiKey: process.env.BITGET_API_KEY,
  apiSecret: process.env.BITGET_API_SECRET,
  apiPass: process.env.BITGET_API_PASS, // passphrase set when you created the key
  // demoTrading: true, // demo key? enable Bitget demo trading
});

async function main() {
  // Public, no key needed: compare with Date.now() if you see 40008
  const serverTime = await client.getServerTime();
  console.log('server time:', serverTime);

  try {
    const account = await client.getSpotAccountInfo();
    console.log(JSON.stringify(account, null, 2));
  } catch (e: any) {
    // Bitget error bodies look like {"code":"40037","msg":"Apikey does not exist","data":null}
    console.error('Bitget error:', e?.body ?? e);
  }
}

main();

Related reading