Agent Keys

Agent Service Keys

Let AI agents call x402-protected APIs automatically — billed to your Metered account.

Agent Service Keys let you link any ERC-721 agent NFT to your RelAI account and issue a scoped service key. The agent uses that key on every request — RelAI identifies the agent, pays the x402 fee from your Metered account, and returns the API response. The agent never touches crypto.

The EVM network is only relevant once — when you link the agent to verify NFT ownership. After that, the sk-agent-... key is just a plain API key with no blockchain dependency.

Scoped key

Each sk-agent-... key is tied to a specific agent ID and contract

On-chain verified

Ownership checked against the NFT contract — no gas required

OAuth consent flow

Agents can request keys programmatically without a browser

How It Works

Step 1 — Prove You Own the Agent

RelAI generates a challenge message. You sign it with the wallet that owns the agent NFT. The backend verifies the signature and confirms on-chain ownership. No gas required.

// Flow
RelAI backend → challenge nonce
Your wallet → signs message
RelAI verifies: signature + NFT ownership on-chain

Step 2 — Get the Service Key

Once ownership is confirmed, RelAI issues an sk-agent-... key tied to your account, the agent's contract address, and token ID.

Step 3 — Agent Calls APIs with Two Headers

The agent passes two headers on every request. RelAI identifies the agent, finds your Metered account, and pays the x402 fee automatically.

X-Service-Key: sk-agent-<your-key>
X-Agent-ID: 1

Calling APIs as an Agent

Agents call APIs through the Metered endpoint — RelAI handles x402 payment automatically from your custodial wallet balance.

Metered Relay Shortcut

Call any RelAI-hosted API directly. RelAI detects the x402 requirement, pays it from your Metered wallet, and returns the API response.

curl https://relai.fi/metered/{apiId}/api/endpoint \
  -H "X-Service-Key: sk-agent-..." \
  -H "X-Agent-ID: 1"

Metered Proxy — Any External API

Proxy any external x402-protected URL.

curl "https://relai.fi/metered/x?url=https://api.example.com/data" \
  -H "X-Service-Key: sk-agent-..." \
  -H "X-Agent-ID: 1"

How Does the Agent Know to Use RelAI?

An agent never discovers RelAI on its own — the person deploying the agent tells it to use RelAI for payments, the same way they configure any other API credential (OpenAI key, database URL, etc.).

The agent is started with one of the following:

Environment variables

RELAI_CONSENT_URL=https://relai.fi/agent-keys/consent/initiate
RELAI_API_ID=1772665023009

The agent sees these at startup, initiates the consent flow, and retrieves a key automatically.

Config file

{
  "paymentProvider": "relai",
  "relai": {
    "consentUrl": "https://relai.fi/agent-keys/consent/initiate",
    "apiId": "1772665023009"
  }
}

Already have a key? Skip the flow entirely

RELAI_SERVICE_KEY=sk-agent-...
RELAI_AGENT_ID=1
RELAI_API_ID=1772665023009

If a key was issued before (manually from the dashboard or from a previous consent), the agent can use it directly — no consent flow needed.

Tip: The consent flow is only needed once per agent. After the key is issued, the agent stores it and reuses it for all future requests — no re-authentication required.

API Reference

POST/agent-keys/consent/initiatePublic

Start the consent flow. Returns a consentToken and authorizeUrl.

FieldTypeRequiredDescription
agentPubKeystringrequiredAgent's public key (EVM address or any unique identifier)
agentIdstringoptionalToken ID of the agent NFT
contractAddressstringoptionalERC-721 contract address
networkstringoptionalEVM network name or custom RPC URL
agentNamestringoptionalHuman-readable agent name shown in the consent UI
labelstringoptionalLabel for the issued key
GET/agent-keys/consent/status/:tokenPublic

Poll consent status. Returns retrieveNonce when approved.

POST/agent-keys/consent/retrievePublic

Retrieve the service key. Requires agent signature of retrieveNonce.

FieldTypeRequiredDescription
consentTokenstringrequiredToken from initiate response
signaturestringrequiredSignature of retrieveNonce using the agent's private key
GET/agent-keysBearer JWT

List all agent keys linked to your account.

DELETE/agent-keys/:keyIdBearer JWT

Revoke an agent key permanently. Immediate effect.

Security Model

  • Ownership verified on-chainYou can't link an agent you don't own — the NFT contract is queried directly.
  • Scoped keyThe sk-agent-... key only works with the specific X-Agent-ID it was issued for.
  • Keypair challengeIn the OAuth flow, the key is delivered only to the agent that holds the matching private key (signs retrieveNonce).
  • Revocable at any timeOne click in the dashboard removes the key permanently — with a confirmation prompt.
  • No credential exposureThe agent never sees your private key or your RelAI JWT token.
  • Payments enforcedAgents must go through the Metered endpoint — direct relay access still requires x402 payment.

Dashboard

Manage agent keys from Dashboard → Agent Keys.

Link Agent

Enter contract address, token ID, and network. Connect MetaMask and sign the challenge (no gas). Key is issued immediately.

Revoke Key

Click the trash icon next to a key. A confirmation dialog appears before permanent deletion. Takes effect immediately.