Before you start
- A verified Kalshi (or demo) account
Create your Kalshi API key
- 1
Open account settings
Log in and go to Account & security → API keys (profile settings).
- 2
Create a key
Click Create new API key and name it.
- 3
Download the private key
Save the downloaded
.key/.pemfile immediately; Kalshi does not store it. - 4
Store both values
Save
KALSHI_API_KEY_IDand the private key contents asKALSHI_PRIVATE_KEY.
Test the key
Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.
# pip install cryptography
import base64, time, requests
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
key = serialization.load_pem_private_key(open("kalshi.key", "rb").read(), password=None)
ts, path = str(int(time.time() * 1000)), "/trade-api/v2/portfolio/balance"
sig = key.sign((ts + "GET" + path).encode(), padding.PSS(mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.DIGEST_LENGTH), hashes.SHA256())
print(requests.get("https://demo-api.kalshi.co" + path, headers={
"KALSHI-ACCESS-KEY": KEY_ID, "KALSHI-ACCESS-TIMESTAMP": ts,
"KALSHI-ACCESS-SIGNATURE": base64.b64encode(sig).decode()}).json())balance response means the key works.Keep the credentials safe
- Store values in a password manager or a git-ignored
.env, never in code or notebooks you share. - In an AlgoGP project you can still add them under APIs & keys (encrypted at rest) and read them with
strategy_runtime.secrets.get("KALSHI_API_KEY_ID"). - Give each bot its own credential so you can revoke one without stopping the others.
KALSHI_API_KEY_ID=paste-your-value-here
KALSHI_PRIVATE_KEY=paste-your-value-hereDesign and backtest your Kalshi strategy first
AlgoGP turns an idea into Python and tests it on years of history before you connect it to Kalshi. The exported code keeps the broker behind four small adapter methods.
- AI copilot writes and revises the rules
- Backtests with realistic costs
- Exported Python ready to wire to Kalshi
Free plan, no card required.
AlgoGP is not affiliated with Kalshi. Menus get renamed from time to time; if a label differs, the official documentation has the current path.