Read records from an S2 stream by sequence number, timestamp, or tail offset.
Documentation Index
Fetch the complete documentation index at: https://s2.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
readSession APIs) or SSE responses.
tail_offset=0.
| Query parameter | Unit | Starts at |
|---|---|---|
seq_num | Sequence number | The first record whose sequence number is greater than or equal to seq_num. |
timestamp | Milliseconds since Unix epoch | The first record whose timestamp is greater than or equal to timestamp. |
tail_offset | Record count | The position tail.seq_num - tail_offset, saturated at the start of the stream. |
tail_offset=0 starts at the tail. The tail is the next sequence number that will be assigned, so there is no existing record at that position.
If a requested seq_num or timestamp is beyond the current tail, clamp=true moves the start to the current tail. This is most useful with wait > 0, where the read can then wait for future records. Without clamp, starts beyond the tail return 416 Range Not Satisfiable.
| Query parameter | Unit | Behavior |
|---|---|---|
count | Records | Stop after this many records. For single-batch reads, the effective maximum is 1000 records. |
bytes | Bytes | Limit the total metered bytes returned. For single-batch reads, the effective maximum is 1 MiB. |
until | Timestamp | Stop before records whose timestamp is greater than or equal to until. |
wait is how many seconds the read may wait at the tail for new records after all immediately available records have been returned.
| Request mode | Default wait | Tail behavior |
|---|---|---|
| Single-batch read | 0 | Return immediately unless wait > 0. |
Session with count, bytes, or until | 0 | Stop when a bound is reached or when the session catches up to the current tail, unless wait > 0. |
Session without count, bytes, or until | Infinite | Follow the stream indefinitely, waiting at the tail for new records. |
wait > 0 may long poll for up to 60 seconds. If the wait elapses before records arrive, the response is an empty batch.
For sessions, wait applies throughout the session while still respecting any count, bytes, or until bound.
416 Range Not Satisfiable when it cannot return records under the request’s effective wait and clamp behavior. The 416 response body is a TailResponse containing the current tail.
| Request behavior | 416 when |
|---|---|
Effective wait > 0 | The start is beyond the tail and clamp is omitted or false: seq_num > tail.seq_num or timestamp > tail.timestamp. |
Effective wait = 0 | No record is available immediately: the stream is empty, tail_offset = 0, seq_num >= tail.seq_num, or timestamp > tail.timestamp. |
wait > 0, the read waits for future records, and with wait = 0, it returns 416 because no record exists at the tail yet.
clamp=true only changes starts that are beyond the tail. It moves the start to the current tail, not to the last existing record.Accept: text/event-stream header.
error message will terminate the stream.Bearer authentication header of the form Bearer <token>, where <token> is your access token.
Defines the interpretation of record data (header name, header value, and body) with the JSON content type.
Use raw (default) for efficient transmission and storage of Unicode data — storage will be in UTF-8.
Use base64 for safe transmission with efficient storage of binary data.
raw, base64 Encryption key material for append and read operations. Provide base64-encoded key when stream encryption is enabled.
Stream name.
1 - 512Start from a sequence number.
x >= 0Start from a timestamp.
x >= 0Start from number of records before the next sequence number.
x >= 0Start reading from the tail if the requested position is beyond it.
Otherwise, a 416 Range Not Satisfiable response is returned.
Record count limit. Non-streaming reads are capped by the default limit of 1000 records.
x >= 0Metered bytes limit. Non-streaming reads are capped by the default limit of 1 MiB.
x >= 0Exclusive timestamp to read until.
x >= 0Duration in seconds to wait for new records.
The default duration is 0 if there is a bound on count, bytes, or until, and otherwise infinite.
Non-streaming reads are always bounded on count and bytes, so you can achieve long poll semantics by specifying a non-zero duration up to 60 seconds.
In the context of an SSE or S2S streaming read, the duration will bound how much time can elapse between records throughout the lifetime of the session.
x >= 0Records that are durably sequenced on the stream, retrieved based on the requested criteria.
This can only be empty in response to a unary read (i.e. not SSE), if the request cannot be satisfied without violating an explicit bound (count, bytes, or until).
Sequence number that will be assigned to the next record on the stream, and timestamp of the last record. This will only be present when reading recent records.