Authentication

Apps, scripts, and services authenticate with an organization API key. New to the API? Start with Get Started.

API key

Create a key in the Print Hive web app under Settings → API Keys. The key is shown once. Send it in the x-api-key header:

x-api-key: YOUR_API_KEY

A key belongs to one organization, so requests act on that organization. Never send a key in a query string or ship it to a browser.

Scopes

  • read: read printers, jobs, queue, models, and files.
  • control: everything in read, plus create, release, start, and cancel queued print jobs.
  • dangerous: everything in control, plus operations on a running print, such as stop. Only an organization owner or admin can grant it.

The endpoint reference lists the scope each operation needs. A key without it gets 403 with code API_KEY_SCOPE_REQUIRED and a message that names the scope.

Live event scopes

The live stream needs a live-events scope. read, control, and dangerous do not include one, so add it to the key. Live events is a section of the new API key page, which opens from Create API Key. In the web app you cannot add it to an existing key, because Change access covers only MCP tool access and webhooks. Create a new key instead, and set each event row you need to Read.

  • events:read:printer (Printer events) lets printers.watch() stream printer status, progress, temperatures, and filament. It also covers printer readiness and bed-clear watch events.
  • events:read:job (Print job events) lets events.subscribe({ kinds: ["job.*"] }) stream job events.
  • events:read:bov (Bed occupancy check events) lets events.subscribe({ kinds: ["bov.*"] }) stream bed occupancy verification runs.
  • events:read (All live events) grants every event kind, including kinds added later. Pulse also accepts events:read:* for the same grant.

The stream connects to pulse.printhiv3d.com over Socket.IO. Pulse refuses Host keys, keys bound to a Host, keys with a production:* scope, and keys with the legacy * scope, even when they hold a live-events scope. When Pulse refuses a key, the SDK ends the loop with PrintHiveLiveError, and its code is unauthorized or forbidden. See Watch printers live for the calls.

An agent that needs a key can send a request link. The link opens the new API key page with the scopes, name, expiry, and reason filled in. The person checks the preselected scopes and the expiry, above all control and dangerous, and then presses Create key. Nothing is created before that. Anyone can write a link like this, so the person creates the key only if they asked an agent for it. Print Hive shows the key once. The person pastes it into the agent's secret prompt, never into chat.

https://app.printhiv3d.com/settings/api-keys/new?scopes=read,control&name=Print%20operator&expires=1d&reason=Pause%20and%20resume%20prints%20while%20you%20watch
ParameterWhat it doesLimits
scopesThe scopes to preselect, separated by commas.The page drops the legacy * and any scope it cannot create, and tells the person. production:upload and production:read select the partner production key type and drop every other scope. Only an organization owner or admin can create a key with dangerous or a production:* scope.
nameThe key's name.Trimmed, at most 100 characters. A name is unique in the organization. If a key already has the name, the API answers 409, Create key creates nothing, and the page asks the person for another name. The form keeps the selected scopes and the expiry.
expiresHow long the key lasts: a positive whole number of one to four digits and h, d, or w, such as 1h, 1d, 7d, or 30d.The page picks its longest option that is not longer than the request: 1 hour, or 1, 7, 30, 60, or 90 days. A link cannot ask for no expiration. Without a valid value the page uses 30 days.
reasonWhy the agent needs the key.At most 280 characters. The person sees it as plain text that Print Hive does not check. Markdown, HTML, and links do not work.

The page shows name and reason on one line. It joins each run of blanks and line breaks into one space. It replaces each control character and selected invisible formatting characters, such as a zero-width joiner, with a space. Other invisible characters, such as a soft hyphen, stay. The limits count that text, and the page ignores a value that is empty after that.

The page stores one access level for each area, so the key's scopes can differ from the list in the link. The page does not tell the agent.

  • dangerous stores read, control, and dangerous.
  • control includes read, so a link that asks for both stores control.
  • webhooks:write includes webhooks:read, so a link that asks for both stores webhooks:write.
  • events:read includes every kind of event, so a link that also asks for events:read:job stores events:read.

With @printhive/api 0.18.0 or later, build the link with buildApiKeyRequestLink. It throws for a scope the page cannot create, and for a name or a reason over its limit. It is stricter than the page: it takes strings only, each scope by its exact name, and expires in lower case with no blanks.

import { buildApiKeyRequestLink } from "@printhive/api";

const link = buildApiKeyRequestLink({
  scopes: ["read", "control"],
  name: "Print operator",
  expires: "1d",
  reason: "Pause and resume prints while you watch",
});

Ask for the fewest scopes and the shortest expiry the task needs.

User session tokens

The Print Hive web app calls the API with the signed-in user's session token in Authorization: Bearer. Some endpoints accept only a session token, not an API key; the reference marks them. OAuth tokens issued to MCP clients are accepted only by the MCP server. REST endpoints answer them with 403.

Errors

  • 401 Unauthorized: the key is missing, invalid, disabled, or expired. An endpoint that accepts only a signed-in session also answers 401 to an API key. GET /v1/organizations is one, and its message says that API keys are not accepted.
  • 403 API_KEY_SCOPE_REQUIRED: the key lacks the scope the endpoint needs.