// GUIDE — WINDOWS
Kalshi CLI Setup on Windows
May 21, 2026 · Yeti Games, LLC · 8 min read
The Windows setup follows the same logic as macOS but uses PowerShell instead of Terminal, has different file paths, and requires a few extra steps for OpenSSL. This guide covers the full setup plus the three errors that catch most people: InvalidByte, NOT_FOUND, and the missing positions bug.
1. Prerequisites
Install these first if you don't have them:
- Python 3.9+ — python.org/downloads — check "Add Python to PATH" during install
- Git — git-scm.com/download/win
- Node.js 18+ — nodejs.org (for Claude Code)
Verify in PowerShell:
python --version git --version node --version
2. Credential Setup
Create a directory for your keys:
mkdir $HOME.kalshi
Set environment variables permanently via PowerShell:
[System.Environment]::SetEnvironmentVariable("KALSHI_ACCESS_KEY", "your-uuid-here", "User")
[System.Environment]::SetEnvironmentVariable("KALSHI_PRIVATE_KEY_PATH", "$HOME.kalshiprivate_key.pem", "User")
[System.Environment]::SetEnvironmentVariable("KALSHI_ENVIRONMENT", "demo", "User")Close and reopen PowerShell after setting these. Verify:
echo $env:KALSHI_ACCESS_KEY
3. Fixing the InvalidByte Error
Same cause as macOS: copying your private key from a browser corrupts the PEM file with hidden characters or smart quotes. The CLI throws:
ValueError: InvalidData(InvalidByte(4, 95))
Install OpenSSL for Windows from slproweb.com (grab the Win64 installer, not Light). Then in PowerShell:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt ` -in $HOME.kalshiprivate_key.pem ` -out $HOME.kalshiprivate_key_fixed.pem Move-Item $HOME.kalshiprivate_key_fixed.pem $HOME.kalshiprivate_key.pem -Force
4. Fixing the NOT_FOUND Error (Demo Mode)
If you're using demo credentials and every request returns NOT_FOUND, the CLI is hitting the production server instead of demo.
Find cli.py — typically at:
C:UsersYourNameAppDataLocalProgramsPythonPython3xxLibsite-packageskalshi_clicli.py
Or locate it with:
python -c "import kalshi_cli; print(kalshi_cli.__file__)"
Open in Notepad or VS Code and add the environment switch:
import os
KALSHI_ENV = os.getenv("KALSHI_ENVIRONMENT", "prod").lower()
if KALSHI_ENV == "demo":
BASE_URL = "https://external-api.demo.kalshi.co"
else:
BASE_URL = "https://api.elections.kalshi.com"Add PowerShell functions to your $PROFILE for easy switching:
# Open profile:
notepad $PROFILE
# Add these lines:
function kalshi-demo { $env:KALSHI_ENVIRONMENT = "demo"; Write-Host "→ DEMO" }
function kalshi-prod { $env:KALSHI_ENVIRONMENT = "prod"; Write-Host "→ PRODUCTION" }5. Fixing the Missing Positions Bug
Symptom: kalshi positionsshows "No open positions" even with open trades.
Cause: Kalshi changed their API — the integer position field was replaced by a string field position_fp. The CLI filters on the old field, so all positions read as zero and get dropped.
In the same cli.py from Section 4, find and replace the position-loading block:
# Before (original two lines):
ps = data.get("market_positions", [])
ps = [p for p in ps if p.get("position", 0) != 0]
# After (replace with this block):
ps = data.get("market_positions", [])
for p in ps:
if p.get("position", 0) == 0 and p.get("position_fp"):
try:
p["position"] = int(float(p["position_fp"]))
except (ValueError, TypeError):
pass
ps = [p for p in ps if p.get("position", 0) != 0]No restart needed. Run kalshi positions to verify your open positions now appear.
6. Troubleshooting Checklist
| Problem | Fix |
|---|---|
| python not found | Reinstall Python with "Add to PATH" checked |
| openssl not found | Install Win64 OpenSSL from slproweb.com |
| Env vars not loading | Close and reopen PowerShell after setting |
| cli.py not found | Run: python -c "import kalshi_cli; print(kalshi_cli.__file__)" |
| InvalidByte error | Run the OpenSSL PKCS8 conversion in Section 3 |
| NOT_FOUND on demo | Patch BASE_URL in cli.py as described in Section 4 |
| No open positions | Apply the position_fp backfill patch in Section 5 |
Next Steps
CLI running? The next step is the 5-step AI trading workflow. The Claude Kalshi Playbook ($17) covers scanning for opportunities, stress-testing research with an adversarial AI pass, and executing trades with smart order placement.