{"id":12764,"library":"kalshi-typescript","title":"Kalshi TypeScript Client","description":"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.","status":"active","version":"3.13.0","language":"javascript","source_language":"en","source_url":"https://github.com/GIT_USER_ID/GIT_REPO_ID","tags":["javascript","axios","typescript","openapi-client","openapi-generator","kalshi-typescript"],"install":[{"cmd":"npm install kalshi-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add kalshi-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add kalshi-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as the underlying HTTP client for all API requests.","package":"axios","optional":false}],"imports":[{"note":"The primary way to configure the client, including API keys and base path. Supports both ESM and CommonJS.","wrong":"const { Configuration } = require('kalshi-typescript');","symbol":"Configuration","correct":"import { Configuration } from 'kalshi-typescript';"},{"note":"Represents the API client for managing API keys. Most API service clients are named exports.","wrong":"import ApiKeysApi from 'kalshi-typescript';","symbol":"ApiKeysApi","correct":"import { ApiKeysApi } from 'kalshi-typescript';"},{"note":"Imports the TypeScript interface for the response payload of the getApiKeys method. Type imports are automatically resolved.","wrong":"import { type GetApiKeysResponse } from 'kalshi-typescript';","symbol":"GetApiKeysResponse","correct":"import { GetApiKeysResponse } from 'kalshi-typescript';"}],"quickstart":{"code":"import { Configuration, ApiKeysApi } from 'kalshi-typescript';\n\n// Ensure your Kalshi API key is set as an environment variable\n// For production, use secure secret management best practices.\nconst KALSHI_API_KEY = process.env.KALSHI_API_KEY ?? '';\n\nif (!KALSHI_API_KEY) {\n  console.error('KALSHI_API_KEY environment variable is not set.');\n  process.exit(1);\n}\n\n// Initialize the Configuration object with your API key and base path.\nconst config = new Configuration({\n  apiKey: KALSHI_API_KEY,\n  basePath: 'https://api.elections.kalshi.com/trade-api/v2' // As specified in the README\n});\n\n// Create an instance of the API client you want to use.\nconst apiKeysApi = new ApiKeysApi(config);\n\nasync function listApiKeys() {\n  try {\n    console.log('Attempting to fetch Kalshi API keys...');\n    const response = await apiKeysApi.getApiKeys();\n    console.log('Successfully retrieved API keys.');\n\n    if (response.data && response.data.api_keys && response.data.api_keys.length > 0) {\n      response.data.api_keys.forEach(key => {\n        console.log(`  - Key ID: ${key.api_key_id}, Name: ${key.name}, Created At: ${new Date(key.created_at * 1000).toLocaleString()}`);\n      });\n    } else {\n      console.log('No API keys found for this account.');\n    }\n  } catch (error: any) {\n    console.error('Error fetching API keys:', error.message);\n    if (error.response) {\n      console.error('Response data:', error.response.data);\n      console.error('Response status:', error.response.status);\n    }\n  }\n}\n\nlistApiKeys();","lang":"typescript","description":"This quickstart initializes the Kalshi client with an API key and fetches a list of existing API keys, demonstrating basic authentication and API interaction."},"warnings":[{"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.","message":"As 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Hardcoding 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The API request failed due to invalid or missing authentication credentials (API key).","error":"Error: Request failed with status code 401"},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'data')"},{"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.","cause":"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.","error":"Property 'someMethod' does not exist on type 'SomeApi'. Did you mean 'someOtherMethod'?"}],"ecosystem":"npm"}