Start the device flow for an agent
/v1/agent/deviceFor 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_namestringWhat the agent is, shown to the person as its claim and naming its key ("OpenCode, set up <date>").
setup_tokenstringThe 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
AgentDeviceAuthorizationdevice_coderequiredstringnm_device_…: keep it private; only pollAgentDeviceToken takes it.
user_coderequiredstringShow this to the person: they confirm it matches.
verification_urirequiredstringverification_uri_completerequiredstringThe page with the user code filled in: the link to give the person.
expires_inrequiredintegerintervalrequiredintegerSeconds to wait between polls.
nextSteprequiredstringWhat 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.
ApiErrorerrorrequiredobjecterror.coderequiredstringerror.messagerequiredstringerror.requestIdrequiredstringerror.fieldstringerror.retryablerequiredbooleanerror.resetAtstringNext 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.requiredobjectOn a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.