Skip to content

Agent sign-up (device authorization)

An AI agent can sign a user up for Truelist and get an API key without the user copying and pasting anything. The agent starts a request, the user opens a link, signs in or creates a free account, and approves. The agent then receives an API key it can use right away.

The flow follows the same pattern as the OAuth 2.0 device authorization grant used by TVs and CLIs: the agent never sees the user’s password, and the user decides whether to grant access.

Note

Building on Claude Code? The truelist skill already runs this flow for you. Using Claude Desktop, Cursor, or VS Code? The MCP server connects with a browser login instead and doesn't need an API key.

How it works

  1. The agent calls POST /api/v1/agent_auth/device. Truelist returns a short user_code, a link for the user, and a secret device_code.
  2. The agent shows the user the link (verification_uri_complete) and the code.
  3. The user opens the link, signs in or creates a free account, checks that the code matches, and clicks Approve.
  4. Meanwhile the agent polls POST /api/v1/agent_auth/token with the device_code every interval seconds.
  5. Once the user approves, the next poll returns an api_key. The agent saves it and starts validating.

Both endpoints are on https://api.truelist.io and don’t require authentication.

Start the request

POST /api/v1/agent_auth/device

The body is optional. Pass client_name so the user can see which agent is asking. It defaults to AI agent and can be up to 60 characters.

curl -X POST https://api.truelist.io/api/v1/agent_auth/device 
  -H "Content-Type: application/json" 
  -d '{"client_name": "Claude Code"}'

Response 201 Created:

{
  "device_code": "<opaque string, keep secret>",
  "user_code": "WDJB-MJHT",
  "verification_uri": "https://app.truelist.io/connect",
  "verification_uri_complete": "https://app.truelist.io/connect?code=WDJB-MJHT",
  "expires_in": 900,
  "interval": 5,
  "instructions_for_agent": "Ask the user to open verification_uri_complete, sign in or create a free Truelist account, and approve the request (code WDJB-MJHT). Meanwhile poll POST /api/v1/agent_auth/token with device_code every `interval` seconds."
}
Field Description
device_code Secret the agent uses to poll. Never show it to the user.
user_code Eight-letter code in XXXX-XXXX form, shown to the user so they can confirm it matches. Uses consonants only, so it can’t spell words or be confused with digits. Lookups ignore case and the dash.
verification_uri Page where the user approves the request.
verification_uri_complete Same page with the code pre-filled. Show this link to the user.
expires_in Seconds until the request expires (15 minutes).
interval Minimum seconds to wait between polls.
instructions_for_agent Plain-language next steps written for an LLM agent.

Poll for the API key

POST /api/v1/agent_auth/token

curl -X POST https://api.truelist.io/api/v1/agent_auth/token 
  -H "Content-Type: application/json" 
  -d '{"device_code": "DEVICE_CODE"}'

While the user hasn’t decided yet, the response is 400 with "error": "authorization_pending". Keep polling every interval seconds.

Response 200 OK, once the user approves:

{
  "api_key": "<api key>",
  "token_type": "Bearer",
  "email": "user@example.com",
  "instructions_for_agent": "Save api_key as the TRUELIST_API_KEY environment variable (or the user's secret store), never print it in full, and send it as 'Authorization: Bearer <api_key>'."
}

The key is returned exactly once. Polling again after that returns expired_token.

Use the key like any other Truelist API key:

curl -X POST "https://api.truelist.io/api/v1/verify_inline?email=jane@example.com" 
  -H "Authorization: Bearer $TRUELIST_API_KEY"

Polling errors

Every error response is 400 with an error field and an instructions_for_agent field.

error Meaning What the agent should do
authorization_pending The user hasn’t approved or denied yet. Wait interval seconds and poll again.
slow_down The agent polled faster than interval. Add 5 seconds to the interval, then keep polling.
access_denied The user clicked Deny. Stop. Don’t retry unless the user asks.
expired_token 15 minutes passed, or the key was already collected. Start over with a new device request.
invalid_grant The device_code is unknown. Start over with a new device request.

Full example (bash)

This script starts the flow, prints the link for the user, and polls until it gets a key. It needs curl and jq.

#!/usr/bin/env bash
set -euo pipefail

API="https://api.truelist.io"

start=$(curl -s -X POST "$API/api/v1/agent_auth/device" 
  -H "Content-Type: application/json" 
  -d '{"client_name": "My agent"}')

device_code=$(echo "$start" | jq -r .device_code)
interval=$(echo "$start" | jq -r .interval)

echo "Open $(echo "$start" | jq -r .verification_uri_complete)"
echo "and check that the code is $(echo "$start" | jq -r .user_code)"

while true; do
  sleep "$interval"
  response=$(curl -s -X POST "$API/api/v1/agent_auth/token" 
    -H "Content-Type: application/json" 
    -d "$(jq -n --arg dc "$device_code" '{device_code: $dc}')")

  api_key=$(echo "$response" | jq -r '.api_key // empty')
  if [ -n "$api_key" ]; then
    echo "Connected as $(echo "$response" | jq -r .email)"
    # Store the key somewhere safe (secret manager, .env). Never print it.
    break
  fi

  case "$(echo "$response" | jq -r .error)" in
    authorization_pending) ;;
    slow_down) interval=$((interval + 5)) ;;
    *) echo "Stopped: $(echo "$response" | jq -r .error)"; exit 1 ;;
  esac
done

Security

  • The user stays in control. Nothing happens until the user signs in to Truelist in their own browser and clicks Approve. The approval page shows the code and the agent’s client_name, so the user can check that the request came from their agent.
  • Check the code. Users should only approve if the code on the page matches the one their agent showed them. If they didn’t start a request, they should click Deny.
  • Short-lived requests. A request expires after 15 minutes, and the API key is handed out exactly once.
  • Ordinary, revocable keys. The key is a normal Truelist API key named after the agent, for example “Claude Code (agent)“. It appears in Settings → API keys, where the user can revoke it at any time.
  • Team accounts. On a team account, only admins can approve a request, the same rule as creating API keys.
  • Keep the secrets secret. Agents should never show the device_code to the user or print the api_key in full. Store the key in an environment variable such as TRUELIST_API_KEY or in the user’s secret store.

Errors written for agents

Once the agent has a key, Truelist API errors for quotas, billing, authentication, and rate limits carry extra fields so an agent knows what to tell the user. See API errors for agents.

{
  "error": "You have used all of your free validations. ...",
  "error_code": "quota_exceeded",
  "purchase_url": "https://app.truelist.io/settings/billing",
  "instructions_for_agent": "Tell the user their free validations are used up and share purchase_url. Do not retry this request."
}