Skip to content

HTTP API ​

Reference for the Pico protocol on the stream listener. The Kafka listener is covered in Kafka protocol, and the admin listener in Admin API.

OpenAPI spec: openapi.yaml

Conventions ​

  • Names. The request path is the topic name, so /logs/api/prod addresses that topic. Slashes and dots are the same separator, and the /_ namespace is reserved, see Topics and streams.
  • Encoding. Paths and query values are percent-decoded once. A value that does not decode to UTF-8 is a 400, never rewritten into another name.
  • Partitions. A topic has one partition unless it was created or grown with more. Every request to a topic with several partitions names one with ?partition=N, and leaving it out is a 400.
  • Sequences. Record offsets within a partition, starting at 0 and stable forever.
  • Headers. Custom headers use the Pico- prefix.
  • Redirects. A request for a partition owned by another node returns 307 with the owner's address in Location. Standard HTTP clients drop Authorization on cross-origin redirects, so clients follow 307s themselves and re-attach the credential. A hop must stay on http or https and never downgrade from https to http, since the credential rides along, and the clients refuse such a hop as unsafe_redirect. picomq-client, the Go and TypeScript clients, and the CLI do all of this.
  • Auth. With auth required, every request sends Authorization: Bearer <token>. See Authorization for scopes.

Errors ​

Errors on stream and group routes are JSON with a code:

json
{ "error": "conflict", "message": "producer epoch 3 is stale", "next_seq": 42 }

message and next_seq appear when they help. next_seq is also sent as Pico-Next-Seq.

StatuserrorMeaning
400bad_requestMalformed request
401unauthenticatedNo valid credential, with a WWW-Authenticate: Bearer challenge
403permission_deniedInsufficient scope
403fencedStale producer epoch, with the current one in Pico-Producer-Epoch
404not_foundNo such topic, partition, or group
405method_not_allowedA method this protocol does not serve
409conflictCreate with different settings
409sequence_gapProducer sequence gap, with Pico-Expected-Seq and Pico-Received-Seq
409closedThe topic is sealed, with Pico-Closed: true
412match_failedPico-Match-Seq did not match the tail
413Body larger than --max-request-size
500durability, internalThe WAL write failed, or an unexpected error
503unavailableThe partition is moving between nodes, the node is stopping, or metadata is unreachable. Retry
504timeoutThe operation timed out. Retry

Retrying 503 and 504 is safe. How the same failures look over Durable Streams and Kafka is in Protocols.

The topic config route, /_streams, is a control surface and answers errors as {"error": "<message>"}, like the admin API.

Lists ​

Every list on this listener and on the admin API pages the same way. Items come in their natural order, by name, id, or offset, never sorted another way, and the response is:

json
{ "items": [ ... ], "next": "opaque" }
Query parameterMeaning
limitItems per page, 100 by default and 1000 at most
cursorThe next of the previous page, to continue after it
FiltersSuch as prefix, sent again with every page
  • Last page. next is null.
  • Short pages. A page can hold fewer items than limit while next is set, when entries the token may not see were skipped or the page reached its size cap. Keep following next until it is null.
  • Cursors. A cursor only continues the list it came from, so sending it with different filters is a 400.

Topic settings ​

A topic's settings are given as headers on create. Some can change later through the topic config route, and the rest are fixed for the topic's life.

SettingCreate headerConfig fieldAfter create
Content typeContent-Type, default application/octet-streamFixed
PartitionsPico-Partitions, default 1partitionsGrows, never shrinks, by at most 10000 at a time
ExpiryPico-TTL, seconds without appends or reads, or Pico-Expires-At, a fixed time. Not bothFixed
RetentionPico-Retention-Ms, Pico-Retention-Bytes, unlimited by defaultretentionMs, retentionBytesSet, or removed with null
SealedPico-Closed: trueSealed by an append with Pico-Closed, never reopened
Kafka nameFollows from the topic namekafkaTopicFixed

Limits must be positive, and a partition count of 0 is a 400.

Create ​

PUT /{topic}

Creates a topic with the settings in its headers, with no body. 201 when created, 200 when it already exists with the same settings, 409 when the settings differ. The response carries the same headers as Inspect.

Append ​

POST /{topic}

Appends records. The body is a single record in the topic's content type, a JSON batch (application/vnd.picomq.batch+json) of records, or a binary batch (application/vnd.picomq.batch). Returns 200.

Request headerMeaning
Pico-KeyRecord key for a single-record body. Batch bodies carry keys inline
Pico-Producer-Id, Pico-Producer-Epoch, Pico-Producer-SeqIdempotent producer identity. A repeated seq is acknowledged without writing
Pico-Match-SeqConditional append: succeeds only if the tail is at this sequence
Pico-Closedtrue seals the topic after this append. With no body, it only seals
Pico-Trim-SeqTurns the request into a trim, dropping records below this sequence. No body
Response headerMeaning
Pico-Start-SeqSequence of the first record in this append, or the new start after a trim
Pico-Next-SeqThe partition's next sequence after the append
Pico-TimestampTimestamp assigned to the records
Pico-Producer-Epoch, Pico-Producer-SeqThe producer state the append was accepted at

Read ​

GET /{topic}?seq=0

Reads records from a sequence. Without live it returns what exists and stops. seq=now starts at the tail, and an SSE reconnect can supply Last-Event-ID instead of seq.

Query parameterMeaning
seqStart position: a number, or now. Defaults to 0
count, bytesCaps on records and bytes returned
formatjson (default), binary batch, or raw concatenated bodies
livelong-poll waits for the next record, sse holds the response open as an event stream

Records come back in the record shape, with seq and timestamp added.

Response headerMeaning
Pico-Next-SeqWhere to resume. Pass it as the next seq
Pico-Up-To-Datetrue when the response reaches the tail
Pico-Closedtrue when the topic is sealed and fully read
Pico-CursorOpaque resume token for paginated catch-up reads

Catch-up responses include an ETag and honor If-None-Match with 304, so polling readers that are caught up transfer nothing. A long poll that times out with no data returns 204. SSE delivers each record as an event with its sequence as the event id, and ends with a control event when the topic is sealed. A node that is shutting down ends live reads with 503, and the client reconnects.

Records ​

A JSON batch is {"records": [...]}, and each record has a key, ordered headers, and a body:

json
{
  "key": "customer-1042",
  "headers": [
    { "name": "trace-id", "value": "4f9c2a" },
    { "name": "trace-id", "value": "7d1e08" },
    { "name": "deleted-by", "value": null }
  ],
  "body": "{\"order\":\"o-981\",\"amount\":42.5}"
}
  • Bytes. UTF-8 text goes in key, body, and a header's value. Other bytes use key_b64, body_b64, or value_b64 with base64 instead.
  • Headers. A list, kept in order, so a name can repeat.
  • Null. A body of null is a record with no value, the Kafka tombstone, and a header value of null has no value either. An absent key means no key. A binary batch carries the same fields, with a length of -1 for null.

Inspect ​

HEAD /{topic}

Returns the topic's metadata in headers with no body, or 404.

Response headerMeaning
Content-TypeThe topic's content type
Pico-PartitionsNumber of partitions
Pico-Start-Seq, Pico-Next-SeqThe partition's readable range. On a topic with several partitions, only with ?partition=
Pico-TTL, Pico-Expires-AtExpiry settings, when set
Pico-Retention-Ms, Pico-Retention-BytesRetention limits, when set
Pico-Closedtrue when sealed
Pico-Kafka-TopicThe topic's Kafka name, when it has one

Delete ​

DELETE /{topic}

Removes the topic, all of its partitions, and their records. 204 on success, 404 when it does not exist. The name is reusable at once.

List ​

GET /?prefix=/logs/&limit=100

Lists topics in pages, filtered by name prefix. Each item has name, content_type, partitions, and closed, plus ttl and expires_at when the topic expires. With auth, only topics the token's stream matchers cover are listed.

Topic config ​

GET /_streams/{topic}
PATCH /_streams/{topic}

Reads and changes a topic's settings as JSON, with the config fields from Topic settings. Both routes serve either HTTP protocol, and cover topics created over Kafka too. In a cluster they follow the ownership of partition 0.

json
{ "kafkaTopic": "orders", "partitions": 3, "retentionMs": 604800000, "retentionBytes": null }
  • GET returns every field, with null for an unset one. 404 when the topic does not exist.
  • PATCH takes only the fields to change and returns the result. An absent field is left alone, and null removes a setting. A partitions that does not grow the topic, or a kafkaTopic, is a 400.
  • Auth. GET needs head on the topic and PATCH needs create. Errors take the control surface's shape.

Consumer groups ​

How groups work is in Consumer groups. Group routes are served on a Pico listener, not on Durable Streams, and redirect to the group's coordinator like topic requests.

RouteDoes
GET /_groups?prefix=Lists group ids in pages, only the groups the token may describe
GET /_groups/{group}Describes a group: group, state, generation, and members
DELETE /_groups/{group}Deletes a group without members and its offsets. 204
POST /_groups/{group}/membersJoins. Returns once the rebalance completes
GET /_groups/{group}/members/{member}?generation=The member's current assignment
POST /_groups/{group}/members/{member}/heartbeatKeeps the member alive. 204
DELETE /_groups/{group}/members/{member}Leaves. 204
PUT /_groups/{group}/offsetsCommits offsets. 204
GET /_groups/{group}/offsets?stream=Fetches committed offsets, for the named topics or all of them

A join sends the topics to subscribe to, at least one, and optionally the member's previous id, a static instanceId, a clientId, and timeouts:

json
{ "subscription": ["/orders", "/payments"], "sessionTimeoutMs": 30000 }

and gets back the member id, generation, and the topics assigned to it:

json
{ "memberId": "m-1", "generation": 3, "assignment": ["/orders"], "members": ["m-1", "m-2"] }

Heartbeats send {"generation": 3}. A commit sends offsets for at least one topic, with the member id and generation when committing as a member:

json
{ "offsets": { "/orders": { "position": 42, "metadata": "checkpoint" } }, "memberId": "m-1", "generation": 3 }

Group errors use the error format above:

StatuserrorMeaning
404unknown_member, not_foundThe member or group does not exist
409rebalance_in_progressRejoin to get the new assignment
409illegal_generationThe member is behind the group's generation. Rejoin
409inconsistent_protocolThe group is in use by Kafka members
409conflictDelete of a group with members, or a join replaced by a newer one
403fencedAnother member holds this static instanceId
429capacity_exceededThe coordinator's group or member limits were hit
503coordinator_unavailableThe coordinator is moving. Retry

Durable Streams ​

A listener started with --protocol ds speaks the Durable Streams open protocol on its exact wire vocabulary, with Stream-* and Producer-* headers, raw record bodies, plain text errors, and one record per append. The topic settings the protocol has no header for are extensions under the same prefix: Stream-Partitions, Stream-Retention-Ms, and Stream-Retention-Bytes. Topics created through either HTTP protocol or Kafka are readable through all three.