You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SyncTransport.__init__ caches self._base_path = urlparse(config.base_url).path and signs requests with sign_path = self._base_path + path. The signature MUST be computed over the canonical server-visible path (/trade-api/v2/markets).
If a user constructs KalshiConfig(base_url="https://api.elections.kalshi.com") — dropping the /trade-api/v2 path component, which _validate_url does NOT require — _base_path becomes "" and every request is signed as /markets instead of /trade-api/v2/markets. Worse:
The httpx request goes to https://api.elections.kalshi.com/markets (no /trade-api/v2 prefix), producing a 404.
If the user adds /trade-api/v2/ to each call manually thinking they have to compensate, signing breaks invisibly with 401s.
_validate_url (kalshi/config.py:67-95) validates scheme + host but never path, so this misconfig is undetectable until first request.
# kalshi/_base_client.py:102self._base_path=urlparse(config.base_url).path# "" if base_url has no path# kalshi/_base_client.py:136sign_path=self._base_path+path# corrupted if path component missing
# kalshi/config.py:67-95# _validate_url checks scheme + host only, never path → misconfig is silent
Recommended fix
In KalshiConfig.__post_init__ (or _validate_url), require the base_url path to be the canonical versioned segment (/trade-api/v2). Two options:
Strict (recommended):
parsed=urlparse(base_url)
ifparsed.pathnotin ("/trade-api/v2", "/trade-api/v2/"):
raiseValueError(
f"KalshiConfig.base_url must include the /trade-api/v2 path component, "f"got base_url={base_url!r}"
)
Lenient (auto-fix):
If path is empty/just /, append /trade-api/v2 and log a warning. Strict is preferred because it surfaces the misconfig at construction.
Activity