pai
Provides sandboxed command execution using Docker containers, allowing agents to run commands in isolated, throwaway environments.
Allows reading and sending emails via Gmail's IMAP/SMTP, with support for managing drafts and searching messages.
Allows reading and sending emails via iCloud's IMAP/SMTP, with support for managing drafts and searching messages.
Provides sandboxed command execution using Podman containers, allowing agents to run commands in isolated, throwaway environments.
Enables agents to manage Solana wallets and pay for credit on the Phantom AI platform using USDC or SOL.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@paicreate a child key with $0.50 for 6 hours"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pai runs on your machine and manages a Phantom AI key.
Your agent can hand each subagent a child key with its own spending limit, lifetime, and rate cap.
It also sets plans and model routing, pays for credit from an agent wallet, and checks which model answered a call.
pi, Claude Code, Codex, and Cursor drive it through a skill, and any MCP client can use pai mcp.
The CLI is MIT licensed. The Phantom AI API it calls is a hosted service.
How It Works
┌────────────────────────┐
│ Main Phantom Key │
│ (prepaid, no id) │
└───────────┬────────────┘
│
┌───────────────────────┼───────────────────────┐
│ pai child │ pai child │ pai wallet
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Researcher │ │ Code Agent │ │ Agent Wallet │
│ Claude Code │ │ Cursor │ │ (Solana) │
│ $0.50 limit │ │ $1.00 limit │ │ auto-topup │
│ 6 hour TTL │ │ $0.10 / min │ │ below $1.00 │
└──────┬───────┘ └──────┬───────┘ └──────────────┘
│ │
└───────────┬───────────┘
▼
┌───────────────────────┐
│ Phantom AI Gateway │ ──> https://phantom.codes/v1
│ (zero prompt logs) │ ──> Ed25519 signed receipts
└───────────────────────┘Related MCP server: L402 Gateway
Features
Scoped Subagent Keys — Create child keys that spend the parent's balance up to a limit, with lifetimes and rate caps (
pai child). Revoke one withpai burn.Autonomous Agent Wallet — Local Solana keypairs allow running agents to self-fund inference on chain. Capped by environment-only limits (
PHANTOM_WALLET_MAX_USD).Multi-Agent Skill & MCP — Native skill installation for
pi,Claude Code,Codex, andCursor, plus a 16-tool Model Context Protocol (MCP) server over stdio.Cryptographic Receipts — Upstream responses return an Ed25519 signature verifying the model served, actual token counts, and cost (
pai verify).Local Tooling Suite — Private local markdown memory notebooks, throwaway Docker sandboxes, and safe IMAP/SMTP mail drafting.
Install
npm i -g @phantom-ai/paiThe package also installs the same CLI as phantom-key, its earlier name.
Quickstart
# 1. Login once and install the skill for your installed agents
pai login # paste your key once; pai saves it with mode 600
pai setup # configures pi, Claude Code, Codex, and Cursor
# 2. Check balance and active caps
pai balance
# 3. Mint a child key for an autonomous subagent
pai child --limit 0.50 --ttl 6 --rate 0.10 --save researcher
# 4. Run the subagent as the scoped child
PHANTOM_KEY_NAME=researcher claudeUse It From an Agent
pai setup installs the phantom-ai skill for each agent it finds in your
home directory (pi, Claude Code, Codex, Cursor). You can then prompt your agent in
plain words, for example:
"Give a subagent $0.50 for 6 hours with a $0.10/min rate cap."
--agent pi(orclaude,codex,cursor) sets up one agent.--mcpalso registers the MCP server with Claude Code, Codex, and Cursor.pihas no MCP and uses the CLI through the skill; install there with:pi install npm:@phantom-ai/pai
Commands
pai --help prints every command and flag. docs/reference.md
has the complete text, the MCP tools, and the environment variables, all generated
from the code.
Group | Commands | What they do |
Setup |
| Save your key, and install the skill for your agents |
Keys |
| Show credit, create child keys paid from this key, save keys by name, and replace or revoke a key |
Caps and plans |
| Set a monthly cap and a per-minute cap, or money for a period |
Routing |
| Choose which models |
Credit |
| Buy credit with crypto |
Agent wallet |
| Keep Solana wallets and pay for credit from them. See Let the agent pay |
Receipts |
| Check which model answered a call, from its signed receipt |
Local tools |
| See the sections below |
MCP |
| Run an MCP server over stdio. See Use with an MCP client |
A command runs as the saved key named by PHANTOM_KEY_NAME if it is set, then
as PHANTOM_API_KEY, then as the login key. A subagent started with
PHANTOM_KEY_NAME=<child> runs as the child even when your parent key is exported.
Memory
Each agent gets a private notebook on this machine. Notes are markdown files in
~/.config/phantom-key/memory/<space>/, so you can read, edit, or commit them.
pai sends none of them anywhere.
Command | What it does |
| Keeps a note. Pipe long notes on stdin |
| Notes with every word (or any word with |
| The newest notes (50 by default), one note, or delete one |
| Each notebook and how many notes it holds |
pai picks the notebook from --space, then PAI_MEMORY_SPACE, then the saved
key name (PHANTOM_KEY_NAME), then main, so each subagent keeps its own.
pai reads your own mailbox over IMAP and SMTP. It saves the login, with an app
password, in ~/.config/phantom-key/mail.json (mode 600). Gmail, Outlook,
iCloud, and Fastmail addresses have presets; for any other provider, pass
--imap host:port --smtp host:port.
Command | What it does |
| Checks the login by listing one message, then saves it. A wrong password is not saved. The password comes from a prompt or |
| Shows the mailbox and whether sending is on |
| Reads mail from |
| Saves a draft in your Drafts folder and sends nothing. Without |
| Sends only when |
Browser and Sandbox
pai wraps two existing tools:
Command | What it does |
| Checks for agent-browser, a headless Chrome built for agents. |
| Runs agent-browser ( |
| Reports whether Docker or Podman is running |
| Runs a command in a throwaway container (default image |
Output Format
Commands print JSON on stdout, so you can pipe into jq. --table prints
a formatted table for human inspection. browser and sandbox run pass through the exit code of the
command they ran.
Exit code | Meaning |
| Success |
| Any other error |
| Key rejected (401/403). Get a new key; a retry fails the same way |
Use With an MCP Client
pai mcp starts an MCP server over stdio. Add it to your client's config:
{
"mcpServers": {
"phantom": {
"command": "npx",
"args": ["-y", "@phantom-ai/pai", "mcp"]
}
}
}docs/reference.md lists every tool with its inputs and whether it is read-only or destructive.
delete_key authenticates as the key you pass in api_key or key_name and
deletes that key. It refuses the key the server runs as; use pai burn for
that.
Let the Agent Pay
The agent can maintain its own Solana wallets and buy credit with them. Each wallet
is a Solana keypair in ~/.config/phantom-key/wallets/ (mode 600). The wallet
pays Phantom AI's Solana address, and Phantom AI finds the payment on chain.
Create a wallet, and back up its file:
pai wallet create --table # saved as "main" pai wallet create --name work --table # a second oneFund the address with USDC on Solana, plus some SOL for fees (at least 0.003 SOL).
Set the safety cap:
export PHANTOM_WALLET_MAX_USD=10Without this variable,
pairefuses to pay. The total over 24 hours is capped byPHANTOM_WALLET_MAX_USD_PER_DAY, which defaults to the same amount: one payment a day. Raise it forautotopup.Pay:
pai buy --amount 5 --payWith more than one wallet saved,
paiasks in a terminal which one pays. It then reports each step:Getting a payment request from Phantom AI (amount, recipient, and unique reference)
Sending USDC or SOL from your wallet
Confirming on Solana
Phantom AI finding the payment on chain by its reference
Credit balance before and after
A payment request expires after 30 minutes.
You can also prompt your agent: "Top up my Phantom AI key with $5 from my Phantom agent wallet."
Over MCP it calls list_wallets, asks which wallet if not specified, then calls pay_for_credit.
To refill automatically when the balance runs low:
pai autotopup --below 1 --amount 5 --wallet main --every 10Safeguards
paipays the recipient and exact amount the payment request names, with that request's reference attached.paireadsPHANTOM_WALLET_MAX_USDandPHANTOM_WALLET_MAX_USD_PER_DAYstrictly from the environment; no flag or tool argument can raise them.Before signing,
paichecks the payment request against what it asked for: the coin, the USDC mint, and an amount no more than requested (for SOL, within 10% of Coinbase's price). A wrong or hostilePHANTOM_BASE_URLcannot make it sign more.One payment runs at a time, across processes.
paiverifies the wallet balance before requesting a payment.pairecords payments in~/.config/phantom-keybefore sending, and keeps the record until Phantom AI reports the payment credited or dead. If a run crashes, times out or loses the connection, the next run waits for that payment instead of paying again.These limits bind an agent that reaches pai through MCP. An agent with its own shell can set environment variables and edit the state folder, so give such an agent a wallet holding only what you are willing for it to spend.
Store wallet secrets in a local secrets manager (e.g. KRU) and inject
PHANTOM_WALLET_KEYat runtime.
Configuration
pai reads its settings from environment variables. Run pai --help or see
docs/reference.md#environment-variables for the full list,
including secrets, environment-only flags, and caps.
Requirements
Node 24 or newer
Runtime dependencies:
@modelcontextprotocol/sdkandzodformcp,@solana/kitfor wallet payments, andimapflow,mailparser,nodemailerformail.
Read phantom.codes/docs/concepts for key lifecycle and subagent hierarchy details.
Development
npm ci
npm test # vitest
npm run typecheck
npm run docs # regenerate docs/reference.md
node src/pai.mts --help # run from sourceContributing
See CONTRIBUTING.md for setup, style, and how to add a command or MCP tool. CHANGELOG.md lists changes by release.
Security
Report vulnerabilities privately through a GitHub security advisory. See SECURITY.md.
License
This server cannot be deployed
Maintenance
Related MCP Connectors
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Give AI agents identity, permissions, and reusable proof through one MCP.
One MCP tool for verified AI-agent outcomes with success-only charging.
Connect MCP clients to 2,000+ AI models without managing provider API keys.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceMCP server for AgentPay — the payment gateway for autonomous AI agents. Fund a wallet once, give your agent the key, and it discovers, provisions, and pays for tool APIs on its own. One key, every tool.112 npm1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to manage Bitcoin micropayments, service offers, and escrow contracts through MCP tools, without requiring a Lightning node.9 npmMIT
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to manage personal finances through MCP tools for transaction management, spending analytics, and goal tracking.1-
- AlicenseAqualityAmaintenanceEnables MCP clients to manage and orchestrate autonomous agents, budgets, and multi-agent workflows within the OpenMesha agentic operating system.91Apache 2.0