Skip to content
Coininfo

API

How to Create an OKX API Key: Passphrase, Permissions, IP Binding and Expiry

Creating an OKX API key step by step: the three values you must store, which permissions to grant, why binding an IP address matters, the inactivity expiry rule and the errors new keys most often hit.

Last checked: How we check our guides

An OKX API key lets a script, trading bot or portfolio tracker act on your account without your login password. Creating one takes a few minutes. The parts that cause trouble later are the passphrase, the permission choice and the expiry rule for keys without a bound IP address.

What you get when you create a key

OKX issues three values that work together: the API key, the secret key and the passphrase. The first two are generated by OKX. The passphrase is one you choose yourself during creation. Every signed request needs all three.

The secret key and passphrase are the sensitive parts. Anyone holding them along with the key can do whatever the key's permissions allow. Store them in a password manager or a secrets store, never in a shared document, a screenshot or a public code repository.

Create the key

On the website, log in, open the profile menu and go to the API page, then choose to create an API key. In the app, the API entry is further down the main menu. OKX's developer documentation says keys should be created on the website before any request is signed, and the web form is easier to work with.

The form asks for a name for the key, the account it belongs to and what it is used for, an IP address allowlist, the permissions, and the passphrase. Pick a name that says what uses the key, so you can tell keys apart later. OKX then asks for your two-factor codes before it shows the new key.

Copy the values at once. OKX's API FAQ notes that in certain areas an account needs a minimum asset balance before a key can be created. If the create button is unavailable, the page explains which requirement is not met.

Set a passphrase you will not lose

The passphrase is a second password for this key only. It is not your OKX login password and should not be the same string. OKX cannot show it again after creation and cannot recover it.

If the passphrase is lost, the only fix OKX offers is to delete the key and create a new one, then update every tool that used the old key. Saving the passphrase next to the secret key at the moment of creation avoids that.

Choose the narrowest permissions

OKX keys have three main permissions. Read allows viewing account information such as balances, bills and order history. Trade allows placing and cancelling orders, moving funds between your own accounts and changing settings. Withdraw allows sending funds out of the account.

Grant only what the tool needs. A tax or portfolio tracker needs read only. A trading bot needs read and trade. Very few uses justify withdraw, and a leaked key with that permission can empty the account. OKX's FAQ also describes separate transfer, loan and earn permissions, with the last two shown only to eligible accounts.

Permissions, the key name and the bound IP addresses can be edited afterwards from the same API page, so you can start narrow and widen a key later if a tool really needs it.

Bind IP addresses

An IP allowlist restricts the key so that requests are accepted only from the addresses you list. OKX allows up to 20 IP addresses per key and accepts IPv4, IPv6 and network segment formats. In the form, separate multiple addresses with a comma or a space.

Binding only works when the tool runs from a fixed address, such as a server you rent. A home connection whose address changes will start failing after the next change. Hosted bot services normally publish the addresses to allowlist. Use the list from the service's own documentation and nothing else.

The 14-day expiry rule

OKX's documentation states that API keys with trade or withdraw permission that are not bound to an IP address expire after 14 days of inactivity. The API FAQ adds that expired keys are deleted automatically and that calls to private account endpoints, such as a balance query or an order, count as activity.

There are two ways to keep a key alive: bind it to an IP address, or make sure it is used regularly. If a bot stops working after a quiet period and the key has vanished from the API page, this rule is the likely cause, and a new key has to be created. Keys made inside demo trading are an exception. OKX states that demo trading keys do not expire.

Common errors with a new key

Error 50101 means the key does not match the environment. A live key was used with the demo trading header, or a demo key was used against live trading. Error 50119 says the key does not exist, and OKX's FAQ traces it to using the wrong domain for your region. Accounts served by a regional OKX entity must call that entity's API domain.

Error 50102 means the request timestamp has expired. OKX rejects requests whose timestamp differs from server time by more than 30 seconds, so sync the clock on the machine that runs the tool. If a third-party tool fails to connect at all, check that the passphrase was pasted without extra spaces and that the request comes from an allowlisted address.

Sub-accounts have their own keys. Create the key under the sub-account that will trade, and do not mix a main account's key, secret or passphrase with a sub-account's. API availability and features also differ by country and OKX entity, so check OKX's regional information if an endpoint is refused.

Questions and answers

Can I recover a lost OKX API passphrase?
No. OKX cannot recover or display the passphrase after the key is created. Delete the key and create a new one.
Why did my OKX API key disappear?
Keys with trade or withdraw permission that are not bound to an IP address expire after 14 days of inactivity and are deleted. Bind an IP address or keep the key in regular use.
How many IP addresses can I bind to one key?
OKX's documentation allows up to 20 IP addresses per API key, in IPv4, IPv6 or network segment format.
Which permissions should a trading bot have?
Read and trade are enough for most bots. Leave withdraw off unless a tool you fully control needs it, because a leaked key with withdraw permission can move funds out of the account.
Can I change the permissions of an existing key?
Yes. OKX lets you edit a key's name, permissions and bound IP addresses from the API page without creating a new key.

Crypto trading carries a high risk of loss, and leveraged products can lose your whole deposit. Nothing here is investment advice. Check that the exchange is available in your country before you sign up.

Related guides

All OKX guides

Save up to 50% on fees + get up to $100 in rewards

Eligibility and terms may apply. The link fills in our referral code at sign-up. Check the code field before you submit: a registered code usually cannot be changed.

Get OKX Offer

Coininfo earns a commission from the exchange when you sign up through the links on this page, based on the trading fees you later pay. The link does not raise your fee rate.