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
PythonTypeScript
Packagelangbot-sdk on PyPI (imports as langbot)@langbotai/sdk on npm
RuntimePython 3.12+Node 20+; the client core is browser-safe
ClientLangbotClient (async)LangbotClient
Commandlangbotnpx @langbotai/sdk

Install

Terminal
pip install langbot-sdk

Authenticate

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.

Terminal
export LANGBOT_API_TOKEN=lb_...
# or save it once for both SDKs and both commands:
langbot login --token lb_...      # ~/.config/langbot/config.toml

Both 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

Python
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())

Stream live events

The stream reconnects on its own with jittered backoff and resends your filters. Leave out events to follow whatever is live.

Python
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())

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.

Python
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())

The langbot command

The Python package installs the full command; the npm package's command covers the live record and receipts.

CommandWhat it doesPythonnpm
markets [query], market <ticker>search every listed market; one market's history and resultyes
events, calendar, watch <event_id|all>what is live and coming up; follow phrase hits as they arriveyesyes
context <ticker>, brief <ticker>, rates, outcomes, speakersone market in context; settled history by speaker and phraseyesyes
subscribefollow a market or phrases on your accountyesyes
sim events, sim run, sim studyreplay a past event against its recorded books (Simulator)yes
research bench, research calibrationone idea across the whole record, with intervalsyes
backtest <file>replay a local JSONL file of events and booksyes
run <file>, status, live run, live haltrun a strategy on paper or live, on your machine (Live trading)yesrun, status
receipt, replay, verify, attestreceipts: check the record offlineyesyes
login, init, config, mcp installsign in; set up; connect your agentyesyes

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.