For the agent password-manager flow, authentication 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 does not have an active registered runtime key for checkpoint signing. 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:
That download gives you only the API key half of the runtime contract. The runtime host must still generate or be provisioned with its own local RSA private key. Security-group access, direct project permissions, and direct vault sharing should be assigned only after the runtime successfully registers its first public key.
For human- or service-backed keys:
Generate the runtime private key on the host where the agent runs:
openssl genrsa -out ./agent-private-key.pem 2048Keep this file local to the runtime host. Do not upload it to R4 or commit it to source control.
The CLI and Node SDK derive the matching public key from this private key and register it automatically.
{accessKey}.{secret} plus its local private key file.POST /api/v1/machine/vault/public-key.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"The CLI is the shortest path because it handles both the API key and the local private key:
r4 auth login \
--api-key "$R4_API_KEY" \
--private-key-path ./agent-private-key.pem
r4 auth whoamiSupported environment variables:
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"This keeps rotation and revocation safe and targeted.
401 UnauthorizedCheck:
{accessKey}.{secret} formatX-API-Key or Authorization: ApiKey403 Forbidden / api_key_permission_deniedCheck:
Check:
Check:
Check:
projectId filtering is enabledNo wrapped key found for this agent and vaultCheck:
POST /api/v1/machine/vault/public-key