All URIs are relative to https://api.elections.kalshi.com/trade-api/v2
MethodHTTP requestDescription
create_api_keyPOST /api_keysCreate API Key
delete_api_keyDELETE /api_keys/Delete API Key
generate_api_keyPOST /api_keys/generateGenerate API Key
get_api_keysGET /api_keysGet API Keys

create_api_key

CreateApiKeyResponse create_api_key(create_api_key_request)
Create API Key Create a new API key with a user-provided public key. This endpoint allows users with Premier or Market Maker API usage levels to create API keys by providing their own RSA public key. The platform will use this public key to verify signatures on API requests.

Example

import kalshi_python
from kalshi_python.models.create_api_key_request import CreateApiKeyRequest
from kalshi_python.models.create_api_key_response import CreateApiKeyResponse
from kalshi_python.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://api.elections.kalshi.com/trade-api/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = kalshi_python.Configuration(
    host = "https://api.elections.kalshi.com/trade-api/v2"
)

# Read private key from file
with open('path/to/private_key.pem', 'r') as f:
    private_key = f.read()

# Configure API key authentication
configuration.api_key_id = "your-api-key-id"
configuration.private_key_pem = private_key

# Initialize the Kalshi client
client = kalshi_python.KalshiClient(configuration)

create_api_key_request = kalshi_python.CreateApiKeyRequest() # CreateApiKeyRequest | 

try:
    # Create API Key
    api_response = client.create_api_key(create_api_key_request)
    print("The response of ApiKeysApi->create_api_key:\n")
    pprint(api_response)
except Exception as e:
    print("Exception when calling ApiKeysApi->create_api_key: %s\n" % e)

Parameters

NameTypeDescriptionNotes
create_api_key_requestCreateApiKeyRequest

Return type

CreateApiKeyResponse

HTTP response details

Status codeDescription
201API key created successfully
400Bad request - invalid input
401Unauthorized - authentication required
403Forbidden - insufficient permissions
500Internal server error
[Back to top] [Back to API list] [Back to Model list] [Back to README]

delete_api_key

delete_api_key(api_key)
Delete API Key Delete an existing API key. This endpoint permanently deletes an API key. Once deleted, the key can no longer be used for authentication. This action cannot be undone.

Example

import kalshi_python
from kalshi_python.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://api.elections.kalshi.com/trade-api/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = kalshi_python.Configuration(
    host = "https://api.elections.kalshi.com/trade-api/v2"
)

# Read private key from file
with open('path/to/private_key.pem', 'r') as f:
    private_key = f.read()

# Configure API key authentication
configuration.api_key_id = "your-api-key-id"
configuration.private_key_pem = private_key

# Initialize the Kalshi client
client = kalshi_python.KalshiClient(configuration)

api_key = 'api_key_example' # str | API key ID to delete

try:
    # Delete API Key
    client.delete_api_key(api_key)
except Exception as e:
    print("Exception when calling ApiKeysApi->delete_api_key: %s\n" % e)

Parameters

NameTypeDescriptionNotes
api_keystrAPI key ID to delete

Return type

void (empty response body)

HTTP response details

Status codeDescription
204API key successfully deleted
400Bad request - invalid input
401Unauthorized - authentication required
404Resource not found
500Internal server error
[Back to top] [Back to API list] [Back to Model list] [Back to README]

generate_api_key

GenerateApiKeyResponse generate_api_key(generate_api_key_request)
Generate API Key Generate a new API key with an automatically created key pair. This endpoint generates both a public and private RSA key pair. The public key is stored on the platform, while the private key is returned to the user and must be stored securely. The private key cannot be retrieved again.

Example

import kalshi_python
from kalshi_python.models.generate_api_key_request import GenerateApiKeyRequest
from kalshi_python.models.generate_api_key_response import GenerateApiKeyResponse
from kalshi_python.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://api.elections.kalshi.com/trade-api/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = kalshi_python.Configuration(
    host = "https://api.elections.kalshi.com/trade-api/v2"
)

# Read private key from file
with open('path/to/private_key.pem', 'r') as f:
    private_key = f.read()

# Configure API key authentication
configuration.api_key_id = "your-api-key-id"
configuration.private_key_pem = private_key

# Initialize the Kalshi client
client = kalshi_python.KalshiClient(configuration)

generate_api_key_request = kalshi_python.GenerateApiKeyRequest() # GenerateApiKeyRequest | 

try:
    # Generate API Key
    api_response = client.generate_api_key(generate_api_key_request)
    print("The response of ApiKeysApi->generate_api_key:\n")
    pprint(api_response)
except Exception as e:
    print("Exception when calling ApiKeysApi->generate_api_key: %s\n" % e)

Parameters

NameTypeDescriptionNotes
generate_api_key_requestGenerateApiKeyRequest

Return type

GenerateApiKeyResponse

HTTP response details

Status codeDescription
201API key generated successfully
400Bad request - invalid input
401Unauthorized - authentication required
500Internal server error
[Back to top] [Back to API list] [Back to Model list] [Back to README]

get_api_keys

GetApiKeysResponse get_api_keys()
Get API Keys Retrieve all API keys associated with the authenticated user. API keys allow programmatic access to the platform without requiring username/password authentication. Each key has a unique identifier and name.

Example

import kalshi_python
from kalshi_python.models.get_api_keys_response import GetApiKeysResponse
from kalshi_python.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://api.elections.kalshi.com/trade-api/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = kalshi_python.Configuration(
    host = "https://api.elections.kalshi.com/trade-api/v2"
)

# Read private key from file
with open('path/to/private_key.pem', 'r') as f:
    private_key = f.read()

# Configure API key authentication
configuration.api_key_id = "your-api-key-id"
configuration.private_key_pem = private_key

# Initialize the Kalshi client
client = kalshi_python.KalshiClient(configuration)

try:
    # Get API Keys
    api_response = client.get_api_keys()
    print("The response of ApiKeysApi->get_api_keys:\n")
    pprint(api_response)
except Exception as e:
    print("Exception when calling ApiKeysApi->get_api_keys: %s\n" % e)

Parameters

This endpoint does not need any parameter.

Return type

GetApiKeysResponse

HTTP response details

Status codeDescription
200List of API keys retrieved successfully
401Unauthorized - authentication required
500Internal server error
[Back to top] [Back to API list] [Back to Model list] [Back to README]