API

Python & TypeScript SDKs for Developers

Two official clients, Python and TypeScript, generated from the OpenAPI contract: every route is a typed method named after its path, pagination is followed for you, errors are typed exceptions carrying the stable error.code, retries respect Retry-After, and the WebSocket stream reconnects by itself.

Building your own AI agent? Each typed method can back one of its tools (tool calling): the AI agent picks the tool, the SDK makes the call, follows the pages and raises typed errors. To give the data to an existing AI agent — Claude, ChatGPT, Cursor — without code, connect it to the MCP server instead.

#Install

The packages are published on PyPI and npm under the name bytnode. Their source and changelog live in the public repository github.com/bytnode/bytnode-SDK.

pip install bytnode
# with pandas: pip install "bytnode[pandas]"
export BYTNODE_API_KEY="your_key"

Both read the key from the BYTNODE_API_KEY environment variable, the name every example of this documentation uses.

#First calls

from datetime import datetime, timedelta, timezone

from bytnode import Bytnode

client = Bytnode()  # reads BYTNODE_API_KEY

rate = client.funding.rate("BTCUSDT")
if rate.data:  # None when there is no value: rate.unavailable says why
    print(rate.data.rate_pct, rate.data.time)

# every page of a history, followed for you, into one DataFrame
# (to_pandas() needs pandas: pip install pandas)
since = datetime.now(timezone.utc) - timedelta(days=7)  # inside every plan's window
df = client.klines.history.iter("BTCUSDT", "1d", since=since).to_pandas()

client.close()  # or: with Bytnode() as client: ...

#What the clients do for you

  • The URL is the method. /v1/funding/rate/history is client.funding.rate.history(...); each row is a typed model with the contract’s own field names, dates already converted.
  • Pagination. .iter() follows next page after page until it is null, with the largest pages the route allows; time bounds as a date, an ISO string or epoch milliseconds.
  • Errors. One exception per situation (invalid request, permission denied, rate limit...) carrying code, param and the server’s message.
  • Retries. 429 and 503 wait for Retry-After; 502, 503, 504 and network errors back off with jitter; a spent monthly quota fails fast.
  • Stream. Reconnection with backoff, re-subscription, typed messages and loss detection from seq.

#SDK or MCP server?

  • The MCP server when the AI agent already exists — Claude, ChatGPT, Cursor or any MCP client: a URL and your key, twenty-one tools, no code to write.
  • The SDK when you write the code: a script, a backend, a dashboard, a backtest, or the tools of your own AI agent.
  • Both read the same plan and the same market data, under the same field names and units.

With an AI coding agent (Claude Code, Codex, Cursor), the bytnode-sdk Agent Skill teaches it to write code with these clients: install, history into pandas, errors and retries, streaming. See all the Agent Skills.

#Generate your own client

The contract is built for code generators:

  • every operation has a readable operationId (getFundingRateHistory);
  • every response has a named schema (FundingRate, Kline, Trade...);
  • closed values are enums (timeframe, asset, order).

For another language, generate from https://api.bytnode.com/openapi.json (OpenAPI 3.1), or from https://api.bytnode.com/openapi-3.0.json, the same contract in OpenAPI 3.0 for generators that do not read 3.1 yet:

bash
# TypeScript types
npx openapi-typescript https://api.bytnode.com/openapi.json -o bytnode.d.ts

# Python client
pipx run openapi-python-client generate --url https://api.bytnode.com/openapi.json

# A generator that reads only OpenAPI 3.0 (openapi-generator, older tools)
npx @openapitools/openapi-generator-cli generate -g typescript-fetch \
  -i https://api.bytnode.com/openapi-3.0.json -o bytnode-client

#Versions

The SDK version follows its own changelog; each release is generated from one version of the contract, which every response announces in the BytNode-Contract-Version header. Compare the two to know whether the contract has moved since your client was generated. See Versioning.

bytnode 1.0.2 · contract 1.2.0