Give Your AI Agent a Credit Line in 5 Minutes
Step-by-step tutorial: sign up, create a wallet, set spending limits, and make your first x402 payment with the TypeScript SDK.
This tutorial walks you through giving an AI agent its own credit line with Mithril. By the end, your agent will be able to pay for any x402 service autonomously.
Prerequisites
Step 1: Get Your API Key
After signing up, navigate to the dashboard and generate an API key. This key authenticates your agent with the Mithril API.
Store it as an environment variable:
export MITHRIL_API_KEY="mk_live_..."Step 2: Install the SDK
TypeScript:
npm install @mithril/sdkPython:
pip install mithrilStep 3: Create a Wallet
Each agent should have its own wallet. Create one via the SDK:
import Mithril from "@mithril/sdk"
const m = new Mithril({
apiKey: process.env.MITHRIL_API_KEY,
})
// Your default wallet is created automatically
const wallets = await m.wallets.list()
console.log(wallets[0].id) // "wal_..."Step 4: Set Spending Limits
Configure daily and per-transaction limits for safety:
// Check your spending power
const power = await m.spendingPower()
console.log(power.available) // "100.00" USDCStep 5: Make Your First x402 Payment
Now the magic — call any x402 service and Mithril handles payment automatically:
const result = await m.pay({
url: "https://api.exa.ai/search",
method: "POST",
body: JSON.stringify({
query: "best AI agent frameworks 2026",
numResults: 10,
}),
})
console.log(result.data) // Search results!That's it. The SDK detected the 402 response, paid with USDC on-chain, and retried the request — all transparently.
Step 6: Monitor Spending
Check your agent's transactions:
const transactions = await m.wallets.transactions(walletId)
transactions.forEach(tx => {
console.log(`${tx.service}: ${tx.amount} USDC`)
})Alternative: SKILL.md (No SDK Required)
If you're using Claude Code, Codex, or any MCP-compatible agent, you can skip the SDK entirely. Just point your agent to:
https://trymithril.com/SKILL.mdThe agent reads the SKILL.md and gains full API access — including x402 payments — without any code integration.