← All articles

Gate API testnet returning 502 or 404 in Node.js: the testnet host has changed

If your Gate API testnet code suddenly fails with 502 Bad Gateway or 404 Not Found, check the host before you check your keys. Many older examples and wrappers still point at fx-api-testnet.gateio.ws. On 13 November 2026 that host returned 502 for the USDT futures contract endpoint and 404 for spot paths, while api-testnet.gateapi.io answered both normally.

This note shows the working hosts and how to point the open-source gateio-api package (the Gate JavaScript SDK we maintain at Siebly) at testnet with one option, for REST and WebSocket. For the full walkthrough, see the Gate API JavaScript tutorial for Node.js and the Gate JavaScript SDK page.

What the failure looks like

A quick check from the command line shows the difference (results from 13 November 2026):

# Old testnet host
curl -i https://fx-api-testnet.gateio.ws/api/v4/futures/usdt/contracts/BTC_USDT
# HTTP/1.1 502 Bad Gateway

curl -i https://fx-api-testnet.gateio.ws/api/v4/spot/time
# HTTP/1.1 404 Not Found

# Current testnet host
curl -i https://api-testnet.gateapi.io/api/v4/spot/time
# HTTP/1.1 200 OK  {"server_time":...}

An HTML error page from openresty rather than a JSON body with a label is the giveaway. Gate’s own errors, such as INVALID_SIGNATURE or INVALID_KEY, always come back as JSON. If you see HTML, the request never reached the API.

Current Gate testnet hosts

Surface Testnet URL
REST (spot and futures) https://api-testnet.gateapi.io/api/v4
Spot WebSocket wss://ws-testnet.gate.com/v4/ws/spot
USDT perpetual futures WebSocket wss://ws-testnet.gate.com/v4/ws/futures/usdt
Options WebSocket wss://ws-testnet.gate.com/v4/ws/options

These are the hosts used by gateio-api 1.6.8. Gate can move them again, so it is safer to let the SDK choose the host than to hard-code URLs in your app.

Switch to testnet with gateio-api

Install the package:

npm install gateio-api

Then set useTestnet: true. The same option works on RestClient, WebsocketClient and WebsocketAPIClient, and the SDK picks the right testnet host for each product.

import { RestClient } from 'gateio-api';

const client = new RestClient({ useTestnet: true });

const time = await client.getServerTime();
const [ticker] = await client.getSpotTicker({ currency_pair: 'BTC_USDT' });
const contract = await client.getFuturesContract({
  settle: 'usdt',
  contract: 'BTC_USDT',
});

console.log(time.server_time, ticker.last, contract.name, contract.mark_price);

These calls are public, so no keys are needed. For private calls, add testnet API keys (they are separate from live keys) from environment variables:

import { RestClient } from 'gateio-api';

const client = new RestClient({
  apiKey: process.env.GATE_TESTNET_API_KEY,
  apiSecret: process.env.GATE_TESTNET_API_SECRET,
  useTestnet: true,
});

const balances = await client.getSpotAccounts({ currency: 'USDT' });
console.log(balances);

WebSocket streams on testnet

import { WebsocketClient } from 'gateio-api';

const ws = new WebsocketClient({ useTestnet: true });

ws.on('open', (data) => console.log('open', data.wsKey, data.wsUrl));
ws.on('response', (data) => console.log('subscribed', data.channel));
ws.on('update', (data) => console.log(data.channel, data.result));
ws.on('reconnected', (data) => console.log('reconnected', data?.wsKey));
ws.on('exception', console.error);

ws.subscribe(
  { topic: 'futures.tickers', payload: ['BTC_USDT'] },
  'perpFuturesUSDTV4',
);

On 13 November 2026 this connected to wss://ws-testnet.gate.com/v4/ws/futures/usdt and printed a futures.tickers update within a second. The client keeps the connection alive with heartbeats and resubscribes after a reconnect, so you do not need your own retry loop.

Checklist if testnet still fails

  • HTML error page: wrong or retired host. Remove any custom baseUrl and use useTestnet: true.
  • INVALID_KEY: you are sending live keys to testnet, or testnet keys to live.
  • REQUEST_EXPIRED: your clock is more than 60 seconds out. Sync the system clock.
  • INVALID_SIGNATURE: wrong secret or a modified request body. Let the SDK sign the request rather than signing by hand.

More examples, including WebSocket API order commands, are in the Gate API JavaScript tutorial and the gateio-api examples on GitHub.