payagent
v5.0.0
Published
Let AI agents pay for APIs. A fetch wrapper that pays HTTP 402 responses from an ArisPay funding account, inside spend limits that ArisPay enforces.
Maintainers
Readme
payagent
Let AI agents pay for APIs. The ArisPay SDK and CLI.
payagent is a fetch wrapper. When a seller answers HTTP 402 with an
arispay-fiat offer, payagent pays it from your ArisPay funding account
and repeats the request. ArisPay enforces the agent's limits: per
transaction, per day, per month, and by domain. Currencies: EUR, GBP, USD.
A 402 that has no arispay-fiat offer is not paid. The call throws
InvalidRequirementsError.
Install
npm install payagentRequires Node.js >= 18.
Quick start (CLI)
# 1. Create an account and an agent. No browser is necessary.
npx payagent quickstart --email [email protected]
# 2. Pay a paid API.
npx payagent pay https://api.example.com/premiumquickstart saves the developer key and the agent key to
~/.payagent/config.json. The MCP server @arispay/payagent-mcp reads the
same file.
Add money to your funding account before the first payment. Open the ArisPay dashboard and top up by card.
Quick start (library)
import { bootstrapAgent } from "payagent";
const agent = await bootstrapAgent({ email: "[email protected]" });
const res = await agent.fetch("https://api.example.com/premium");With an agent key that you already have:
import { payFetchDelegated } from "payagent";
const pay = payFetchDelegated({
arispayUrl: "https://api.arispay.app",
apiKey: process.env.ARISPAY_AGENT_KEY!,
idempotencyKey: "order-1234", // optional, makes a retry safe
onPayment: (info) => console.log(info.amountCents, info.remainingDaily),
});
const res = await pay("https://api.example.com/premium");onPayment fires after ArisPay authorizes the payment, when the server
sends the spend data. All amounts are integer cents.
How a payment works
payagentsends your request.- The seller answers 402 with an
arispay-fiatoffer: merchant, currency, amount in cents. payagentcallsPOST /v1/fiat/authorizeat yourarispayUrl. ArisPay checks the agent, its limits, its allowed domains and the balance, then returns a single-use authorization.payagentrepeats the request with the authorization inX-PAYMENT.- The seller settles the authorization at ArisPay, then serves the response.
payagent never calls the authorizeEndpoint that a seller names. It
calls only your configured arispayUrl.
Errors
| Error | Meaning |
|---|---|
| InvalidRequirementsError | The 402 could not be read, or it has no arispay-fiat offer. |
| PaymentRejectedError | ArisPay refused to authorize, or the seller rejected the payment. |
| PaymentUndeliveredError | The seller took the payment and then failed. You were charged. |
PaymentUndeliveredError has paymentId and safeRetry. When safeRetry
is true, repeat the request with the same idempotencyKey inside 10
minutes: the seller serves it again and does not charge again. When it is
false, a repeat pays again. A fiat payment can be refunded.
Manage agents
import { DelegationClient, launchAgent, syncAgents } from "payagent";
const client = new DelegationClient("https://api.arispay.app", process.env.ARISPAY_API_KEY!);
await launchAgent({ name: "hermes", limits: { perTx: 50, daily: 1000, monthly: 10000 } });
await syncAgents(); // list from the server
await client.updateAgent(agentId, { suspended: true }); // stop all payments
await client.renameAgent(agentId, "Travel");
await client.rotateX402Key(agentId); // new agent key
await client.listAgentPayments(agentId); // payment historyLimits are integer cents.
CLI
payagent quickstart --email X create an account and an agent
payagent init pair an existing account in the browser
payagent connect CODE connect a BuyForMe wallet to this computer
payagent pay URL make one paid request
payagent pay-merchant URL ... create a merchant payment (card, balance, mpp)
payagent agent create|list|rename|remove
payagent user create|get|attach-card|set-limits|status
payagent discover "QUERY" search the ArisPay marketplace (free)
payagent doctor | whoami | logoutEnvironment: ARISPAY_API_KEY, ARISPAY_URL, PAYAGENT_CONFIG_DIR,
PAYAGENT_NO_UPDATE_CHECK.
Framework tools
import { createPayAgentTool } from "payagent/vercel"; // Vercel AI SDK
import { createPayAgentTool } from "payagent/langchain"; // LangChain
const tool = createPayAgentTool({ arispayUrl: "https://api.arispay.app", apiKey });Sell an API
Use paygate to put a price on a
route. It sends the 402 that payagent pays.
License
MIT
