Client
What the client does itself, beside its surfaces: batched reads and the one-call account snapshot. Constructor options are in the SDK guide.
| new SecondLayer(options) | ||
| batch(requests) | { results: { path: string | null; s… | Run up to 10 public reads in one round trip (POST /v1/batch). |
| context() | ContextSnapshot | Get a one-call snapshot of your account and instance. |
Parameters
hover a row to find it in the codeOptions
baseUrlstring | Base URL of the instance API (trailing slashes are stripped). |
apiKeystring | Bearer token for authenticated requests. Defaults to SECONDLAYER_API_KEY on api.secondlayer.tools, INSTANCE_TOKEN elsewhere. |
accountKeystring | Hosted 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. |
fetchImplFetchLike | Fetch implementation. Tests and edge runtimes can provide their own. |
dumpsBaseUrlstring | Public 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. |
archiveBaseUrlstring | Public base URL for the signed canonical archive tree. Defaults to https://archive.secondlayer.tools. Reaches sl.archive. |
archiveOpsUrlstring | Credits 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. |
verifyDumpsManifestboolean | Check the dumps manifest signature before trusting any file hash (default on). Reaches sl.streams.dumps. |
requestTimeoutMsnumber | How 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 | EtagCache | Where 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.
Parameters
hover a row to find it in the codeRequired
requestsrequired{ path: string; params?: Record<string, string | number… |
sl.context()
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.
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>
ActiveSubgraphOperationsubgraph, operationId, kind, status, progressContextAccountemailContextFieldnull plus the error that produced it.ContextFieldErrorContextSnapshotEtagCacheetagCache.EtagEntryFetchLike(input: string | URL | Request, init?: RequestInit) => Promise<Response>IndexTipblock_height, finalized_height, lag_secondsInstanceDiagnosisInstanceIssuetitle, detail, nextStepsInstanceState"healthy" | "empty-index" | "degraded"StreamsTipSubgraphSummary