Skip to main content
Version: 2.11

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

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

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

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

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