Create API keys
1
Generate your API key on OKX
Visit OKX API Management and create a new API key. OKX will generate three values that you need:
2
Store credentials in environment variables
Never hardcode credentials in source code. Use environment variables instead:Or pass them inline when running a script:
Use single quotes in the shell to prevent special characters like
$ from being incorrectly interpolated.3
Pass credentials to the client
Supply the three credential fields when constructing
RestClient or WebsocketClient.WebsocketClient accepts an accounts array, which allows you to authenticate up to 100 accounts on a single private connection — matching OKX’s own limit.Region selection
OKX operates three separate regional platforms, each with its own domain and API endpoint. API keys are created per platform and are not interchangeable between regions.
Set the
market option on either client to connect to the correct regional endpoint:
Global is the default. If you are on
www.okx.com, you do not need to set market at all.Demo trading mode
OKX provides a paper trading environment (“demo trading”) that uses separate demo keys but does not require real funds. This is the recommended way to test your integration before going live. Enable it by settingdemoTrading: true on either client. Use your demo API keys — not your live keys.
Client options reference
TheRestClientOptions interface (from src/types/rest/client.ts) and WSClientConfigurableOptions interface (from src/types/websockets/ws-general.ts) accept the following credential and authentication options:
RestClientOptions
WSClientConfigurableOptions
Security best practices
- Use environment variables — load credentials with
process.envand never commit them to version control. - Restrict API key permissions — create read-only keys for market data, and only grant trade/withdrawal permissions to keys that require them.
- Rotate keys regularly — if a key is compromised, revoke it immediately from the OKX API Management page.
- Use IP allowlisting — OKX lets you bind an API key to specific IP addresses, limiting exposure if a key is leaked.
- Separate demo and live keys — keep demo trading keys distinct from production keys to avoid accidentally trading on a live account.

