@kalshi-kit/next
v0.1.2
Published
One-line Next.js helper that proxies Kalshi API requests through your app
Maintainers
Readme
@kalshi-kit/next
One-line Next.js helper that proxies Kalshi API requests through your app, so the browser stays inside its own origin. No API key is required for public market data.
Install
npm install @kalshi-kit/nextQuick start
Wrap your Next.js config with withKalshi():
// next.config.mjs
import { withKalshi } from "@kalshi-kit/next";
export default withKalshi();That mounts /api/kalshi/* and forwards each request to https://api.elections.kalshi.com/trade-api/v2/*. Pair it with @kalshi-kit/react and your components fetch through your own origin automatically.
To override the prefix or point at the demo environment:
export default withKalshi(
{ reactStrictMode: true },
{ prefix: "/api/kalshi", upstream: "https://demo-api.kalshi.co/trade-api/v2" },
);Features
| Export | What it does |
| --- | --- |
| withKalshi(config?, options?) | Wraps your next.config.{js,mjs,ts} and adds a rewrite that proxies /api/kalshi/* to the Kalshi API. |
| kalshiRouteHandler | Drop-in App Router handler if you'd rather see the proxy as an explicit app/api/kalshi/[...path]/route.ts file. Re-export it as GET, POST, PUT, and DELETE. |
// app/api/kalshi/[...path]/route.ts
import { kalshiRouteHandler } from "@kalshi-kit/next";
export const GET = kalshiRouteHandler;
export const POST = kalshiRouteHandler;
export const PUT = kalshiRouteHandler;
export const DELETE = kalshiRouteHandler;Monorepo
Source, issues, and the live demo live at github.com/sam-shridhar1950f/kalshi-kit.
License
MIT
