Skip to main content
@spfunctions/sdk is the TypeScript data and contract client for SimpleFunctions. It is now published as a stable package:
Use the stable 1.0.1 package in server-side TypeScript services, agents, and internal tools.

What The SDK Is

The SDK is a typed wrapper over stable SimpleFunctions HTTP objects and the strict contract manifest. Use it when you want to build:
  • market-intelligence dashboards
  • internal research tools
  • macro policy monitors
  • election and legislation workflows
  • portfolio and thesis review tools
  • Agent SDK runtimes that need an identity-bearing client
The SDK is not:
  • the CLI
  • the Agent SDK
  • an MCP client
  • a browser runtime for long-lived API keys
  • a trading engine
  • a wrapper around every SimpleFunctions API route

Install

Node 18 or newer is required because the SDK uses the platform fetch API.

Authentication

Most useful SDK calls require a SimpleFunctions API key.
Then construct the client:
The constructor also reads process.env.SF_API_KEY and process.env.SF_API_URL when explicit options are omitted. Do not expose a long-lived SF_API_KEY in browser code. Use the SDK from a server process, worker, backend job, notebook, or local agent harness.

No-key Bootstrap

The SDK is API-key-first, but strict manifest inspection works without a key:
No-key bootstrap is intentionally narrow. Data, research, user-data, and cost-bearing calls are preflighted against /api/contracts/tools metadata. If the contract has costEffect !== "none", sideEffect !== "none", authRequired: true, user_data permission, or access.anonymousAllowed: false, the SDK throws MissingApiKeyError before making the live request.

First Data Call

world.read is a real hosted data call. Its strict contract currently has:
So new SimpleFunctions().world.get() should fail with MissingApiKeyError unless SF_API_KEY is available in the environment.

Read And Research Surfaces

These are read or research calls with sideEffect: "none". They still require identity when the strict contract marks them as cost-bearing.

Market Intelligence Surfaces

The SDK also exposes existing market-intelligence API surfaces through sf.intelligence.*. These are the pieces a fund, macro desk, election office, or internal research team usually needs before they build an application: screeners, regime scans, calendars, index history, contagion signals, cross-venue pairs, yield curves, and calibration summaries.
Trader-style market data lives under sf.markets.*:
sf.markets.candles() maps to market.candles and returns OHLCV/K-line bars for 1m, 5m, 15m, 1h, and 1d. Pass venue: "kalshi" or venue: "polymarket" when the market id is ambiguous. screenCandles() is a bounded-concurrency client-side helper for watchlist-first momentum, range, volatility, and volume screening. These calls still follow the API-key-first contract. They are read-only, but they are real hosted data and analytics calls, so no-key callers get MissingApiKeyError before the SDK sends a request.

Data Routing

The SDK default baseUrl is https://simplefunctions.dev. Agent SDK tools use the same SDK client. That means contract-info reads such as sf.markets.get() and agent.call("market.inspect", ...) hit the Vercel API surface first. From there, routing is endpoint-specific:
  • market.inspect runs on the SimpleFunctions API server and returns price, spread, orderbook depth levels, and liquidity score. The server may read DB/cache rows, use the configured Kalshi orderbook proxy, fall back to server-side Kalshi credentials, or call Polymarket CLOB.
  • market.candles hits the Vercel API route, then proxies to the terminal/Fly candle service behind TERMINAL_BASE.
  • The SDK does not call Kalshi, Polymarket, the CLI, or a local runtime directly unless you set baseUrl or SF_API_URL to a local/self-hosted SimpleFunctions API.

Authenticated User Reads

These calls require SF_API_KEY because they are account-scoped user-data reads or governed user writes.

User Writes In 1.0

The SDK includes thesis write methods:
These methods are not enabled as default Agent-callable tools. Their strict contracts are implemented, authenticated, and marked:

Request Metadata

SDK responses carry source metadata where the API provides it:
Typed errors also carry request metadata:
The SDK exports typed errors for missing or invalid keys, permission failures, validation failures, not-found responses, conflicts, rate limits, upstream failures, invalid JSON, and timeouts.

Pagination Helpers

Some authenticated reads return SimpleFunctions page envelopes:

Contract Truth

The SDK uses /api/contracts/tools as its strict truth source.
Current production manifest:
Use canonical dotted names such as world.read, markets.search, and market.inspect. Do not treat /api/tools names such as get_world_state as SDK contract names. /api/tools is the broader hosted compatibility inventory.

Boundary With CLI And Agent SDK

Execution Surfaces

Kalshi and Polymarket execution are exposed through explicit, governed contract tools:
execution.place checks cloud and configured SDK runtime candidates before creating the intent. Hosted cloud status is daemon-aware: a Fly machine that is started but has no live runtime daemon is not treated as executable, so ensure starts or wakes the daemon when allowed. Polymarket execution requires a CLOB token id and an explicit limit price; venue signing is handled by the runtime with user-configured exchange credentials. Set runtime: { mode: "none" } only for an explicit intent-only workflow. The SDK package does not depend on the CLI package. Agent SDK callers must opt in through policy before these tools are callable, for example maxSideEffect: "live_trade", maxCostEffect: "venue_request_cost", and trade guardrails such as venue/ticker allowlists, blocked venues, jurisdiction requirements, max quantity, max order cost, required limit prices, confirmation tokens, and allowRuntimeStart: false when runtime startup must be operator-controlled.

Not In SDK 1.0

The SDK does not include:
  • browser long-lived API keys
  • every CLI command
  • every /api/public/* route
  • every MCP tool
  • events.*
  • market.related
  • auth.status
  • investigations.create
  • intents.propose
  • webhooks.create
Those surfaces require separate contract, auth, side-effect, cost, and policy decisions before becoming SDK or Agent SDK surfaces.