← All articles

Binance API -2015 “Invalid API-key, IP, or permissions for action” in Node.js: a checklist

Binance returns -2015 when it won’t accept the API key for the request you just made. The message, “Invalid API-key, IP, or permissions for action.”, bundles three different problems into one code, which is why it’s so annoying to debug. This guide goes through each cause in the order they usually show up, using the Binance JavaScript SDK (binance on npm) to check them from Node.js.

What the error looks like

With the SDK, a rejected key surfaces as a thrown error you can inspect directly:

const { MainClient } = require('binance');

const client = new MainClient({
  api_key: process.env.BINANCE_API_KEY,
  api_secret: process.env.BINANCE_API_SECRET,
});

client
  .getAccountInformation()
  .then(console.log)
  .catch((e) => console.error(e.code, e.message));
// -2015 Invalid API-key, IP, or permissions for action.

The error object carries code, message, the raw body from Binance and the response headers, so you can log exactly what came back without parsing anything yourself.

1. The key is wrong, or for a different environment

This is the most common cause by far:

  • The key or secret has a stray space or newline from copy and paste, or an environment variable that isn’t loaded (check process.env.BINANCE_API_KEY?.length, a Binance HMAC key is 64 characters).
  • The key was deleted or regenerated in API Management and your app still has the old one.
  • The key belongs to a different environment. Spot testnet, futures testnet and demo trading keys don’t work on live endpoints, and live keys don’t work on test endpoints. In the SDK, pass testnet: true or demoTrading: true only when the key was created for that environment.
  • The key was created on a regional Binance site (for example Binance.US or Binance TR) but you’re calling binance.com, or the other way round.

2. The request IP isn’t on the key’s whitelist

If the key has “Restrict access to trusted IPs only” switched on, every request must come from a listed IP. Things that quietly break this:

  • Your server’s outbound IP changed (a redeploy, a new container, a cloud provider with dynamic egress).
  • You’re running locally with a key that’s whitelisted for the server, or behind a VPN.
  • Your requests go through a proxy, so Binance sees the proxy’s IP, not your server’s.

The SDK supports HTTP, HTTPS and SOCKS proxies, which is handy when you need a fixed egress IP; the Binance JavaScript tutorial covers the proxy options. Whatever IP your traffic leaves from is the one to whitelist.

3. The key doesn’t have permission for that action

A read-only key can call getAccountInformation(), but placing an order needs “Enable Spot & Margin Trading”, futures calls need “Enable Futures”, and so on. Binance answers a missing permission with the same -2015. Rather than guessing, ask Binance what the key can do:

const { MainClient } = require('binance');

const client = new MainClient({
  api_key: process.env.BINANCE_API_KEY,
  api_secret: process.env.BINANCE_API_SECRET,
});

async function main() {
  const p = await client.getApiKeyPermissions();
  console.log({
    ipRestrict: p.ipRestrict,
    reading: p.enableReading,
    spotAndMargin: p.enableSpotAndMarginTrading,
    futures: p.enableFutures,
    margin: p.enableMargin,
    withdrawals: p.enableWithdrawals,
  });
}

main().catch((e) => console.error(e.code, e.message));

If this call itself fails with -2015, the problem is the key or the IP (causes 1 and 2), not a missing permission. If it succeeds, compare the flags with the call that fails.

Two extra gotchas: Binance only lets you enable futures on a key after the futures account is opened, and Binance can switch off trading permission on keys with no IP restriction, so if a key that used to trade starts failing with -2015 on order calls, check the trading flag again.

4. Right key, wrong product

Spot, USD-M futures and COIN-M futures are separate APIs with separate clients in the SDK (MainClient, USDMClient, CoinMClient). A key that’s fine for spot will still fail on futures if futures isn’t enabled on it, so test with the client for the product you actually trade:

const { USDMClient } = require('binance');

const futures = new USDMClient({
  api_key: process.env.BINANCE_API_KEY,
  api_secret: process.env.BINANCE_API_SECRET,
});

futures
  .getBalanceV3()
  .then((b) => console.log(b.filter((x) => Number(x.balance) > 0)))
  .catch((e) => console.error(e.code, e.message));

-2015 or -1022?

If Binance says -1022 (“Signature for this request is not valid”) instead, the key was accepted but the signature didn’t match, which is a secret or signing problem rather than a permissions one. We wrote that up separately in troubleshooting Binance API error -1022. The SDK signs requests for you, so with it a -1022 almost always means the wrong secret. Timestamp complaints are -1021, covered in our -1021 recvWindow guide.

Quick checklist

  1. Log the key length and the first few characters to confirm the right key is loaded.
  2. Check the key is for the same environment (live, testnet or demo) and the same Binance site you’re calling.
  3. Find your real outbound IP and compare it with the key’s whitelist.
  4. Run getApiKeyPermissions() and check the flag for the action that fails.
  5. Use the client for the right product (spot, USD-M or COIN-M).

More on the SDK: the Binance JavaScript SDK page, the Binance API JavaScript tutorial and the Binance SDK docs. The package is open source (MIT) on GitHub.