Skip to main content
Every 4casters API, REST and WebSocket alike, authenticates the same way: one credential string in the Authorization header. There are two kinds of credential, and the only decision is which one to use. If you are writing code that runs unattended, use an API key. Login tokens exist so the website can sign you in; they rotate, they die with a password change, and a leaked one is as good as your password until you notice.

API keys

Create one at My Account → Security → API Keys (or go straight to 4casters.io/account/api-keys): name it, optionally restrict it to your servers’ IP ranges and give it an expiry, and copy the key from the confirmation. It is shown once. A key looks like 4ck_Wk15VXFX_T4MPcp8Ij2IODI7OFFIlQsHmvvzJ3Nj8C-StfVe3h0k1kH2SF. The first part, 4ck_Wk15VXFX, is its Key ID: not secret, and how the account page refers to the key. The rest is the secret. Send it exactly where a login token goes:
There is no login step and nothing to refresh. The full reference, including allowed IPs, expiry, what a key cannot do, and every error it can produce, is on the API keys page.

Login tokens

A login token is what the website holds after you sign in. It works on every API, so it is fine for a quick experiment or a one-off script; for anything that keeps running, prefer a key.

1. Log in

POST https://api.4casters.io/user/login
The username field accepts either your username or the email on the account. The token is at data.user.auth in the response body: a 256-character hex string. The same value is also set as a signed auth cookie; server-side integrations should capture data.user.auth and ignore the cookie.
The full response shape is documented on the REST login page.
Log in once and reuse the token. Login is rate-limited per IP and per account, and every successful login mints a new token. Logging in again does not invalidate tokens you already hold.

2. Send the token

Pass the token in the Authorization header. The Bearer prefix is optional.
A missing, unknown, or expired token returns 401 with body { "error": { "message": "InvalidCredentials", "code": 401 } }.

Token lifetime

If you must run on a login token for more than a month, do one of the following:
  • Re-login on any 401. Simplest and robust. Treat 401 as “get a fresh token”, not as a fatal error.
  • Watch for X-Auth-Token. Whenever that header is present on a response, persist its value and use it from then on.
A script that logs in once, stores the token, and never looks at response headers will work for exactly 30 days and then fail with 401 on every request. An API key has none of this.

Login errors

Two-factor authentication

Two-factor authentication on 4casters protects withdrawals, not login. Enabling it on your account does not change how you authenticate against the API: POST /user/login never asks for a code, and API keys are unaffected.

Keeping credentials safe

  • Store keys, usernames and passwords in environment variables or a secrets manager, never in source control.
  • Treat a key or a token like a password. Anyone holding it can place orders and read your account.
  • Give each program its own API key, named after the program, and restrict it to the addresses it runs from. If one leaks, revoke that one.
  • Consider a dedicated account for automated trading so a leaked credential does not expose your main balance. Accounts are opened the same way as any user account.