@chainpeavax/agent
v2.0.0
Published
ChainPe Agent SDK — Pre-built AI agent with x402 payment capabilities on Avalanche C-Chain
Downloads
162
Maintainers
Readme
@chainpe/agent
Pre-built AI Agent with x402 Payment Capabilities on Avalanche
ChainPe Agent is an AI agent SDK that can discover, pay for, and use monetized API services. Built on the Vercel AI SDK with support for OpenAI and Anthropic.
Installation
npm install -g @chainpe/agentOr as a library:
npm install @chainpe/agentQuick Start
Prerequisites
Before you start, you'll need:
- LLM API Key - Get a free Groq API key at https://console.groq.com/
- AVAX - Available on major exchanges (Coinbase, Binance, Kraken, etc.)
- Avalanche Wallet - Generate a new wallet or use existing private key
1. Initialize Configuration
chainpe-agent initThis interactive wizard will ask you for:
- LLM Mode: Local (Ollama) or Cloud API
- LLM Provider: Groq (free), OpenAI, Anthropic, or Google Gemini
- Model selection: Recommended models shown first
- API key: Your LLM provider API key
- Avalanche wallet private key: private key (0x…) (for automatic payments)
- Preferred payment token: USDC
2. Check Status
chainpe-agent status3. Run Tasks
chainpe-agent run "Find a weather service and get the weather for San Francisco"Commands
| Command | Description |
|---------|-------------|
| chainpe-agent init | Interactive setup wizard |
| chainpe-agent status | Show config and wallet balance |
| chainpe-agent services | List available services |
| chainpe-agent run <task> | Execute a task with the agent |
Programmatic Usage
import { ChainPeAgent } from "@chainpe/agent";
// Create agent (reads config from ~/.chainpe/agent.json)
const agent = new ChainPeAgent();
// List available services
const services = await agent.listServices();
console.log(services);
// Run a task
const result = await agent.run(
"Find a research service and summarize quantum computing",
{
maxSteps: 5,
verbose: true,
onPayment: (receipt) => {
console.log(`Paid ${receipt.amount} ${receipt.token}`);
}
}
);
console.log(result.text);
console.log(`Total spent: ${result.payments.totalSpent.AVAX} AVAX`);How It Works
User Task → AI Agent → Discovers Services → Pays via x402 → Gets Response
↓
On-Chain Registry (Avalanche)- Agent receives a task from user
- Agent queries on-chain registry for relevant services
- Agent calls service, receives 402 Payment Required
- Agent signs x402 payment authorization
- Service returns data, agent processes and responds
Configuration
The agent stores config in ~/.chainpe/agent.json:
Example: Using Groq (Free Tier)
{
"llm": {
"mode": "api",
"provider": "groq",
"model": "qwen/qwen3-32b",
"apiKey": "gsk_..."
},
"wallet": {
"private key": "your twenty five word avalanche private key phrase here...",
"address": "YOUR_ALGO_ADDRESS..."
},
"payment": {
"preferredToken": "AVAX"
},
"network": "avalanche"
}Example: Using OpenAI
{
"llm": {
"mode": "api",
"provider": "openai",
"model": "gpt-4o",
"apiKey": "sk-..."
},
"wallet": {
"private key": "your twenty five word avalanche private key phrase here...",
"address": "YOUR_ALGO_ADDRESS..."
},
"payment": {
"preferredToken": "AVAX"
},
"network": "avalanche"
}Example: Using Local Ollama
{
"llm": {
"mode": "local",
"provider": "openai",
"model": "qwen2.5:7b",
"apiKey": "ollama",
"baseURL": "http://localhost:11434/v1"
},
"wallet": {
"private key": "your twenty five word avalanche private key phrase here...",
"address": "YOUR_ALGO_ADDRESS..."
},
"payment": {
"preferredToken": "AVAX"
},
"network": "avalanche"
}Supported LLMs
- Groq (Recommended for free tier): llama-3.3-70b, qwen/qwen3-32b
- OpenAI: gpt-4o, gpt-4-turbo, gpt-3.5-turbo
- Anthropic: claude-3-5-sonnet, claude-3-opus, claude-3-sonnet
- Google Gemini: gemini-2.0-flash, gemini-1.5-pro
- Local (Ollama): Any Ollama model (free, runs locally)
Getting API Keys
- Groq (Free): https://console.groq.com/ - Fast inference, generous free tier
- OpenAI: https://platform.openai.com/api-keys
- Anthropic: https://console.anthropic.com/
- Google AI: https://aistudio.google.com/app/apikey
Requirements
- Node.js >= 18
- LLM API key (Groq recommended for free tier) OR local Ollama installation
- Avalanche wallet with AVAX (available on major exchanges)
License
MIT
