Registry / http-networking / kalshi-typescript

kalshi-typescript

JSON →
library3.13.0jsnpmunverified

This package provides a TypeScript/JavaScript client for interacting with the Kalshi API, automatically generated from an OpenAPI specification. It leverages `axios` for HTTP requests and is currently at version 3.13.0. The client supports both Node.js and browser environments, as well as ES5 and ES6 language levels, and CommonJS and ES6 module systems. As a generated client, its release cadence typically follows updates to the underlying Kalshi OpenAPI specification, meaning the client API surface can change with new spec versions. A key differentiator is its comprehensive type definitions, enabling robust development in TypeScript projects and providing compile-time safety for API interactions. It primarily targets the `https://api.elections.kalshi.com/trade-api/v2` endpoint.

npm install kalshi-typescript
INSTALL
IMPORT
SIG · KALSHI-TYPESCRIPT
K
kalshi-typescript
http-networkingjavascriptv3.13.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Configuration
import { Configuration } from 'kalshi-typescript';
const { Configuration } = require('kalshi-typescript');
The primary way to configure the client, including API keys and base path. Supports both ESM and CommonJS.
ApiKeysApi
import { ApiKeysApi } from 'kalshi-typescript';
import ApiKeysApi from 'kalshi-typescript';
Represents the API client for managing API keys. Most API service clients are named exports.
GetApiKeysResponse
import { GetApiKeysResponse } from 'kalshi-typescript';
import { type GetApiKeysResponse } from 'kalshi-typescript';
Imports the TypeScript interface for the response payload of the getApiKeys method. Type imports are automatically resolved.

This quickstart initializes the Kalshi client with an API key and fetches a list of existing API keys, demonstrating basic authentication and API interaction.

import { Configuration, ApiKeysApi } from 'kalshi-typescript'; // Ensure your Kalshi API key is set as an environment variable // For production, use secure secret management best practices. const KALSHI_API_KEY = process.env.KALSHI_API_KEY ?? ''; if (!KALSHI_API_KEY) { console.error('KALSHI_API_KEY environment variable is not set.'); process.exit(1); } // Initialize the Configuration object with your API key and base path. const config = new Configuration({ apiKey: KALSHI_API_KEY, basePath: 'https://api.elections.kalshi.com/trade-api/v2' // As specified in the README }); // Create an instance of the API client you want to use. const apiKeysApi = new ApiKeysApi(config); async function listApiKeys() { try { console.log('Attempting to fetch Kalshi API keys...'); const response = await apiKeysApi.getApiKeys(); console.log('Successfully retrieved API keys.'); if (response.data && response.data.api_keys && response.data.api_keys.length > 0) { response.data.api_keys.forEach(key => { console.log(` - Key ID: ${key.api_key_id}, Name: ${key.name}, Created At: ${new Date(key.created_at * 1000).toLocaleString()}`); }); } else { console.log('No API keys found for this account.'); } } catch (error: any) { console.error('Error fetching API keys:', error.message); if (error.response) { console.error('Response data:', error.response.data); console.error('Response status:', error.response.status); } } } listApiKeys();
Debug
Known issues
breakingAs an OpenAPI generated client, breaking changes to the underlying Kalshi API specification can result in changes to method signatures, request/response bodies, or available endpoints within this client library, even without a major version bump of `kalshi-typescript`. Always review the generated client's documentation or diff the new version if you encounter unexpected behavior after an update.
fix
Consult the Kalshi API documentation and the generated client's `docs/` folder for updated API endpoint and data model information. Regenerate local client if maintaining a fork.
affects: >=1.0.0
gotchaHardcoding API keys directly in your source code or checking them into version control is a severe security risk. API keys provide access to your account and should be treated as sensitive credentials.
fix
Always use environment variables (e.g., `process.env.KALSHI_API_KEY`), a secure configuration management system, or dedicated secret management services to store and retrieve API keys, especially in production environments.
affects: >=1.0.0
gotchaThe `basePath` configured for the client is crucial. Using an incorrect or outdated base path (e.g., accidentally pointing to a sandbox environment when intending production) will lead to authentication failures or interactions with the wrong Kalshi environment.
fix
Ensure the `basePath` in your `Configuration` object matches the target Kalshi API environment (e.g., `https://api.elections.kalshi.com/trade-api/v2` for production). Verify this against the official Kalshi API documentation.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Request failed with status code 401
The API request failed due to invalid or missing authentication credentials (API key).
fix
Verify that your `KALSHI_API_KEY` environment variable is correctly set and contains a valid, active API key from your Kalshi account. Ensure it has the necessary permissions for the API endpoint you are trying to access.
TypeError: Cannot read properties of undefined (reading 'data')
The API response object or its properties are `undefined`, often due to an HTTP error that prevented a successful data payload, or an unexpected response structure.
fix
Wrap your API calls in a `try-catch` block and inspect the `error.response` object for details on the HTTP status code and error message. Ensure your API key is valid and the request parameters are correct.
Property 'someMethod' does not exist on type 'SomeApi'. Did you mean 'someOtherMethod'?
You are attempting to call a method that does not exist on the API client class, likely due to an outdated client library, a typo, or a breaking change in the Kalshi API.
fix
Check the `kalshi-typescript` documentation (especially the `docs/` folder) for the correct method name and signature. Ensure your `kalshi-typescript` package is up-to-date with the latest version from npm.
Upgrade
Version history
3.13.0latest on npm
Audit
Dependencies
axiosrequiredUsed as the underlying HTTP client for all API requests.
Agent activity
4 hits · last 30 days
node
4
Resources
kalshi-typescript — npm install kalshi-typescript · libregistry