# Binance API key error -2015 in Node.js: invalid key, IP or permissions checklist

Binance uses `-2015` for three checks. Its message is _“Invalid API-key, IP, or permissions for action.”_ Start with the key loaded by your Node.js process, then check the IP Binance sees and the permissions for the call that failed. The examples use the [Binance JavaScript SDK](https://siebly.io/sdk/binance/javascript) (`binance` on npm).

## What the error looks like

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

```javascript
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

Check the credentials the process actually loaded.

*   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](https://siebly.io/sdk/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:

```javascript
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:

```javascript
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?

Binance returns `-1022` when the signature does not match. Check the secret configured for the key. See [troubleshooting Binance API error -1022](https://siebly.io/blog/troubleshooting-binance-api-error-1022-in-javascript-diagnose-invalid-signatures) for signing errors and the [\-1021 recvWindow guide](https://blog.siebly.io/binance-api-1021-timestamp-recvwindow-nodejs/) for timestamp errors.

## 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](https://siebly.io/sdk/binance/javascript), the [Binance API JavaScript tutorial](https://siebly.io/sdk/binance/javascript/tutorial) and the [Binance SDK docs](https://sieblyio.github.io/docs/binance/). The package is open source (MIT) on [GitHub](https://github.com/sieblyio/binance).
