Hyperliquid API key and API wallet in the SDK
Public market data needs no key. Signed exchange actions on the Hyperliquid API, such as placing or cancelling an order, need a signer. Hyperliquid has no API key and secret pair. Its equivalent is an API wallet, also called an agent wallet: a separate private key that your main account approves to sign on its behalf.
| Exchange-style setting | Hyperliquid equivalent | SDK option |
|---|---|---|
| API secret | API wallet private key | privateKey |
| API key or account ID | Main account or subaccount address | accountAddress |
Create an API wallet
Open the API page of the Hyperliquid app while connected with the main account, generate an API wallet, and approve it. Store the API wallet private key as soon as it is shown. Approvals are per network, so approve a separate API wallet on Testnet if you trade there as well.
When you set it up:
- Give each trading process its own API wallet. Hyperliquid tracks nonces per signer, so separate wallets keep processes independent.
- An approved API wallet can be given an expiry. When it is replaced or expires, generate a new one instead of reusing the old address.
- Keep the private key on a server you control. Do not put it in a browser bundle, a mobile app, or a public repository.
Use the API wallet with the SDK
Supply the API wallet private key and the main account address through environment variables, then construct the client:
import { RestClient } from '@siebly/hyperliquid-api';
const privateKey = process.env.HYPERLIQUID_API_WALLET_KEY;
const accountAddress = process.env.HYPERLIQUID_ACCOUNT_ADDRESS;
if (!privateKey || !accountAddress) {
throw new Error('Set HYPERLIQUID_API_WALLET_KEY and HYPERLIQUID_ACCOUNT_ADDRESS.');
}
export const client = new RestClient({
privateKey,
accountAddress,
});The API wallet only signs. Account data belongs to the main account, so always set accountAddress. Creating the client does not check the approval. This example asks Hyperliquid which account the API wallet signs for:
import { RestClient } from '@siebly/hyperliquid-api';
import { Wallet } from 'ethers';
async function main() {
const privateKey = process.env.HYPERLIQUID_API_WALLET_KEY;
const accountAddress = process.env.HYPERLIQUID_ACCOUNT_ADDRESS;
if (!privateKey || !accountAddress) {
throw new Error('Set HYPERLIQUID_API_WALLET_KEY and HYPERLIQUID_ACCOUNT_ADDRESS.');
}
const testnet = process.env.HYPERLIQUID_TESTNET === 'true';
const client = new RestClient({ privateKey, accountAddress, testnet });
const apiWallet = new Wallet(privateKey).address;
const role = await client.getUserRole({ user: apiWallet });
if (role.role !== 'agent' || role.data.user.toLowerCase() !== accountAddress.toLowerCase()) {
throw new Error(`API wallet ${apiWallet} is not approved for this account on ${testnet ? 'Testnet' : 'Mainnet'}.`);
}
console.log(`API wallet ${apiWallet} signs for ${accountAddress}.`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Save that example as api-wallet.mjs, install ethers alongside the SDK, and run it with Node.js 24:
node --env-file=.env api-wallet.mjsA successful check prints the API wallet address and the account it signs for. See getUserRole() and Error handling if the request fails.
Mainnet and Testnet
Mainnet is the default. For Testnet, approve an API wallet in the Testnet app, set HYPERLIQUID_TESTNET=true for the example above, and pass testnet: true to every client. See Hyperliquid Testnet with the SDK.
Common failures
| Symptom | What to check |
|---|---|
User or API Wallet 0x... does not exist. | The API wallet is approved for this account on the same network as the client |
The signer is not a Hyperliquid account on this network. Set accountAddress when using an API wallet. | accountAddress is set to the main account or subaccount, not the API wallet address |
| Nonce errors with several processes | Each process uses its own API wallet |