.md

Client

What the client does itself, beside its surfaces: batched reads and the one-call account snapshot. Constructor options are in the SDK guide.

@secondlayer/sdk@15.5.02 methodsfrom source with openpkgSDK guideInstance API
new SecondLayer(options)
batch(requests){ results: { path: string | null; s…Run up to 10 public reads in one round trip (POST /v1/batch).
context()ContextSnapshotGet a one-call snapshot of your account and instance.
new SecondLayer(
options?: {
baseUrl?: string;
apiKey?: string;
accountKey?: string;
fetchImpl?: FetchLike;
dumpsBaseUrl?: string;
archiveBaseUrl?: string;
archiveOpsUrl?: string;
origin?: "cli" | "mcp" | "session";
verify?: boolean | { publicKey: string; };
verifyDumpsManifest?: boolean;
requestTimeoutMs?: number;
etagCache?: false | EtagCache;
},
)

Parameters

hover a row to find it in the code

Options

baseUrlstringBase URL of the instance API (trailing slashes are stripped).
apiKeystringBearer token for authenticated requests. Defaults to SECONDLAYER_API_KEY on api.secondlayer.tools, INSTANCE_TOKEN elsewhere.
accountKeystringHosted account key (sk-sl_*). Env SECONDLAYER_API_KEY. Used by sl.archive quote/fetch/credits; reaches /v1 and /api only through apiKey when the base URL is the hosted API.
fetchImplFetchLikeFetch implementation. Tests and edge runtimes can provide their own.
dumpsBaseUrlstringPublic base URL for Streams bulk parquet dumps (the cold backfill plane). Required for streams.dumps.*; without it the dumps client falls back to its built-in default.
archiveBaseUrlstringPublic base URL for the signed canonical archive tree. Defaults to https://archive.secondlayer.tools. Reaches sl.archive.
archiveOpsUrlstringCredits and fetch-gate API. Defaults to https://api.secondlayer.tools, not baseUrl. Reaches sl.archive quote/fetch/credits.
origin"cli" | "mcp" | "session"Deploy origin label sent as x-sl-origin (telemetry). Defaults to cli.
4 more options
verifyboolean | { publicKey: string; }Check the ed25519 signature on every Streams read. Omit for lenient (verify when signed, pass through unsigned self-host responses), true or { publicKey } for strict, false for off. Reaches sl.streams.
verifyDumpsManifestbooleanCheck the dumps manifest signature before trusting any file hash (default on). Reaches sl.streams.dumps.
requestTimeoutMsnumberHow long one request may take, headers and body, before it fails with a retryable ApiError (default 30 000 ms). A hung socket then trips the retry policy instead of stalling a walk or consume loop forever. 0 disables the timeout.
etagCachefalse | EtagCacheWhere GET responses carrying an ETag are kept, so a repeat read sends If-None-Match and a finalized page comes back as a free 304. Defaults to an in-memory store of the last 64 pages. Pass your own to keep it across processes (a file, a KV), or false to turn it off.

Run up to 10 public reads in one round trip (POST /v1/batch).

Each item is authorized on its own; the client's bearer token applies to every item. Results come back in order as { path, status, body }. Only paths under /v1/index/, /v1/subgraphs, /v1/streams/, and /v1/contracts are allowed; anything else is a per-item 400.

sl.batch(
requests: { path: string; params?: Record<string, string | number | boolean> }[],
): Promise<{ results: { path: string | null; status: number; body: unknown }[] }>
import { SecondLayer } from "@secondlayer/sdk";
const sl = new SecondLayer({
apiKey: process.env.SECONDLAYER_API_KEY,
});
const { results } = await sl.batch([
{ path: "/v1/streams/tip" },
{ path: "/v1/index/pox5/events", params: { topic: "stake", limit: 5 } },
]);
for (const result of results) {
console.log(result.path, result.status);
^Each item has its own status, so one failed read does not fail the batch.
}

Parameters

hover a row to find it in the code

Required

requestsrequired{ path: string; params?: Record<string, string | number…

sl.context()

REST GET /api/accounts/mesource

Get a one-call snapshot of your account and instance.

Returns a ContextSnapshot: the same orientation an MCP agent reads from secondlayer://context, available to any SDK or CLI consumer. Reads run concurrently; a failed read lands as { value: null, error } on its field rather than rejecting the whole snapshot.

sl.context(): Promise<ContextSnapshot>
Returns Promise<ContextSnapshot>
account
ContextField<ContextAccount>
streamsTip
ContextField<StreamsTip>
indexTip
ContextField<IndexTip>
subgraphs
ContextField<SubgraphSummary[]>
webhooks
ContextField<{ count: number; byStatus: Record<string, number> }>
activeOperations
ContextField<ActiveSubgraphOperation[]>
instance
ContextField<InstanceDiagnosis>
ActiveSubgraphOperation
subgraph, operationId, kind, status, progress
ContextAccount
email
ContextField
One snapshot field: the value, or null plus the error that produced it.
ContextFieldError
Why one snapshot field could not be read.
ContextSnapshot
A point-in-time orientation snapshot: live tips and what this instance holds.
EtagCache
Storage for etagCache.
EtagEntry
One cached GET response: its validator and the body it validated.
FetchLike
(input: string | URL | Request, init?: RequestInit) => Promise<Response>
IndexTip
block_height, finalized_height, lag_seconds
InstanceDiagnosis
An instance's state, the API verdict, and the issues found.
InstanceIssue
title, detail, nextSteps
InstanceState
"healthy" | "empty-index" | "degraded"
StreamsTip
The chain tip: latest block, Bitcoin anchor, and finality boundary.
SubgraphSummary
A subgraph's name, status, and indexing progress.
Edit on GitHub