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 like4ck_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:
- REST API
- Orders WebSocket
- Streaming WebSocket
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
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.
2. Send the token
- REST API
- Orders WebSocket
- Streaming WebSocket
Pass the token in the A missing, unknown, or expired token returns
Authorization header. The Bearer prefix is optional.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. Treat401as “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.
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.