NightmailDocs
Docs

Start the device flow for an agent

post/v1/agent/device

For a coding agent without a setup token (RFC 8628): returns a device code to keep and a user code to show. Show the person verification_uri_complete as a link on its own line and ask them to open it, sign in, check the code and approve; nextStep says so in words. Then poll pollAgentDeviceToken every interval seconds until it returns the key. Codes work once, for 15 minutes. With setup_token (one from the person's prompt that expired or was replaced before it was used), their dashboard shows you waiting.

Needs no credential.

Example

import { createClient } from '@nightmail/sdk/client';
import { startAgentDeviceAuthorization } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await startAgentDeviceAuthorization({
  client,
  body: {},
  throwOnError: true,
});

console.log(result.data);
curl --request POST \
  --url 'https://nightmail.dev/v1/agent/device' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{}'

Request body

client_namestring

What the agent is, shown to the person as its claim and naming its key ("OpenCode, set up <date>").

setup_tokenstring

The setup token from the person's prompt, even if it expired or was replaced: their dashboard then shows you waiting for their approval. One that was used already addresses nobody.

Responses

200Success
AgentDeviceAuthorization
device_coderequiredstring

nm_device_…: keep it private; only pollAgentDeviceToken takes it.

user_coderequiredstring

Show this to the person: they confirm it matches.

verification_urirequiredstring
verification_uri_completerequiredstring

The page with the user code filled in: the link to give the person.

expires_inrequiredinteger
intervalrequiredinteger

Seconds to wait between polls.

nextSteprequiredstring

What to do now, in words: the link to show the person on its own line, then the polling.

400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiError
errorrequiredobject
error.coderequiredstring
error.messagerequiredstring
error.requestIdrequiredstring
error.fieldstring
error.retryablerequiredboolean
error.resetAtstring

Next capacity change for a Hosted rolling send limit.

error.detailsobject[]

Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).

error.requiredobject

On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.