Without credentials, the client can fetch every market-data endpoint. With credentials, it can also fetch portfolio data. Every request is signed for you, pages are followed automatically, and rate-limit and server errors are retried with exponential backoff.
Parameters
api_key_id:str, optional
Your Kalshi API key ID.
private_key:str or bytes, optional
The private key’s PEM text. Use this or private_key_path, not both.
private_key_path:str or os.PathLike, optional
Path to the private key .pem file. ~ is expanded.
environment:{'prod', 'demo'}, default 'prod'
Which Kalshi exchange to use. Demo keys only work on demo, and production keys only work on production.
base_url:str, optional
A custom API base URL. Overrides environment.
timeout:float, default 30.0
Seconds to wait for each HTTP response.
max_retries:int, default 3
How many times to retry a request that gets a rate-limit (429) or server (5xx) error, with exponential backoff.
session:requests.Session, optional
Use your own HTTP session, for example to add a proxy or for testing. By default, the client builds one with retries.
Returns
KalshiClient
A new client.
Attributes and other methods
Name
Type
Description
client.is_authenticated
bool
True if the client has credentials.
client.base_url
str
The API URL in use. The defaults are in kd.BASE_URLS ({"prod": ..., "demo": ...}).
client.close()
method
Closes the HTTP session. You can also use the client as a context manager (see below).
Raises
KalshiAuthError
If only one of api_key_id and a private key is given, or the key file can’t be read or parsed.