Python and TypeScript SDKs
Install the SDK, authenticate once, and read markets, history and live events from Python or TypeScript. Both are MIT-licensed and ship a `langbot` command.
On this page
| Python | TypeScript | |
|---|---|---|
| Package | langbot-sdk on PyPI (imports as langbot) | @langbotai/sdk on npm |
| Runtime | Python 3.12+ | Node 20+; the client core is browser-safe |
| Client | LangbotClient (async) | LangbotClient |
| Command | langbot | npx @langbotai/sdk |
Install
pip install langbot-sdkuv add langbot-sdk # in a project
uv tool install langbot-sdk # just the `langbot` commandpoetry add langbot-sdknpm i @langbotai/sdkpnpm add @langbotai/sdkyarn add @langbotai/sdkbun add @langbotai/sdkAuthenticate
Public markets, the live calendar and recent events work without a token (at the Free plan's delay). Everything else needs one from langbot.ai/app/tokens.
export LANGBOT_API_TOKEN=lb_...
# or save it once for both SDKs and both commands:
langbot login --token lb_... # ~/.config/langbot/config.tomlBoth clients read LANGBOT_API_TOKEN (then the saved config) when you pass no token, and LANGBOT_API_URL when you point them at another feed.
Read markets and history
import asyncio
from langbot import LangbotClient
async def main():
async with LangbotClient() as lb:
page = await lb.public_markets("fed", status="open", limit=5)
ticker = page["markets"][0]["ticker"]
market = await lb.public_market(ticker)
print(market["title"], market["series"]["source"], len(market["series"]["points"]))
rates = await lb.base_rates(speaker="powell", phrase="transitory")
print(rates.markets, rates.yes_rate)
asyncio.run(main())import { LangbotClient } from "@langbotai/sdk";
const lb = new LangbotClient();
const page = await lb.publicMarkets({ q: "fed", status: "open", limit: 5 });
const market = await lb.publicMarket(String(page.markets[0].ticker));
console.log(market.title);
const rates = await lb.baseRates({ speaker: "powell", phrase: "transitory" });
console.log(rates.markets, rates.yes_rate);Stream live events
The stream reconnects on its own with jittered backoff and resends your filters. Leave out events to follow whatever is live.
import asyncio
from langbot import LangbotClient
async def main():
async with LangbotClient() as lb:
async for evt in lb.stream(types=["phrase_detected"]):
print(evt.event_id, evt.phrase, evt.market_refs, evt.verdict)
asyncio.run(main())import { LangbotClient } from "@langbotai/sdk";
const lb = new LangbotClient();
for await (const evt of lb.stream({ types: ["phrase_detected"] })) {
console.log(evt.event_id, evt.phrase, evt.market_refs, evt.verdict);
}Behind a proxy that blocks WebSockets, use stream_sse() / streamSSE(): same filters, same events. The wire protocol is on WebSocket.
Errors
Every API error carries the feed's stable code (token_invalid, rate_limited, quota_exceeded, …) beside the HTTP status. Branch on the code, not the message; the full list is in the REST API reference.
import asyncio
from langbot import LangbotAPIError, LangbotClient
async def main():
async with LangbotClient() as lb:
try:
await lb.me()
except LangbotAPIError as e:
print(e.status, e.code, e.detail)
asyncio.run(main())import { LangbotAPIError, LangbotClient } from "@langbotai/sdk";
try {
await new LangbotClient().me();
} catch (e) {
if (e instanceof LangbotAPIError) console.log(e.status, e.code, e.detail);
}The langbot command
The Python package installs the full command; the npm package's command covers the live record and receipts.
| Command | What it does | Python | npm |
|---|---|---|---|
markets [query], market <ticker> | search every listed market; one market's history and result | yes | |
events, calendar, watch <event_id|all> | what is live and coming up; follow phrase hits as they arrive | yes | yes |
context <ticker>, brief <ticker>, rates, outcomes, speakers | one market in context; settled history by speaker and phrase | yes | yes |
subscribe | follow a market or phrases on your account | yes | yes |
sim events, sim run, sim study | replay a past event against its recorded books (Simulator) | yes | |
research bench, research calibration | one idea across the whole record, with intervals | yes | |
backtest <file> | replay a local JSONL file of events and books | yes | |
run <file>, status, live run, live halt | run a strategy on paper or live, on your machine (Live trading) | yes | run, status |
receipt, replay, verify, attest | receipts: check the record offline | yes | yes |
login, init, config, mcp install | sign in; set up; connect your agent | yes | yes |
langbot --help (or npx @langbotai/sdk --help) lists every option.
Source and license
Both SDKs and the MCP server are MIT-licensed; the README on each package page has the full method list. The hosted service they talk to is Langbot's own and is governed by the terms.