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.
| Surface | Default | Protocol | Audience |
|---|---|---|---|
| HTTP admin | :9460 | HTTP + JSON | Operators, CLI, probes |
| Broker gRPC | :9461 | HTTP/2 protobuf | Applications, firn-cli |
| Mesh gRPC | :9471 | mTLS protobuf | Cluster nodes — never clients |
Authentication & authorization
- Fail-closed. Zero keys ⇒ only
/healthzanswers (gRPC:Unauthenticated). First boot prints a one-timeBOOTSTRAP TOKENon stderr. - Bootstrap.
POST /apikeyswith the token mints exactly one admin key; token is void thereafter. - Enforced. Once any non-revoked key exists, every non-public route requires
Authorization: Bearer <key>(CLI:-api-keyorFIRN_API_KEY). - Roles (least → most):
viewer→ read topics/groups/metrics/UI ·operator→ produce/fetch/queue/group ops/topic create ·admin→ all + key lifecycle.list-apikeysis admin even for viewers. - Rate limits: per-key token bucket,
-rate(default 100 ops/s) → HTTP429/ gRPCRESOURCE_EXHAUSTED. Anonymous per-IP sliding window-anon-rate(default 20/min); refusals are audited. - CIDR allowlists: keys may carry
allowed_ips; mismatch ⇒ HTTP403/ gRPCPERMISSION_DENIED, audited asauthz-refused:ip-not-allowed. - Cluster fencing: internal-topic writes are single-writer; non-holder nodes fail closed with HTTP
503/ gRPCFailedPreconditioncontainingfenced+ holder. Retry on the holder (CLI does this for key ops).
Refusal payloads
| Code | When |
|---|---|
401 / UNAUTHENTICATED | Missing/unknown/revoked key (incl. zero keys — bootstrap mode) |
403 / PERMISSION_DENIED | Valid key, wrong role or disallowed source IP |
429 / RESOURCE_EXHAUSTED | Per-key or anonymous rate limit |
503 / Unavailable | Subsystem 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)
| Method | Path | Purpose |
|---|---|---|
| POST | /federation/peers | Register/overwrite peer — {name, addr, direction:in|out|both, mode:passive|active-active, key, topics?[], queues?[], ca_crt_pem?, server_name?} |
| GET | /federation/peers | List peers (key material never returned; keySet reported) |
| DELETE | /federation/peers/{name} | Remove peer; cursors persist; full re-import = re-register |
| POST | /federation/keys | Mint a federation-scoped key for this cluster (shown once) |
| GET | /federation/cursors | Import 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
| Code | When |
|---|---|
OK | success |
INVALID_ARGUMENT | bad mode/protocol/args, empty batch |
NOT_FOUND | topic/queue/group/delivery/member |
FAILED_PRECONDITION | below retention horizon · non-lease-holder (cluster) · stale generation · stream/queue mode mixup · fenced internal topic (retry on holder) |
UNAUTHENTICATED | missing/unknown/revoked key |
PERMISSION_DENIED | wrong role, or source IP not in key allowlist |
RESOURCE_EXHAUSTED | per-key rate limit |
UNAVAILABLE | broker down / connection refused |
HTTP status codes
| Code | Meaning |
|---|---|
| 200 | OK (GET, pull, ack, revoke) |
| 201 | Created (topic, apikey session mint) |
| 202 | Accepted — cluster topic create, propagating via quorum |
| 400 | Bad JSON/args · not a queue |
| 401 | Missing/unknown/revoked key |
| 403 | Valid key, wrong role / disallowed IP |
| 404 | Not found |
| 405 | Method not allowed for path |
| 409 | Topic exists · resource passively federated (sink is read-only until cutover) |
| 429 | Rate limited |
| 500 | Internal |
| 503 | Subsystem unconfigured · internal topic fenced (retry on holder) · audit budget exhausted |
firn-cli ↔ API map
| CLI | Path |
|---|---|
create-topic / create-queue | POST /topics |
list | GET /topics |
produce / fetch | gRPC Produce / Fetch (batch file → ProduceBatch) |
groups | GET /groups |
dlq list / dlq redrive | gRPC Fetch on <q>.dlq / Fetch + Produce into source queue |
create-apikey / revoke-apikey / list-apikeys | POST / DELETE / GET /apikeys |
federation add-peer|list-peers|remove-peer|keys|status | POST|GET|DELETE /federation/peers · POST /federation/keys · GET /federation/cursors |
mesh-ca init | local 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.