> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simplefunctions.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK quickstart

> Install @spfunctions/sdk, inspect the strict manifest, read world state, screen markets, and use guarded Kalshi or Polymarket execution primitives.

Use `@spfunctions/sdk` when a TypeScript service, notebook, dashboard, or agent harness owns the application code.

## 1. Install

```bash theme={null}
npm init -y
npm install @spfunctions/sdk@1.0.1
```

Use Node 18 or newer. Use the stable package version.

## 2. Create the client

```ts theme={null}
import { SimpleFunctions } from "@spfunctions/sdk"

const sf = new SimpleFunctions({
  baseUrl: "https://simplefunctions.dev",
  apiKey: process.env.SF_API_KEY,
})
```

Do not expose long-lived API keys in browser bundles.

## 3. Inspect the manifest without a key

```ts theme={null}
const noKey = new SimpleFunctions({ baseUrl: "https://simplefunctions.dev" })

const manifest = await noKey.manifest.list()
const world = await noKey.manifest.get("world.read")
const legacy = await noKey.manifest.get("get_world_state")

console.log(manifest.schemaVersion)
console.log(world?.name)
console.log(legacy) // null
```

The SDK uses canonical dotted names from `/api/contracts/tools`.

## 4. Read market context

```ts theme={null}
const worldState = await sf.world.get()
const delta = await sf.world.delta({ since: "1h" })

const screen = await sf.intelligence.screen({
  venue: "kalshi",
  volMin: 100,
  sort: "volume",
  order: "desc",
  limit: 10,
  nextActions: false,
})

const ticker = screen.markets[0]?.ticker
const inspected = ticker ? await sf.markets.get(ticker) : null
```

## 5. Read portfolio and runtime state

```ts theme={null}
const portfolio = await sf.portfolio.state()
const runtime = await sf.runtime.status()

console.log(portfolio?.openPositionCount)
console.log(runtime.usable.length)
```

## 6. Guard execution explicitly

```ts theme={null}
const result = await sf.execution.place({
  ticker: "KXFED-27APR-T3.50",
  action: "buy",
  direction: "yes",
  quantity: 1,
  limitPrice: 32,
  rationale: "operator-approved test order",
  runtime: { mode: "auto", startIfNeeded: true },
})

const polyResult = await sf.execution.place({
  venue: "polymarket",
  tokenId: "POLYMARKET_CLOB_TOKEN_ID",
  action: "buy",
  quantity: 1,
  limitPrice: 32,
  rationale: "operator-approved test order",
  runtime: { mode: "auto", startIfNeeded: true },
})
```

`execution.place` supports Kalshi and Polymarket through the runtime-backed intent path. It checks runtime candidates and starts or wakes a usable runtime when allowed before creating the intent. Polymarket orders require a CLOB token id and explicit limit price. Use small limits, explicit rationale, and your own application-level guardrails.

## Next steps

<CardGroup cols={2}>
  <Card title="SDK" href="/sdk">
    Full SDK surface.
  </Card>

  <Card title="SDK market research cookbook" href="/cookbook/sdk-market-research-loop">
    Build a read-only research loop.
  </Card>

  <Card title="Execution guardrails cookbook" href="/cookbook/sdk-kalshi-execution-guardrails">
    Runtime and order safety pattern.
  </Card>

  <Card title="Agent SDK quickstart" href="/start/agent-sdk-quickstart">
    Add a model loop and policy hooks.
  </Card>
</CardGroup>
