Skip to main content
Every /v1 call except the OpenAPI document needs an API key:

Create a key

Each key belongs to one trading account and has its own limits. A key is either a test key (lean_sk_test_…) or a live key (lean_sk_live_…). Both use the same trading account. Test keys simulate orders and fills with no money; live keys trade real money, and trading can be paused platform wide. A key’s mode is set when you create it and can’t be changed. See Test mode and live mode.
  1. Sign in to Lean.
  2. Open Settings (the gear) and choose API.
  3. Under API keys, choose Create API key. Give the key a name, then choose its mode, access, per order limit, daily limit and expiry. The mode is Test and the access is Read and trade unless you change them. Choose Create key.
  4. Under Copy your key now, choose Copy, then Done. You won’t see the key again.
Lean stores only a hash of the key and cannot recover a lost one. Keep it in a secret manager, never in source control.
The API keys list shows each key’s name with a Test or Live badge, its prefix (such as lean_sk_test_xxxxxxxx…), when it was created, last used and expires, and whether it is Active, Revoked or Expired. A user can hold up to 10 active keys; revoke one to create another.

Manage keys with the API (advanced)

If you manage keys from your own tooling, call /api-keys instead. These requests take the access token of your Lean session while you are signed in, sent as Authorization: Bearer <token>, never an API key. The token expires after a short time.
A session token acts as you, signed in. Use it only to create, list and revoke keys, never paste it into a program, and don’t share it.
Send the body as JSON with Content-Type: application/json, or the request is refused with 400 VALIDATION_ERROR. The secret is in data.secret. mode is test or live and defaults to test. scopes takes read, trade and route. route lets the key pay for a buy with cash on the other venue (see Paying from the other venue) and needs trade. Leave it out for a key that should only trade with the cash already on each venue. A key can also take withdraw, with optional withdrawal limits; see Withdrawals through the API. Limits are in millionths of a dollar, so 5000000 is $5. The API reference documents Create an API key, List API keys and Revoke an API key, with every field and error.

Rotate and revoke

To rotate a key, create a new one, move your client to it, then revoke the old one: in Settings, API, choose Revoke on its row, then Revoke again to confirm. Programs using the key stop working immediately, and this can’t be undone. With the API:
Lean refuses revoked and expired keys immediately.

Failures