This process is the same for the demo or production environment.
Key types
Kalshi API keys are asymmetric key pairs: you sign each request with the private key, and Kalshi verifies the signature with the registered public key. Two key types are supported:
Headers, pre-sign text, permissions and errors are identical for both types. Kalshi
selects the verification algorithm from the registered public key; sign with the
algorithm that matches your key.
The PEM header does not identify the key type: PKCS#8 RSA keys, including
openssl genpkey output, also begin with -----BEGIN PRIVATE KEY-----.
Determine the type from the parsed key, as the samples below do.
Generating an API Key
Access the Account Settings Page:
Log in to your account and navigate to the “Account Settings” page. You can typically find this option by clicking on your profile picture or account icon in the top-right corner of the application.Generate a New API Key
In the “Profile Settings” page https://kalshi.com/account/profile, locate the “API Keys” section. Click on the “Create New API Key” button to generate a key pair. Ed25519 is selected by default; choose RSA if your client supports only RSA-PSS. You can also register your own public key (below) or usePOST /trade-api/v2/api_keys/generate with key_type.
To register your own public key of either type, in PEM format:
kalshi.pub into the public key field. The private key never leaves your system.
Store Your API Key and Key ID:
After generating the key, you will be presented with: • Private Key: your secret key in PEM format. • Key ID: This is a unique identifier associated with your private key. Important: For security reasons, the private key will not be stored by our service, and you will not be able to retrieve it again once this page is closed. Please make sure to securely copy and save the private key immediately. The key will also be downloaded as txt file with the name provided. Keys can also be created through the API:POST /trade-api/v2/api_keys registers your public key; POST /trade-api/v2/api_keys/generate returns a new key pair of the requested key_type (rsa when omitted). Both are available on every API tier.
In production, an account can hold up to 100 keys that it manages directly, meaning keys created on the account settings page or with these two endpoints. Creating another returns 409 with code MAXIMUM_NUMBER_OF_API_KEYS_REACHED; delete one of those keys with DELETE /trade-api/v2/api_keys/{api_key} first. Keys issued to the account in other ways, such as through a partner integration, are counted separately. The limit can differ in the demo environment.
Using a API Key
Each request to Kalshi trading api will need to be signed with the private key generated above. The following header values will need to be provided with each request:KALSHI-ACCESS-KEY- the Key ID
KALSHI-ACCESS-TIMESTAMP - the request timestamp in ms
KALSHI-ACCESS-SIGNATURE- request hash signed with private key
The signature is the base64 encoding of the signed concatenation of the timestamp, the HTTP method and the path. Ed25519 keys sign the string directly; RSA keys use RSA-PSS with SHA-256 (MGF1 with SHA-256, salt length equal to the digest length).
The samples below detect the key type and sign accordingly. For end-to-end examples, see Quick Start: Authenticated Requests. The official Python and TypeScript SDKs accept either key type from version 3.31.0.
Python
Load the private key stored in a fileJavascript
Load the private key stored in a fileScopes
Each key carries a list of scopes, set when the key is created (scopes on Create API Key and Generate API Key). A key created without scopes gets read and write, which is full access. Accounts with data-only access are the exception: their keys are always read-only, whatever scopes the request names. Scopes never widen what the account itself is allowed to do.
A parent scope grants its child scopes: write covers write::trade, write::transfer, write::fcm_risk and write::block_trade_accept, and read covers read::portfolio_balance and read::block_trade_accept. A child scope never grants its parent, and no write scope grants read.
The table covers the operations listed, not every endpoint. A write that is not listed needs either
write or one of the child scopes above. A request the key’s scopes do not cover returns 403, and the error code names the scope that endpoint needs, for example insufficient_scope:_write::trade_required, so you can read the exact requirement from the response.
Because every GET needs read, a key that holds only write::trade can place and cancel orders but cannot list orders, fills or positions. Give a trading key read as well, or track state from the write responses.
Public endpoints such as market data need no scope.
Authentication errors
A request whose credentials are rejected returns401 with an error object. Problems with the headers themselves have their own code:
Every other rejection returns
401 with the code authentication_error, and the details field carries the reason:
message text is generic and is the same for every authentication_error, so branch on details. Other details values are possible.
Check the HTTP status before deciding whether to retry. A 401 means the credentials were rejected, and sending the same request again will not help. The same authentication_error code is also returned with a 500 or 503 status when Kalshi could not complete the check, for example during a brief outage. Those are not credential problems: keep your key and retry with backoff.