API keys
You can use API keys to trade and manage your Lighter account programmatically. Each API key will be assigned an index, ranging from 0 to 254 - note that indexes {0,1,2,3} are reserved for desktop and mobile interfaces.
Each account (master or sub-account) has its own set of API keys (indexes 0–254), each with its own key pair and nonce.
Permissions
Scope
One account index (master, sub-account or pool)
Index range
0–254. 0–3 reserved for Lighter's web/mobile apps. Use 4–254.
Special index 255
"All keys" – only for querying apikeys
Nonce
Independent per key (see Core concepts)
Registration
ChangePubKey, requires the L1 wallet signature (or an on-chain call)
Can do
Trade, cancel, modify, leverage/margin, sub-accounts, secure withdrawals, same-owner transfers, auth-gated REST and WebSocket reads
Cannot do alone
Transfers to another L1 owner, fast withdrawals, approving an integrator with fees (these also need the L1 signature)
Secure withdrawals only need the API key because they can only go back to the L1 address that created the account. Fast withdrawals and transfers can go to other L1 addresses, so they also need a signature from the wallet's private key. See When an L1 signature is required.
List keys on an account:
curl "https://mainnet.zklighter.elliot.ai/api/v1/apikeys?account_index=123&api_key_index=255"Authentication
To interact with certain endpoints, you will need to generate an auth token using your API private key. You can do so using our GO SDK, the create_auth_token_with_expiry() function in our Python SDK, or the WASM signer:
Each auth token can have a maximum expiry of 8 hours, and it uses the following structure: {expiry_unix}:{account_index}:{api_key_index}:{random_hex}. Refresh tokens before they expire.
Use it as:
REST:
Authorization: <token>header.WebSocket:
"auth": "<token>"inside the subscribe message.
Authenticating a request also makes it count against your L1 address instead of your IP. See Rate Limits.
Read-only Authentication
Using an API-key-signed auth token, you can generate read-only auth tokens - those won't allow placing trades nor request withdrawals (essentially, you won't be able to sign transactions hence initialize a signer client), but you will be able to access auth-gated data via API. Each read-only token can have a maximum expiry of 10 years, and a minimum of 5 minutes. Read-only tokens are limited to read.* scopes. They will use the following structure: ro:{account_index}:{single|all}:{expiry_unix}:{random_hex}. all covers the master account and its sub-accounts; single covers one account index.
You can generate one using the tokens/create endpoint, or via front-end. On Lighter, tokens/create costs 10,000 request weight, about 40% of the 24,000/minute Plus or Premium/Advanced budget. On Robinhood Chain, it costs 23,000; see the RH rate limits. Create tokens once and store them; don't create one per session.
Maker-only API keys
Clients on a Premium/Advanced account may mark up to 251 keys per account index as maker-only. Those keys will be restricted to 0ms speed bump transactions only:
Post-only (ALO) orders
Modify orders on ALO orders
Cancel, and Cancel All orders
The direct benefit of using this configuration is having access to an optimized execution path, with reduced scheduling latency. Keys reserved by our front-end (0-3) cannot be set as maker-only, and we apply a one-hour cooldown in between changes.
You can set a list of keys as maker-only using setMakerOnlyApiKeys, and get a list of maker-only keys using getMakerOnlyApiKeys.
How to create API keys programmatically
While generating the API keys does not require your L1 private key, associating them with your Lighter account does. See Create accounts programmatically for a TypeScript example, or use the Python SDK or the GO SDK. You can also interact with Lighter's smart contract directly using the ChangePubKey function (this is particularly helpful if you're running a multi-sig).
Nonce management
Each API key has its own nonce. Nonce rules, skipping nonces, which rejected transactions consume a nonce, and why to use a separate API key per workload are covered in Core concepts.
Last updated
Was this helpful?