OpenPrinterOpenPrinter

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 on localhost or 127.0.0.1. Credentials, fragments, and whitespace are rejected. sha256 is 64 lowercase hex characters, and byteLength is 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:

HeaderValue
X-OpenPrinter-Agent-IdThe agent identity from pairing
X-OpenPrinter-Job-IdThe job identity
X-OpenPrinter-TimestampUnix time in milliseconds
X-OpenPrinter-SignatureUnpadded 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

CodeRetryableMeaning
document.fetch_failedyesTransport failure, timeout, or server error
document.not_foundnoThe server no longer has the document
document.refusednoThe server rejected the authenticated request
document.authorization_failednoThe agent credential could not sign the request
document.integrity_failednoLength or digest differed from the job
document.fetch_unavailablenoThe agent has no document retrieval configured
document.invalidnoThe bytes are not a readable PDF
document.encryptednoThe PDF is password protected
document.limit_exceedednoSize, page, or pixel limits were exceeded
document.page_range_invalidnoA selected page does not exist
document.settings_invalidnoA setting is out of range
document.processing_timeoutyesRasterization exceeded its time limit
document.format_unsupportednoThe printer cannot receive PDFs
document.option_unsupportednoThe 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: receipt and/or pdf
  • paperSizes: standard sizes the printer offers, when known
  • customPaperSize: whether custom media, such as label stock, is available
  • printOptions: explicit booleans for copies, duplex, orientation, scaling, and pageRanges

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:

AgentServerResult
Earlier releaseAnyBase protocol, identical to earlier releases
Current releaseEarlier releaseBase protocol. The agent's extended hello is refused, and the agent retries once with the base offer.
Current releaseCurrent releaseVersion 2 negotiated. Document capabilities and PDF jobs are exchanged.

The rules that make this safe:

  • Handshake frames use envelope version "1". agent.hello offers supportedProtocolVersions. Current agents offer ["2", "1"], and earlier agents offer ["1"]. server.hello lists only the selected version in supportedProtocolVersions and names it in selectedProtocolVersion. 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; sendJob returns protocol-version-unsupported instead.
  • Earlier servers close a rejected extended hello without replying. The agent treats a connection that closes after its hello and before server.hello as 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 for server.hello is 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 selectedProtocolVersion in server.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.

On this page