API reference

Two surfaces, one rule: no keys ⇒ /healthz only. HTTP for admin/ops, gRPC (firn.v1) for data-plane traffic. Everything reflects internal/api/firn.proto at v0.6.0.

SurfaceDefaultProtocolAudience
HTTP admin:9460HTTP + JSONOperators, CLI, probes
Broker gRPC:9461HTTP/2 protobufApplications, firn-cli
Mesh gRPC:9471mTLS protobufCluster nodes — never clients

Authentication & authorization

Refusal payloads

CodeWhen
401 / UNAUTHENTICATEDMissing/unknown/revoked key (incl. zero keys — bootstrap mode)
403 / PERMISSION_DENIEDValid key, wrong role or disallowed source IP
429 / RESOURCE_EXHAUSTEDPer-key or anonymous rate limit
503 / UnavailableSubsystem not configured; internal topic fenced (other node holds it)

HTTP admin surface (:9460)

GET /healthz — public

curl localhost:9460/healthz
{"status":"ok","version":"0.5.2","flushWindow":"2ms"}   # flushWindow: effective group-commit window ("2ms" default; "off" with -flush-window=0)

GET /metrics

Prometheus text format. Requires a viewer key by default; -metrics-auth=false restores unauthenticated scraping (private networks only).

Topics

POST /topics      {"name":"orders","partitions":3,"mode":"stream"}   # mode: stream|queue
GET  /topics      → {"topics":[{"name":"orders","partitions":3,"mode":"stream"}]}

Single-node: 201 Created. Cluster: 202 Accepted with {"status":"propagating"}; the topic lands via the quorum and followers converge within a tick. Errors: 400 bad args · 409 exists · 401/403 auth.

Consumer groups

GET /groups                  # generation, leader, protocol, members, assignments
GET /groups/{name}/offsets   # committed offsets per partition

Queue

POST /queues/{q}/pull        {"max_messages":10,"visibility_timeout_ms":30000}
POST /queues/{q}/ack         {"delivery_id":"d-3f2a9c…"}

Pull claims with a visibility lease (default 30 s; hard cap 500/batch). Unacked redeliver at lease expiry (at-least-once); after 3 delivery attempts the message diverts to <queue>.dlq (auto-created). Errors: 404 unknown queue/delivery · 400 not a queue · 401/403 auth · cluster: 409 if passively federated.

API keys admin

POST   /apikeys                 {"name":"ci-deploy","role":"operator"}   # plaintext key shown ONCE
GET    /apikeys                 # names, roles, revoked flags — never key material
DELETE /apikeys/{name}          # revoke; sessions tied to the key die immediately

Browser sessions (/ui/*)

POST /ui/session exchanges a bearer key (viewer suffices) for an HttpOnly SameSite=Strict cookie (12h; Secure under TLS). /ui/* accepts the cookie or bearer; everything else (/topics, …) stays bearer-only. DELETE /ui/session revokes (idempotent 200). Sessions are in-memory; every request re-verifies the backing key — revoking the key kills sessions instantly. Grant/revoke are audited.

Federation (preview)

MethodPathPurpose
POST/federation/peersRegister/overwrite peer — {name, addr, direction:in|out|both, mode:passive|active-active, key, topics?[], queues?[], ca_crt_pem?, server_name?}
GET/federation/peersList peers (key material never returned; keySet reported)
DELETE/federation/peers/{name}Remove peer; cursors persist; full re-import = re-register
POST/federation/keysMint a federation-scoped key for this cluster (shown once)
GET/federation/cursorsImport progress per (peer, topic, partition)

FederationService (gRPC) lives only on the mesh listener: FederationFetch serves raw, CRC-checked frame windows; normal keys get Unimplemented, federation keys get nothing else.

gRPC FirnService (:9461)

Package firn.v1; every RPC is unary. Proto source: internal/api/firn.proto.

Produce

message ProduceRequest  { string topic = 1; bytes key = 2; bytes value = 3; }
message ProduceResponse { int32 partition = 1; int64 offset = 2; }

Key → FNV-64a(key) % partitions; unset key → round-robin. In cluster mode the CLI routes to the lease holder from GetMetadata (2s cache, refresh-on-retry).

ProduceBatch

message ProduceBatchRecord    { bytes key = 1; bytes value = 2; }
message ProduceBatchRequest   { string topic = 1; repeated ProduceBatchRecord records = 2; }  // ≤ 500
message ProduceBatchResponse  { repeated ProduceBatchRecordResult records = 1; }

One RPC instead of N; order matches request; not atomic — on mid-batch failure earlier records are durable, later ones are not; retrying may duplicate earlier records at new offsets (consumers must tolerate duplicates). CLI: firn-cli produce --batch-file events.jsonl (JSONL; - = stdin; auto-chunked).

Fetch

message FetchRequest  { string topic = 1; int32 partition = 2; int64 offset = 3; int32 max_records = 4; }
message FetchResponse { repeated Record records = 1; int64 federation_hwm = 2; }  // federation_hwm advisory

max_records ≥ 1 (cap 1000). Fetch at/above HWM → zero records. Below the retention horizon → FailedPrecondition.

Consumer groups

JoinGroup / SyncGroup / Heartbeat / LeaveGroup
CommitOffset   { group_id, topic, partition, offset, generation_id, allow_reset = false }
FetchOffset    → { offset, found, generation_id, leader }
FetchGroupOffsets { group_id } → all committed offsets

Protocols: range (default) | roundrobin. session_timeout_ms: 0 = server default (10s). Offsets monotonic (invariant 4) unless allow_reset; stale generations rejected. Persisted in __consumer_offsets, restart-safe.

Queue

Pull(queue, max_messages, visibility_timeout_ms) → [QueueDelivery]
Ack(queue, delivery_id) → OK
AckBatch(queue, delivery_ids[1..500]) → { acked, unknown }   // unknown ids tolerated, counted
GetMetadata(topics[] — empty = all) → brokers + per-partition { leader, leader_addr }

AckBatch is the high-volume path — one __consumer_offsets commit per contiguous advance instead of per Ack.

gRPC status codes

CodeWhen
OKsuccess
INVALID_ARGUMENTbad mode/protocol/args, empty batch
NOT_FOUNDtopic/queue/group/delivery/member
FAILED_PRECONDITIONbelow retention horizon · non-lease-holder (cluster) · stale generation · stream/queue mode mixup · fenced internal topic (retry on holder)
UNAUTHENTICATEDmissing/unknown/revoked key
PERMISSION_DENIEDwrong role, or source IP not in key allowlist
RESOURCE_EXHAUSTEDper-key rate limit
UNAVAILABLEbroker down / connection refused

HTTP status codes

CodeMeaning
200OK (GET, pull, ack, revoke)
201Created (topic, apikey session mint)
202Accepted — cluster topic create, propagating via quorum
400Bad JSON/args · not a queue
401Missing/unknown/revoked key
403Valid key, wrong role / disallowed IP
404Not found
405Method not allowed for path
409Topic exists · resource passively federated (sink is read-only until cutover)
429Rate limited
500Internal
503Subsystem unconfigured · internal topic fenced (retry on holder) · audit budget exhausted

firn-cli ↔ API map

CLIPath
create-topic / create-queuePOST /topics
listGET /topics
produce / fetchgRPC Produce / Fetch (batch file → ProduceBatch)
groupsGET /groups
dlq list / dlq redrivegRPC Fetch on <q>.dlq / Fetch + Produce into source queue
create-apikey / revoke-apikey / list-apikeysPOST / DELETE / GET /apikeys
federation add-peer|list-peers|remove-peer|keys|statusPOST|GET|DELETE /federation/peers · POST /federation/keys · GET /federation/cursors
mesh-ca initlocal CA generation (no API)

Internal services — never call these

ReplicaService (block push/pull, content-addressed by SHA-256 of frame bytes) and QuorumService (one Raft RPC per message: RequestVote/AppendEntries/PreVote + block-commit/lease entries) exist only on the mesh listener behind mTLS. Not reachable from client ports, excluded from GetMetadata, shape may change without notice. Treat as implementation detail.

Audit trail

__audit (replicated like any internal topic) records every admin mutation and authz refusal in every auth mode — including dev. Frame: u32 bodyLen | u32 crc32(body) | body where body = offset, ts, key=audit, value=JSON {"ts","who","action","target","result"}. Budget: -audit-max-bytes (default 64 MiB/process) fails closed past budget; rotation is operator-driven. Cluster caveat: mutations handled on the lease holder are audited; topic-create proposals and refusals served on non-holders log to stderr only.