@spfunctions/sdk is the TypeScript data and contract client for SimpleFunctions.
It is now published as a stable package:
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 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
fetch API.
Authentication
Most useful SDK calls require a SimpleFunctions API key.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:/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:
new SimpleFunctions().world.get() should fail with MissingApiKeyError unless SF_API_KEY is available in the environment.
Read And Research Surfaces
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 throughsf.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.
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 defaultbaseUrl 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.inspectruns 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.candleshits the Vercel API route, then proxies to the terminal/Fly candle service behindTERMINAL_BASE.- The SDK does not call Kalshi, Polymarket, the CLI, or a local runtime directly unless you set
baseUrlorSF_API_URLto a local/self-hosted SimpleFunctions API.
Authenticated User Reads
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:Request Metadata
SDK responses carry source metadata where the API provides it:Pagination Helpers
Some authenticated reads return SimpleFunctions page envelopes:Contract Truth
The SDK uses/api/contracts/tools as its strict truth source.
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
| Surface | Use it for |
|---|---|
@spfunctions/sdk | Typed data, user reads/writes, contract inspection |
@spfunctions/agent | Cursor-style market-intelligence agent runtime |
@spfunctions/agent/v1 | Compatibility subpath for the same model-loop exports |
sf agent --tool | Command-line direct tool wrapper |
/api/contracts/tools | Canonical SDK/Agent truth |
/api/tools | Broad hosted compatibility inventory |
| MCP server | Broad agent-client adapter, not SDK truth |
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.relatedauth.statusinvestigations.createintents.proposewebhooks.create