Authenticated Setup
Public reads and public streams can use public=True without credentials:
from hyperliquid import Hyperliquid
async with Hyperliquid.http(public=True) as client:
mids = await client.info.all_mids()
Otherwise, we recommend using "API wallets" instead of your actual private key. You can create them from the Hyperliquid website.
Authorize the API wallet and then copy the private key, as shown in the screenshot below:

Environment Variable
For authenticated exchange actions, set your private key:
Then construct Hyperliquid normally:
from hyperliquid import Hyperliquid
async with Hyperliquid.http() as client:
result = await client.exchange.noop()
print(result['status'])
For testnet, pass mainnet=False and set the testnet key:
from hyperliquid import Hyperliquid
async with Hyperliquid.http(mainnet=False) as client:
result = await client.exchange.noop()
print(result['status'])
Direct Wallet Usage
You can also pass a private key or wallet object directly:
from hyperliquid import Hyperliquid
async with Hyperliquid.http('0xyour_private_key') as client:
result = await client.exchange.noop()
print(result['status'])
Security Notes
- Never commit private keys.
- Treat
HYPERLIQUID_PRIVATE_KEYandHYPERLIQUID_TESTNET_PRIVATE_KEYas high-sensitivity secrets. - Treat exchange examples as mainnet-sensitive unless you explicitly set
mainnet=False.