<!-- source: https://www.secondlayer.tools/docs/sdk-reference -->

# SDK reference

Every method on the client, read from the SDK's own source. One page per surface: pick one below, or start with the [SDK guide](/docs/sdk).

`@secondlayer/sdk@15.5.1`, read from source with openpkg.

## Surfaces

- [Client](/docs/sdk-reference/client): Batched reads and the agent snapshot (2 methods)
- [sl.streams](/docs/sdk-reference/streams): Ordered events, cursors, dumps (14 methods)
- [sl.index](/docs/sdk-reference/index): Decoded rows, sBTC, PoX-5, Runes (54 methods)
- [sl.subgraphs](/docs/sdk-reference/subgraphs): Deploy, read rows, operations (19 methods)
- [sl.webhooks](/docs/sdk-reference/webhooks): Create, deliveries, replay (15 methods)
- [sl.archive](/docs/sdk-reference/archive): Verify, quote, fetch (11 methods)
- [sl.contracts](/docs/sdk-reference/contracts): Find by trait, ABI (2 methods)
- [sl.instance](/docs/sdk-reference/instance): Status, diagnose (2 methods)

## Helpers

46 functions you import directly: [Helpers](/docs/sdk-reference/helpers).

## Errors

10 error classes: [Errors](/docs/sdk-reference/errors).

## Notes for agents

- The client is 'const sl = new SecondLayer()'; every surface hangs off it ('sl.streams', 'sl.index', 'sl.subgraphs', 'sl.webhooks', 'sl.archive', 'sl.contracts', 'sl.instance'), plus 'sl.batch' and 'sl.context' on the client itself.
- One page per surface at 'https://www.secondlayer.tools/docs/sdk-reference/<client|streams|index|subgraphs|webhooks|archive|contracts|instance|helpers|errors>' (each with a .md twin): signatures, overloads, parameters and the types they use.
- Everything is generated from the shipped package, so a name on these pages is a real export. Find the method by asking what the user is building, then show its signature and a snippet.
- When the user is pinned to an older @secondlayer/sdk, compare their version to the one stated on each page before suggesting a method.

## Setup

Ensure setup once, skipping any step already done:
- Skill: `bunx skills add ryanwaits/secondlayer --skill secondlayer -y`
- CLI: `bun add -g @secondlayer/cli`
- Instance: `secondlayer init` writes `INSTANCE_TOKEN`. Loopback `/v1` reads need no key.
- Hosted/archive: export `SECONDLAYER_API_KEY` (`sk-sl_*`) or buy credits with `secondlayer credits buy` (`balance`, `refill`), then `secondlayer whoami`
