AI agents can now call paid APIs autonomously through RelAI. No wallets in the agent's code, no hardcoded credentials, no crypto complexity. Just a two-header HTTP call and the payments happen automatically.
Here's the full story, from the moment you tell your agent to connect, to its first successful paid API response.
Before You Start: How Does the Agent Know What to Do?
When RelAI returns a consentToken and authorizeUrl, the agent won't automatically know it needs to send that link to the user and wait for approval. It's just JSON data unless the agent has been told what it means.
There are two ways to give the agent that knowledge.
Option A: System Prompt
The simplest approach. When you configure the agent, include a snippet that describes the RelAI flow.
You can call paid APIs through RelAI (https://relai.fi).
To get authorized:
- POST https://api.relai.fi/agent-keys/consent/request
with agentId, agentName, network ("solana" or "base"), and a label.
- You'll receive an authorizeUrl. Send it to the user and wait for approval.
- Once approved you'll get a serviceKey and agentId.
- Use both headers on every API call via:
GET https://api.relai.fi/metered/x?url=
X-Service-Key:
X-Agent-ID:
The agent reads this once at startup and knows exactly what to do when you say "connect to RelAI".
Option B: MCP Server
If you're building with the Model Context Protocol, you can wrap the RelAI consent flow as an MCP tool. The agent calls request_relai_authorization as a named tool, receives the authorizeUrl as a tool result, and sends it to the user. The MCP tool definition carries the description of what to do, so no prompt engineering is needed on the agent side.
The RelAI MCP server is available at https://github.com/web3luka/relai-fi-relai-mcp-server. Clone it, run npm install && npm run build, and add it to your MCP client config.
The Conversation: From Zero to First Paid Call
You're chatting with your AI agent. You want it to fetch data from paid APIs on the marketplace.
You: "Hey, I want you to connect to RelAI so you can call paid APIs on my behalf."
The agent has the system prompt and knows what to do.
Agent: "Got it. I'll request an authorization link from RelAI now. Give me a moment."
Step 1: Agent Requests a Consent Link
The agent calls RelAI to generate a one-time authorization URL it will send back to you.
POST https://api.relai.fi/agent-keys/consent/request
Content-Type: application/json
{
"agentId": "travel-agent-v1",
"agentName": "Travel Booking Agent",
"network": "solana",
"label": "Production instance"
}
RelAI responds with a short-lived consent token and a URL.
{
"consentToken": "ct_abc123xyz...",
"authorizeUrl": "https://relai.fi/authorize?token=ct_abc123xyz...",
"expiresAt": "2026-03-06T17:40:00Z"
}
Step 2: Agent Sends You the Authorization Link
The agent passes the link back to you.
Agent: "I need your permission to call APIs on your behalf. Payments will be billed to your RelAI Metered account at roughly $0.01 per call. Please approve using the link below. It's valid for 10 minutes.
https://relai.fi/authorize?token=ct_abc123xyz..."
No wallet required from the agent at this point. It just waits for your approval.
Step 3: You Approve on relai.fi
You click the link, log in to your RelAI account, and see a clear summary of what the agent is requesting: its name, which network it will pay on, and that costs will be billed to your Metered wallet.
You click Allow.
RelAI immediately issues the agent a scoped service key and delivers it back to the agent via webhook or polling.
{
"status": "approved",
"serviceKey": "sk-agent-752bdd53...",
"agentId": "42"
}
The agent stores these two values securely. That's everything it needs from now on.
Agent: "Authorization confirmed. I'm now connected to RelAI and ready to call paid APIs on your behalf."
Step 4: Agent Calls APIs Autonomously
Now when you ask the agent to fetch data from a paid API, it routes the request through the RelAI Metered proxy. RelAI handles the x402 payment silently in the background.
You: "Get me the latest crypto projects from tgmetrics."
The agent makes a single HTTP call.
GET https://api.relai.fi/metered/x?url=https%3A%2F%2Ftgmetrics.x402.fi%2Fprojects%3Fpage%3D1
X-Service-Key: sk-agent-752bdd53...
X-Agent-ID: 42
RelAI intercepts the 402 Payment Required from the API, pays $0.01 USDC from your Solana custodial wallet, and forwards the real response back to the agent.
{
"projects": [ ... ],
"page": 1,
"total": 42
}
Agent: "Here are the latest projects from tgmetrics: ..."
From your perspective, you asked and the agent answered. No payment dialogs, no wallet popups, no friction.
Step 5: Agent Monitors the Balance
The agent can check how much USDC is left in your wallet at any time and warn you when it's running low.
GET https://api.relai.fi/metered/balance
X-Service-Key: sk-agent-752bdd53...
X-Agent-ID: 42
{
"totalBalance": 0.12,
"balances": {
"solana": {
"address": "EZYjHRJSwGzfN1kT9jtcSZZH9xUQpGr4rMWR3Brv5bYU",
"balance": 0.12,
"network": "solana"
}
}
}
Agent: "Heads up. Your RelAI balance is running low ($0.12 remaining). You may want to top up to keep API calls going."
Revoking Access
You stay in control at all times. From Dashboard → Agent Keys on relai.fi you can revoke any agent's access instantly. The key stops working immediately. No pending calls and no grace period.
Summary
| Step | Who | What happens |
|---|---|---|
| 0 | You | Tell the agent to connect to RelAI |
| 1 | Agent | Calls /agent-keys/consent/request and gets a one-time link |
| 2 | Agent | Sends you the authorization link |
| 3 | You | Click Allow on relai.fi and the agent gets its sk-agent-... key |
| 4 | Agent | Calls any paid API via /metered/x and payments are automatic |
| 5 | Agent | Monitors your balance via /metered/balance |
Ready to try it? Set up your Metered account at https://relai.fi/dashboard/buyer-proxy, fund it with a few dollars of USDC, and your agent is ready to call any x402 API on the marketplace.M