Step 1: Get Your API Keys
- Log in to your Kalshi account (demo or production)
- Navigate to Account & security → API Keys
- Click Create Key
- Save both:
- Private Key: Downloaded as a
.key
file - API Key ID: Displayed on screen (looks like
a952bcbe-ec3b-4b5b-b8f9-11dae589608c
)
- Private Key: Downloaded as a
Your private key cannot be retrieved after this page is closed. Store it securely!
Step 2: Set Up Your Request
Every authenticated request to Kalshi requires three headers:Header | Description | Example |
---|---|---|
KALSHI-ACCESS-KEY | Your API Key ID | a952bcbe-ec3b-4b5b-b8f9-11dae589608c |
KALSHI-ACCESS-TIMESTAMP | Current time in milliseconds | 1703123456789 |
KALSHI-ACCESS-SIGNATURE | Request signature (see below) | base64_encoded_signature |
How to Create the Signature
The signature proves you own the private key. Here’s how it works:-
Create a message string: Concatenate
timestamp + HTTP_METHOD + path
- Example:
1703123456789GET/trade-api/v2/portfolio/balance
- Example:
- Sign with your private key: Use RSA-PSS with SHA256
- Encode as base64: Convert the signature to base64 string
Step 3: Get Your Balance
Now let’s make your first authenticated request to get your account balance:Complete Working Example
Here’s the minimal code to get your balance:Common Issues
Problem | Solution |
---|---|
401 Unauthorized | Check your API Key ID and private key file path |
Signature error | Ensure timestamp is in milliseconds (not seconds) |
Path not found | Path must start with /trade-api/v2/ |
Next Steps
Now you can make authenticated requests! Try these endpoints:/trade-api/v2/portfolio/positions
- Get your positions/trade-api/v2/portfolio/orders
- View your orders/trade-api/v2/markets
- Browse available markets