Machine API authentication supports two runtime shapes:
r4 login, use a browser-approved device access tokenFor the agent password-manager flow, authentication still means more than “just an API key.”
An agent runtime needs:
The API key authenticates the runtime to R4. The private key stays local and is used to unwrap vault DEKs so the runtime can decrypt shared secrets locally.
API keys use this format:
{accessKey}.{secret}Example:
rk_abc123def456.ghijklmnopqrstuvwxyz1234567890abcdef| Scope | Use it for | Notes |
|---|---|---|
AGENT | Agent runtime secret retrieval | This is the scope documented on this site for password management |
USER | User-backed machine writes | Requires an active user key pair for zero-trust write flows |
TENANT | Tenant-scoped automation | Can participate in write flows when backed by an active user key pair |
ORG | Org-scoped automation | Can participate in write flows when backed by an active user key pair |
If you are giving an autonomous runtime access to passwords and secrets, use an AGENT API key.
Machine API keys are created with an endpoint policy as well as a scope.
machine.allmachine.agent.all, machine.vault.read, machine.vault.secret.readmachine.project.read if the runtime needs project discoverymachine.monitoring.read when the runtime should watch scoped API traffic, audit events, vault activity feeds, or entity counts for read-only monitoring/anomaly detectionmachine.vault.all, machine.project.all, machine.domain.all, or machine.billing.allThe key must satisfy both its scope and its machine policy. For example, an AGENT key can still be denied vault-write endpoints if it lacks machine.vault.write or asset access to the target vault or item. Monitoring follows the same rule: AGENT keys can use the scoped metric-stats, entity-counts, request-events, audit-events, and vault-activity-events endpoints, but the infrastructure-only system-stats / session-stats routes still require a global-admin-backed machine key.
For agent runtimes:
When you create a new agent from that platform wizard, R4 generates the runtime
key pair locally in the browser, sends only the public key to the backend,
creates the AGENT credentials, registers the public key, applies the selected
security groups, and offers a one-time JSON download containing agentId,
accessKey, accessSecret, and privateKey. If you also save to a vault, the
vault item stores only the API credentials, not the private key.
For human- or service-backed keys:
Use the CLI when you want the same local ~/.r4 profile to work from shell commands and the SDK.
Account profile:
r4 loginAgent profile:
r4 configure agent --config ./openclaw-agent-runtime.jsonr4 configure agent --config <path> imports the downloaded runtime JSON,
verifies the AGENT API credentials, saves the private key under
~/.r4/profiles/<profile>/private-key.pem, and stores the API credentials in
that profile's credential file.
Switch profiles with:
r4 profiles
r4 profiles use <profile>
r4 whoamiKeep the downloaded private key local to the runtime host. Do not upload it to R4 or commit it to source control. The Node SDK derives the matching public key from this private key when it needs to validate or rotate runtime encryption state.
{accessKey}.{secret} plus its local private key file from the one-time platform runtime config.previousEncryptionKeyId and rotationSignature from the current private key.encryptionKeyId plus a complete rewrappedVaultKeys batch for every active vault DEK.curl -H "X-API-Key: $R4_API_KEY" \
"https://r4.dev/api/v1/machine/vault"curl -H "Authorization: ApiKey $R4_API_KEY" \
"https://r4.dev/api/v1/machine/vault"Account profiles created by r4 login use a CLI device access token. The CLI and SDK send:
curl \
-H "Authorization: Bearer $R4_ACCESS_TOKEN" \
-H "x-r4-session-surface: cli" \
-H "x-r4-device-installation-id: $R4_DEVICE_INSTALLATION_ID" \
"https://r4.dev/api/v1/machine/me"Use account access tokens for user-backed CLI/SDK automation. Use AGENT API keys for autonomous runtimes and zero-trust agent secret retrieval.
Account access tokens do not carry a machine permission policy. A
device-approved token receives the USER-scope machine permission set minus
the access-management write families — machine.org_admin.write,
machine.tenant_admin.write, machine.user_manager.write, and
machine.permissions.write — and access is then constrained by what that user
can actually see and do (tenants, security groups, asset permissions).
Automations that need those admin writes, or endpoint-level least privilege in
general, should mint a scoped API key with an explicit permission policy
instead of reusing a device token.
API keys created before endpoint policies existed have no stored grants. They
now resolve to the safe default permission bundle for their scope at request
time — they no longer receive full access. Calls outside that default bundle
return machine_permission_denied. GET /api/v1/machine/me flags these keys
with legacyFullAccess: true and a rotation warning; rotate them to pin an
explicit policy. New keys always store one, and every scope receives
machine.me.read implicitly so a key can always introspect itself.
Keys created without an explicit policy receive the safe default bundle for
their scope: machine.me.read, machine.vault.all, machine.project.all,
and machine.domain.all, plus machine.billing.read for USER/TENANT/ORG
keys. AGENT keys additionally default to machine.billing.all (the wallet
top-up flow), machine.agent.public_key.write, and machine.feedback.all.
Billing writes for human-scoped keys must be selected explicitly.
Use environment variables or your runtime's secret store for AGENT credentials:
export R4_API_KEY="access_key.secret"
export R4_PRIVATE_KEY_PATH="$PWD/agent-private-key.pem"
export R4_PROJECT_ID="optional-project-id"
export R4_TRUST_STORE_PATH="$PWD/.r4-trust-store.json"The SDK can also load a profile created by the CLI:
import { R4Client } from '@r4-sdk/node'
const client = R4Client.fromProfile({ profile: 'personal' })
const identity = await client.getMachineIdentity()For R4.create() and local secret decryption, use an agent profile or pass an AGENT API key plus the matching private key.
This keeps rotation and revocation safe and targeted.
401 UnauthorizedCheck:
{accessKey}.{secret} formatX-API-Key or Authorization: ApiKeyFor account profiles, check that the bearer token is not expired and that the x-r4-session-surface: cli and device installation headers are present.
403 Forbidden / machine_permission_deniedCheck:
Check:
Check:
Check:
r4 project env or R4.create({ projectId })projectId filtering is enabledNo wrapped key found for this agent and vaultCheck: