Skip to main content
Version: 2.14 (latest)

JetStream API Headers

This document provides a comprehensive reference for all headers used in JetStream operations. These headers are used for message publishing, delivery, and various JetStream features.

Message Publishing Headers

Headers used when publishing messages to JetStream streams.

Message Identification and Deduplication

HeaderValueDescription
Nats-Msg-IdUnique message IDUnique message ID for deduplication. Messages with the same ID within the deduplication window will be rejected as duplicates.
Nats-Expected-Last-Msg-IdMessage IDMessage will only be stored if the last message ID matches this value

Expected State Headers

These headers enforce expected state conditions when publishing. If conditions are not met, the publish will fail.

HeaderValueDescription
Nats-Expected-StreamStream nameVerifies the message is being published to the expected stream
Nats-Expected-Last-SequenceSequence numberMessage will only be stored if the stream's last sequence matches this value
Nats-Expected-Last-Subject-SequenceSequence numberMessage will only be stored if the last sequence for this subject matches this value
Nats-Expected-Last-Subject-Sequence-SubjectSubjectSpecifies the subject for the expected last subject sequence check

Message Rollup

HeaderValueDescription
Nats-Rollupsub or allIndicates this message should replace previous messages. sub replaces all previous messages on the same subject, all replaces all messages in the stream
Nats-Schedule-RollupString

Message Size

HeaderValueDescription
Nats-Msg-SizeSize in bytesIndicates the size of the message payload

Message TTL

HeaderValueDescription
Nats-TTLDuration string (e.g., 60s, 5m)Time-to-live for the message. Message will be automatically removed after this duration

Counter Operations

HeaderValueDescription
Nats-IncrNumberIncrement value for counter operations
Nats-Counter-SourcesJSONSources for counter values in JSON format

Batch Operations

Headers for atomic batch publishing:

HeaderValueDescription
Nats-Batch-IdBatch IDUnique identifier for the batch
Nats-Batch-SequenceSequence numberSequence number within the batch
Nats-Batch-Commit1Marks the final message in a batch, triggering atomic commit

Scheduled Messages

Headers for scheduled message delivery:

HeaderValueDescription
Nats-ScheduleCron expressionSchedule pattern for message delivery
Nats-Schedule-Time-ZoneString
Nats-Schedule-TTLDuration string (e.g., 60s, 5m)Time-to-live for the schedule
Nats-Schedule-TargetSubjectTarget subject for scheduled delivery
Nats-Schedule-SourceSubjectSource subject for scheduled message delivery
Nats-SchedulerScheduler IDIdentifier for the scheduler
Nats-Schedule-NextRFC3339 timestamp or purgeNext scheduled time or purge indicator

Message Delivery Headers

Headers added by JetStream when delivering messages to consumers.

Stream Information

HeaderValueDescription
Nats-Last-StreamSequence numberStream's last sequence at delivery time
Nats-StreamStream nameName of the stream the message came from
Nats-SequenceSequence numberStream sequence number of the message
Nats-Time-StampRFC3339 timestampTimestamp when the message was stored
Nats-SubjectSubjectOriginal subject the message was published to
Nats-Last-SequenceSequence numberLast sequence number in the stream when this message was delivered
Nats-UpTo-SequenceSequence numberUpper bound sequence for batch delivery

Consumer Information

HeaderValueDescription
Nats-Last-ConsumerSequence numberConsumer's last delivered sequence
Nats-Consumer-StalledReply subjectIndicates consumer is stalled with delivery count

Pull Request Headers

Headers used in pull request responses:

HeaderValueDescription
Nats-Num-PendingCountNumber of pending messages for the consumer
Nats-Pending-MessagesCountNumber of pending messages for the pull request
Nats-Pending-BytesSize in bytesNumber of pending bytes for the pull request
Nats-Pin-IdNUIDPriority group pin identifier for the pull request

Source and Mirror Information

HeaderValueDescription
Nats-Stream-SourceStream source infoInformation about the source stream in format: stream-name > seq > subject

Response Type

HeaderValueDescription
Nats-Response-TypeResponse type stringType of response being sent

API Headers

Headers used in JetStream API requests and responses.

HeaderValueDescription
Nats-Required-Api-LevelAPI level numberMinimum API level required for the request

Marker Headers

Headers used to mark special message types in streams.

HeaderValueDescription
Nats-Marker-ReasonMaxAge, Purge, or RemoveReason for the marker: MaxAge, Purge, or Remove

Authentication and Authorization Headers

Headers used for authentication callout and authorization.

HeaderValueDescription
Nats-Request-InfoJSON-encoded client infoClient authorization information for the request
Nats-Server-XkeyX-Key stringServer X-Key for encrypted auth callout requests

Message Tracing Headers

Headers used for message tracing and diagnostics.

HeaderValueDescription
Nats-Trace-DestSubjectDestination subject for message tracing
Nats-Trace-HopHop countNumber of hops in the trace
Nats-Trace-Origin-AccountAccount nameOrigin account for message tracing
Nats-Trace-OnlyBoolean flagIndicates trace-only mode (message is not delivered)

Key-Value Store Headers

Headers used by the NATS Key-Value store built on JetStream.

HeaderValueDescription
KV-OperationPUT, DEL, or PURGEType of KV operation: PUT, DEL, or PURGE

Usage Examples

Publishing with Deduplication

Nats-Msg-Id: unique-message-123

Publishing with Expected State

Nats-Expected-Last-Sequence: 42
Nats-Expected-Stream: my-stream

Batch Publishing

Nats-Batch-Id: batch-456
Nats-Batch-Sequence: 1

For the last message in batch:

Nats-Batch-Id: batch-456
Nats-Batch-Sequence: 10
Nats-Batch-Commit: 1

Scheduled Message

Nats-Schedule: 0 */5 * * * *
Nats-Schedule-TTL: 24h
Nats-Schedule-Target: notifications.email

Notes

  • Headers are case-sensitive
  • Some headers are set automatically by the server and should not be manually set by clients
  • Headers prefixed with Nats-Expected- are used for optimistic concurrency control
  • The Nats-Rollup header is used in conjunction with the stream's MaxMsgsPerSubject setting
  • Batch operations require all messages in a batch to succeed or the entire batch is rejected
  • Counter operations are atomic and support distributed counters across clustered streams