Installation
Install@lifi/perps-sdk plus a provider package for each venue you trade on. Each provider package (@lifi/perps-sdk-provider-hyperliquid, @lifi/perps-sdk-provider-lighter, @lifi/perps-sdk-provider-ondo) declares @lifi/perps-sdk as a peer dependency.
Configuration
Initialize the Perps SDK client. An API key identifies your integration for fees. Theintegrator name is an optional assertion of the API key’s identity:
x-lifi-integrator only when both apiKey and integrator are set. integrator with no apiKey has no effect, because the integration always comes from the API key. See API Reference / Authentication for the full contract.
DEFAULT_API_URL is the Production host (https://li.quest/v1/perps). Pass apiUrl to target another host:
An API key is optional on Production only. Development (
develop.li.quest) and Staging (staging.li.quest) require an API key. On Production, requests with no key use LI.FI’s default fees.Which client?
The SDK has two client surfaces. Build onePerpsClient and use its .client wherever a service function (getProviders, getAssets, getOrders, …) or PerpsWsClient takes a PerpsSDKClient.
Snippets in these docs share these names and declare only what is new. Imports, enums, and other variables are always spelled out. Assume these are in scope:
perps, client, ws (PerpsWsClient), walletClient (the end-user’s viem wallet client), address and userAddress (Address).
Configuration Options
These options configurecreatePerpsClient, the low-level client the service functions (getProviders, getAssets, etc.) take:
PerpsClient constructor options
new PerpsClient(options) — the higher-level class covering setup, trading, and app-level meta actions (see SDK / Actions) — takes a narrower option set. It forwards integrator, apiKey, apiUrl, and providers to an internal createPerpsClient call:
PerpsClient has no userWallet, retry, requestInterceptor, or fetch constructor option, and it cannot take a pre-built low-level client. With a PerpsClient you cannot add request headers, inject fetch, or change the SDK’s retry policy. The only levers are apiUrl (point it at your own proxy, see Browser apps) and the provider plugin factories. Set the end-user wallet after construction with perps.setUserWallet(wallet), and update switchChain at runtime with perps.setSwitchChain(hook).
The SDK bundles its own
viem version range. If your app uses a different viem minor, setUserWallet(walletClient) can fail to type-check; cast the wallet client once (walletClient as Parameters<PerpsClient['setUserWallet']>[0]). A viem wallet client is pinned to the chain it was created on. When a wagmi wallet client changes chain, call setUserWallet again, or configure switchChain so the SDK switches the chain before user-signed EIP-712 and EVM steps.Provider Configuration
Theproviders option takes an array of provider plugins. Each plugin binds a DEX’s read surface to the client, looked up at runtime via client.getProvider(key):
Storage for the agent / API-key signer is configured on the provider plugin (e.g.
hyperliquidProvider({ storage })), not on createPerpsClient.Request Interceptor
TherequestInterceptor option lets you modify request options before each API call. This is useful for adding custom headers, logging, or integrating with authentication systems:
Get an API key from the LI.FI Partner Portal to trade under your own integration. A client with no API key is a supported configuration on Production and uses LI.FI’s default fees.
Browser apps: proxy pattern
Never ship anx-lifi-api-key in a browser bundle. Point apiUrl at a same-origin route on your backend instead. The route adds the key and forwards the request. A relative path works:
x-lifi-api-key (and optionally x-lifi-integrator), and must not cache; see also API Reference / Browser apps. This handler uses only the Fetch API and works in any runtime that passes it a Request:
Rate limits and polling
Rate limits on the LI.FI endpoints apply per integration of the API key. A request with no key counts against the client IP. The account reads and WebSocket streams above hit the venue directly, so the venue’s per-IP budget is the limit that applies to them.- Prefer WebSocket streams over polling.
- If you poll, use an interval of 10 seconds or more, and do not refetch on every stream frame.
- Retry only on
PerpsErrorCode.RateLimitExceeded(2090), with exponential backoff. Do not retry auth errors,ServerError, orMarketNotFound. - The SDK retries HTTP requests itself.
createPerpsClientaccepts aretryoption;PerpsClientdoes not, so retries you add in your own layer (for example a query library) stack on top of the SDK’s.
Terms acceptance
Every non-metacreateAction and executeAction call, which includes checkSetup, setup steps, trading, and withdrawals, fails with 401 / 2012 (TermsNotAccepted) until the address has accepted the current terms version. Check first and onboard when needed:
Quick Start
Fetch available providers and assets:Request Cancellation
All service functions accept an optionaloptions parameter (SDKRequestOptions) with an AbortSignal for cancelling in-flight requests:
fetch is aborted and the promise rejects with an AbortError.
SDKRequestOptions is { signal? }.
Next steps
- Providers / Hyperliquid — Signing Model — Agent provisioning, key storage, and the two-part signing scheme
- Concepts / Action Pattern — The create → authorize → execute pattern
- Providers / Hyperliquid — Setup, signing model, and provider-specific details
- SDK / Trading — All order types, features, and a full end-to-end example
- SDK / Market Data — Prices, orderbooks, and charts