Skip to content
Coingate

OKX how-to guidesAPI

Create an OKX API key: setup, permissions, expiry and errors

Create an OKX API key on the website, store its three values, choose narrow permissions, bind IPs and avoid the 14-day expiry and common error codes.

Checked on: Written: How guides are verified

To create an OKX API key, sign in to the OKX website and go to its API page. There you fill in a name, permissions and a passphrase, and your two-factor codes approve the request. A script, trading bot or portfolio tracker can then act on your account without knowing your login password. Later problems usually trace back to the passphrase, the permissions you picked, or the expiry rule for keys left without a bound IP address.

Settle the key's permissions ahead of the form

Give the key as few permissions as the tool can work with. OKX keys carry three main permissions. Read lets a tool view account information, which covers order history, bills and balances. With trade it can place and cancel orders, change settings and shift funds from one of your own accounts to another. Withdraw lets it send funds out of the account.

Match the grant to the job. Read alone covers a tax or portfolio tracker. A trading bot needs read plus trade.

Withdraw is justified in very few cases, because a leaked key carrying it lets whoever holds it empty the account. Leave it off unless a tool you fully control needs it. The OKX FAQ also describes transfer, loan and earn as separate permissions, the last two of which are visible to eligible accounts only.

Steps to create an OKX API key on the website

After logging in on the website, go from the profile menu to the API page and pick the option that creates an API key. An API entry also exists in the app, lower down in the main menu. The web form is the easier of the two, and the developer documentation from OKX tells you to make keys on the website before you sign any request.

The form asks you to name the key, say which account it belongs to and what it is for, set the permissions, choose the passphrase and list any IP addresses to allow. A name taken from the tool that will use the key makes several keys easy to tell apart later. Your two-factor codes are requested before OKX shows the new key.

If the create button is unavailable, read the page, which explains what requirement is still unmet. The API FAQ from OKX mentions that certain areas require a minimum asset balance on the account for key creation.

Three values to save the moment the key appears

Copy the values as soon as they are displayed. A working key consists of three values used together, namely the API key, its secret key and a passphrase. The first two come from OKX, and you choose the passphrase yourself while creating the key. All three are required on every signed request.

The parts to protect are the passphrase and the secret key. A person who holds them together with the key can do anything the key's permissions allow. A password manager or a secrets store is where they belong. Public code repositories, screenshots and shared documents are the wrong place for them.

Treat the passphrase as a second password that belongs to this one key. It has nothing to do with the password you log in to OKX with, and the two should not be the same string. Once the key is created, OKX has no means of recovering the passphrase or displaying it again.

Losing the passphrase leaves one fix from OKX, which is deleting the key, creating another and updating each tool where the old one was in use. You avoid that by saving the passphrase beside the secret key at the moment of creation.

Should you bind the key to IP addresses?

Bind IP addresses when your tool runs from an address that stays the same. With an allowlist, OKX turns away any request for that key unless it comes from a listed address. One key takes up to 20 IP addresses. IPv4, IPv6 and network segment formats are all accepted, and a space or a comma separates multiple entries in the form.

A rented server is the typical fixed address. A home connection is different, because its address changes and the key starts failing after the next change.

A hosted bot service normally publishes its addresses for allowlisting. Use only the list in that service's own documentation.

Why an idle key disappears after 14 days

OKX's documentation sets an expiry of 14 days of inactivity for any key that carries withdraw or trade permission without a bound IP address. The API FAQ adds two details. OKX deletes expired keys automatically, and a call to a private account endpoint, a balance query or an order for example, counts as activity.

You can keep such a key alive in two ways. Either bind an IP address to it or have something use it regularly.

Suppose a bot stops after a quiet spell and its key is no longer listed on the API page. The 14-day rule is the probable reason, and you have to create a new key.

Keys made inside demo trading are the exception. According to OKX, a demo trading key never expires.

Editing a key later and using sub-accounts

An existing key can be changed without replacing it. The same API page lets you edit the key name, the permissions and the bound IP addresses afterwards. That makes it safe to begin with narrow permissions and widen them later when a tool turns out to need more.

Sub-accounts use keys of their own. Make the key under whichever sub-account will trade, and keep a main account's key, secret and passphrase apart from a sub-account's.

Which API features are available also varies with your country and with the OKX entity serving you. If OKX refuses an endpoint, check its regional information.

What errors 50101, 50119 and 50102 tell you

Error 50101 says the key and the environment do not match. Either the demo trading header accompanied a live key, or live trading received a demo key.

Error 50119 is the report of a key that does not exist. The OKX FAQ traces it to a call sent to a domain other than the one for your region, since an account served by a regional OKX entity has to call the API domain of that entity.

Error 50102 says the request's timestamp has expired. OKX rejects a request when its timestamp and server time differ by more than 30 seconds, so synchronise the clock of the machine that runs the tool.

When a third-party tool cannot connect at all, two checks are worth making. The passphrase must have been pasted with no extra spaces, and the address sending the request must be on the allowlist.

Common questions

Is the API passphrase the same as my OKX login password?

No. You choose the passphrase when you create the key, it belongs to that key only, and it should be a different string from your login password.

What happens to my tools if I lose the passphrase?

It cannot be shown again or recovered by OKX. The key has to be deleted and replaced, and every tool that used the old key needs the new values.

What counts as activity under the 14-day rule?

Calls to private account endpoints count, the API FAQ from OKX says, for example an order or a balance query. The rule covers keys holding withdraw or trade permission with no IP address bound to them.

Do API keys created in demo trading expire as well?

No. OKX says keys for demo trading have no expiry.

Does a portfolio or tax tracker need trade permission?

No. Read permission is enough for a tracker, because it only views order history, bills and balances.

Why can I not press the create button on the API page?

The page states which requirement is unmet. According to the OKX API FAQ, some areas require an account to hold a minimum asset balance first.

You can lose money trading crypto, and with leveraged products the entire deposit can go. This site gives no investment advice. Before you register, confirm that the exchange accepts residents of your country.

More guides in this section

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

Coingate 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.