Protocol
Versioned transport messages, canonical schemas, negotiation, and validation.
OpenPrinter version 1 is an ordered UTF-8 JSON message protocol. OPPA currently carries it over WebSocket, while the server SDK stays transport-neutral. Every message has an explicit discriminator and protocol version. Messages that participate in a request flow also carry a correlation ID.
Canonical definitions
The TypeBox schemas in @openprinter/protocol are the source of
truth. They produce:
- inferred TypeScript types
- runtime validators and codecs
- a deterministic JSON Schema for non-TypeScript consumers
- fixture tests shared with
oppa-protocol
Never change a Rust wire type alone. Update the canonical schema, regenerate the JSON Schema, update fixtures, and make both test suites pass.
Agent messages
- server discovery, pairing, and pre-hello challenge authentication
- heartbeat response
- printer inventory snapshot or change
- job received
- job submitted
- job failed
- sanitized diagnostics summary
Server messages
- server hello with bounded service brand name
- heartbeat request
- print job
- cancel job
- printer inventory request
- configuration invalidation
- disconnect reason
Negotiation
The first messages establish the supported protocol versions. An unsupported version is rejected with a clear protocol error; it is never silently interpreted as the current version.
The server hello also identifies the connected service with required
OpenPrinterBrandMetadata. The metadata contains a display name only;
icons and external resource URLs are excluded.
Limits
Decoders enforce a maximum encoded message size, bounded section and metadata counts, bounded text and image payloads, valid identifiers, and known discriminators. Unknown fields are rejected where they would weaken the remote command boundary.
Document representations
A print job's document is either a structured receipt or a PDF
reference. A PDF is identified by format: "pdf", which a receipt
never contains, so the receipt shape from earlier releases is
unchanged.
A PDF reference has:
source:{ type: "url", url, sha256, byteLength }. The URL must be absolute HTTPS, or HTTP onlocalhostor127.0.0.1. Credentials, fragments, and whitespace are rejected.sha256is 64 lowercase hex characters, andbyteLengthis 1 to 20,971,520.settings: optional print settings described in Print Documents.
Bytes never appear in a message. Keeping them out of the WebSocket frame bounds memory use and lets the agent verify integrity before rendering.
Document retrieval
The agent sends GET to the job's URL with these headers:
| Header | Value |
|---|---|
X-OpenPrinter-Agent-Id | The agent identity from pairing |
X-OpenPrinter-Job-Id | The job identity |
X-OpenPrinter-Timestamp | Unix time in milliseconds |
X-OpenPrinter-Signature | Unpadded base64url Ed25519 signature |
The signed payload is these LF-separated lines:
OPENPRINTER-DOCUMENT-V1
GET
<path and query exactly as requested>
<agent id>
<job id>
<timestamp in milliseconds>
<lowercase hex SHA-256>Servers verify the signature with the agent's registered public key
and reject timestamps more than five minutes from their own clock. The
@openprinter/server package provides verifyDocumentRequest. The
agent never sends a bearer secret, and the credential never leaves
secure storage.
The agent refuses redirects, rejects a body whose length or digest differs from the job, and stops at the declared byte length.
Document failure codes
| Code | Retryable | Meaning |
|---|---|---|
document.fetch_failed | yes | Transport failure, timeout, or server error |
document.not_found | no | The server no longer has the document |
document.refused | no | The server rejected the authenticated request |
document.authorization_failed | no | The agent credential could not sign the request |
document.integrity_failed | no | Length or digest differed from the job |
document.fetch_unavailable | no | The agent has no document retrieval configured |
document.invalid | no | The bytes are not a readable PDF |
document.encrypted | no | The PDF is password protected |
document.limit_exceeded | no | Size, page, or pixel limits were exceeded |
document.page_range_invalid | no | A selected page does not exist |
document.settings_invalid | no | A setting is out of range |
document.processing_timeout | yes | Rasterization exceeded its time limit |
document.format_unsupported | no | The printer cannot receive PDFs |
document.option_unsupported | no | The printer cannot honour a requested option, such as duplex |
Capability advertisement
Printer descriptors may advertise what the printer can accept in the
optional capabilities object:
documentFormats:receiptand/orpdfpaperSizes: standard sizes the printer offers, when knowncustomPaperSize: whether custom media, such as label stock, is availableprintOptions: explicit booleans forcopies,duplex,orientation,scaling, andpageRanges
These fields are part of protocol version 2. An agent sends them only
in a session that negotiated version 2. A server should send a PDF job
only to a printer whose documentFormats include pdf. An agent that
receives a PDF it cannot route fails the job with a non-retryable code
instead of guessing.
Protocol versions and negotiation
Protocol version "1" is the base protocol, and it is unchanged from
earlier releases. Protocol version "2" adds PDF print jobs and
printer document capabilities. Peers negotiate the version during the
hello exchange, and independent upgrades are supported in both
directions:
| Agent | Server | Result |
|---|---|---|
| Earlier release | Any | Base protocol, identical to earlier releases |
| Current release | Earlier release | Base protocol. The agent's extended hello is refused, and the agent retries once with the base offer. |
| Current release | Current release | Version 2 negotiated. Document capabilities and PDF jobs are exchanged. |
The rules that make this safe:
- Handshake frames use envelope version
"1".agent.helloofferssupportedProtocolVersions. Current agents offer["2", "1"], and earlier agents offer["1"].server.hellolists only the selected version insupportedProtocolVersionsand names it inselectedProtocolVersion. An earlier agent therefore receives exactly the reply it expects. - Every other message uses the lowest version its content needs.
Receipts, reports, heartbeats, and base-protocol inventory use
"1". A PDF job or a printer with document capabilities uses"2". - Receivers enforce both rules. A
"1"envelope that carries version-2 content is rejected. A"2"envelope is rejected unless version 2 was negotiated in that session. A server never sends version-2 content to a session that negotiated version 1;sendJobreturnsprotocol-version-unsupportedinstead. - Earlier servers close a rejected extended hello without
replying. The agent treats a connection that closes after its
hello and before
server.helloas a refusal. It retries once with the base offer, and after a successful base handshake it remembers the server for 24 hours. During that time it does not offer the extended protocol again, so a server upgrade is picked up within a day without re-pairing. A timeout waiting forserver.hellois not treated as a refusal. - Base-only sessions never carry extended fields. The agent removes document capabilities from its inventory before sending it, so an earlier server receives the same inventory it always did.
- Agents never infer support from version strings. The only
evidence is the explicit
selectedProtocolVersioninserver.hello.
Servers can restrict the versions they accept with the
protocolVersions option. Use ["1"] to serve only base-protocol
agents; "1" is always required.
Delivery states
Use received, submitted, and failed for agent
acknowledgements. printed is not a universal protocol state because
a successful operating-system or TCP submission does not prove
physical output.