s2-sdk-typescript is the official TypeScript SDK for S2. S2 is a serverless streaming data storage managed service built on a REST API, providing unlimited, durable streams. This SDK provides high-level abstractions and convenience wrappers on top of the core REST API.
Purpose and positioning The SDK is aimed at developers who need to integrate the S2 streaming service into TypeScript/JavaScript applications, covering scenarios such as account and basin management and stream data reads and writes. The repository includes a runnable examples directory, a patterns package, SDK documentation, and links to the S2 REST API documentation; the repository for versions prior to 0.16.x has separate links.
Main capabilities
- Account and basin operations: supports CRUD operations on basins (namespaces for streams), streams, fine-grained access tokens, and more.
- Data plane (stream) operations: the core verbs are appending data to a stream and reading data from a stream. The atomic unit of an append is AppendInput, which contains a batch of AppendRecords and optional additional parameters; a record consists of a body and optional headers, and after an append completes, each record is assigned a sequence number and timestamp. Reads can be indexed by record sequence number or timestamp, and support following updates in real time.
- AppendSession: stateful, guaranteeing that the order of submitted batches is the order on the stream, and supporting pipelined submission while preserving order (especially under the s2s transport). A single stream supports up to 200 append batches per second, but throughput can reach tens of MiB/s, so fewer but larger batches are generally recommended.
- Producer API: combines appendSession with an automatic batcher (BatchTransform), retaining and accumulating records for a configurable time, and is the recommended path for most high-throughput write scenarios.
- readSession: used to read data exceeding a single response batch (greater than 1 MiB), or to keep a session open to track new data (by omitting the stop condition).
- Ending sessions: stopping a read session early can be done by breaking out of the loop or aborting the signal passed to readSession(); an aborted session throws an S2Error with code ABORTED; stopping an append session aborts the signal passed to appendSession(), and appends that may have already reached the server are rejected with ABORTED, and the session is lostAfter a failure, unsent and subsequently appended records are rejected with SESSION_CLOSED; the same applies to unsent Producer records. The error reason can be obtained via cause or failureCause(). stream.close() ends all sessions opened by that handle and releases the connection: read sessions throw ABORTED, and append sessions complete in-flight appends.
Usage You first need to register in the S2 console and obtain an access key, create a new basin in the UI, and then configure the corresponding environment variables to run the code snippets in the repository or other examples. The SDK also includes a basic browser example that can be used directly on the Web.
Client configuration Retry and append retry policy: when appendRetryPolicy is set to "noSideEffects", only appends that are naturally idempotent via matchSeqNum are retried; when set to "all", any failure can be retried (higher durability, but may produce duplicate data in non-idempotent cases). Session transport: sessions can use fetch (HTTP/1.1) or s2s (S2's HTTP/2-based streaming protocol). The transport can be forced per stream, or rely on environment auto-detection (the default behavior). The HTTP/2 library required for s2s is enabled by default on Node.js and Bun >= 1.3.11; older Bun versions default to HTTP/1.1 due to a node:http2 defect, but s2s can be forced via the mechanisms above. HTTP/2 flow control: the s2s transport pools HTTP/2 connections per endpoint, with each connection multiplexing up to 100 sessions. The flow-control window limits how much in-flight data the server can retain before the client acknowledges it, split into per-session and per-connection totals, both defaulting to 10 MiB, which suits most workloads; it is worth increasing when high-throughput reads traverse high-latency links (where the bandwidth-delay product exceeds the window) or when multiple concurrent read sessions share a connection. Clients using different http2 configurations do not share pooled connections; these settings have no effect on the fetch transport.
Use cases and limitations Suitable for TypeScript applications that need durable stream storage, sequential appends, reads by sequence number or timestamp, and real-time tracking of new data, as well as scenarios requiring high-throughput batch writes. For higher-level, more opinionated building blocks (typed append/read sessions, framing, deduplication helpers), see the patterns package. Feature requests and issues are tracked via GitHub Issues, and you can also contactus via Discord or email at hi@s2.dev. The materials do not provide details such as specific pricing, costs, or performance benchmarks.