@axonfi/plugin-vercel-ai
v0.1.1
Published
Vercel AI SDK tools for Axon — treasury and payment infrastructure for autonomous AI agents
Maintainers
Readme
@axonfi/plugin-vercel-ai
Vercel AI SDK tools for Axon — treasury and payment infrastructure for autonomous AI agents.
Gives your AI agent the ability to send payments, swap tokens, execute DeFi protocols, and check vault balances through Axon's non-custodial vaults.
Prerequisites
Before using this plugin, you need an Axon vault:
- Go to app.axonfi.xyz and connect your wallet
- Deploy a vault - this is your non-custodial treasury. Only you (the owner) can withdraw.
- Register a bot key - generate a new key pair in the dashboard or bring your own. This is the key your agent will sign with. Set a
maxPerTxAmountto cap what the bot can spend per transaction. - Fund the vault - deposit USDC (or any ERC-20) into your vault address.
- Copy your credentials:
vaultAddress- your deployed vault addressbotPrivateKey- the bot's private key (the one registered in step 3)chainId-Chain.Base(8453),Chain.Arbitrum(42161), orChain.BaseSepolia(84532) for testing —import { Chain } from '@axonfi/sdk'
Your bot signs payment intents. It never holds funds, never pays gas, and can only spend within the limits you set. If the bot key is compromised, the attacker is capped by maxPerTxAmount and can only send to whitelisted destinations.
Installation
npm install @axonfi/plugin-vercel-ai @axonfi/sdk ai zodQuick Start
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { createAxonTools } from '@axonfi/plugin-vercel-ai';
import { Chain } from '@axonfi/sdk';
const tools = createAxonTools({
botPrivateKey: process.env.BOT_PRIVATE_KEY as `0x${string}`,
vaultAddress: process.env.VAULT_ADDRESS as `0x${string}`,
chainId: Chain.Base,
});
const { text } = await generateText({
model: openai('gpt-4o'),
tools,
maxSteps: 5,
prompt: 'Send 5.00 USDC to 0xRecipient...',
});
console.log(text);Available Tools
| Tool | Description |
|------|-------------|
| pay | Send a payment from the vault (e.g. "5.00" USDC) |
| swap | Swap tokens within the vault for rebalancing |
| executeProtocol | Call a DeFi protocol (approve/call/revoke pattern) |
| getBalance | Check the vault balance for a specific token |
| getVaultValue | Get total vault USD value with per-token breakdown |
pay
Send a payment to any recipient address. The full Axon pipeline applies: policy checks, AI verification (if configured), and on-chain execution via the relayer.
// The AI agent decides to call this tool with:
// { to: "0x...", amount: "5.00", token: "USDC", memo: "API subscription" }Parameters:
to(required) — Recipient address (0x...)amount(required) — Human-readable amount (e.g. "5.00" for 5 tokens)token(optional) — Token symbol or address. Defaults to "USDC"memo(optional) — Payment description
swap
Swap tokens within the vault. Tokens remain in the vault (no external recipient). Useful for rebalancing holdings.
// { fromToken: "USDC", toToken: "WETH", amount: "100.00" }Parameters:
fromToken(required) — Source token symbol or addresstoToken(required) — Destination token symbol or addressamount(required) — Maximum amount of fromToken to spend
executeProtocol
Execute a DeFi protocol call. The vault approves tokens to the target, calls it, then revokes approvals. The target must be approved on the vault.
// { target: "0x...", calldata: "0x...", tokens: ["USDC"], amounts: ["100.00"] }Parameters:
target(required) — Protocol contract addresscalldata(required) — Hex-encoded calldatatokens(optional) — Token symbols to approveamounts(optional) — Approval amounts (human-readable)memo(optional) — DescriptionprotocolName(optional) — Protocol name (e.g. "Aave Deposit")
getBalance
Check vault balance for a token.
// { token: "USDC" }
// Returns: { token: "USDC", formatted: "1250.500000", balance: "1250500000", decimals: 6 }Parameters:
token(optional) — Token symbol or address. Defaults to "USDC"
getVaultValue
Get total vault USD value with a breakdown by token.
// {} (no parameters)
// Returns: { totalValueUsd: 5230.45, tokens: [{ symbol: "USDC", valueUsd: 3000, ... }, ...] }Configuration
import { Chain } from '@axonfi/sdk';
createAxonTools({
botPrivateKey: '0x...', // Bot's private key (signs EIP-712 intents)
vaultAddress: '0x...', // Axon vault contract address
chainId: Chain.Base, // Chain.Base, Chain.Arbitrum, Chain.BaseSepolia
relayerUrl: '...', // Optional, defaults to https://relay.axonfi.xyz
});How It Works
- Your AI agent (via Vercel AI SDK) decides to call an Axon tool
- The plugin signs an EIP-712 intent with the bot's private key
- The signed intent is submitted to the Axon relayer
- The relayer runs policy checks (spending limits, velocity, whitelist/blacklist)
- If thresholds are triggered, a 3-agent AI verification scan runs
- Approved intents are executed on-chain by the relayer (the bot never pays gas)
- The tool returns the result (status, txHash, or rejection reason)
Using with Other AI Providers
The tools work with any model supported by the Vercel AI SDK:
import { anthropic } from '@ai-sdk/anthropic';
const { text } = await generateText({
model: anthropic('claude-sonnet-4-20250514'),
tools,
maxSteps: 5,
prompt: 'Check my vault balance and tell me the total value in USD.',
});License
MIT
