跳到正文
DEV Community· Damien·· 7 天前AI 評分52

AIPayGen 教學:用純 HTTP 為 AI 智能體設定預算、審批按鈕和晨間例行任務

Give your AI agent a budget, an approval button and a morning routine (with plain HTTP)

AI 導讀

Damien 以 AIPayGen 示範如何只用 curl,為 AI 智能體按次支付工具費用、設定每日支出上限、請求人手審批及安排定時任務。用戶可為每個智能體建立獨立 API key 並設定每日上限;達限後請求會被拒絕,直至下一個 UTC 日,擁有人亦可更改上限或暫停智能體。

正文

Once an agent does real work, three questions come up fast:

  1. How does it pay for an API without me signing up for everything?
  2. How does it ask me before doing something risky?
  3. How do I cap what it can spend?

This tutorial sets all three up with AIPayGen (disclosure: my project) using only curl. It works the same from Python, JavaScript or any MCP client.

1. Get a free key

curl -X POST https://aipaygen.com/v1/keys

The response includes api_key (starts with apg_), shown only once. Save it:

export APG=apg_your_key_here

The key comes with a small trial credit, and the cheapest tools give a few free calls a day. Agents with their own wallet can skip keys entirely and pay per call with x402 (USDC on Base).

2. Call a tool

Every tool is POST /v1/<tool name> with a JSON body:

curl -X POST https://aipaygen.com/v1/dns_lookup \
  -H "Authorization: Bearer $APG" \
  -H 'content-type: application/json' \
  -d '{"domain":"example.com"}'

There are 95 tools: web and company data, crypto and markets, reference data, and AI text and media. The full list with prices is at aipaygen.com/docs. A failed call is never charged.

3. Give each agent its own key and a daily limit

Instead of handing every agent your main key, create one key per agent with a cap:

curl -X POST https://aipaygen.com/v1/keys/agents \
  -H "Authorization: Bearer $APG" \
  -H 'content-type: application/json' \
  -d '{"label":"research-bot","daily_cap_usd":0.02,"fund_usd":0.03}'

fund_usd moves credit from your key to the agent's (the trial credit is small, so top up by card on the site for real use). The agent gets its own api_key. When it reaches its daily limit, its calls are refused with DAILY_CAP_REACHED until the next UTC day. Only the owner key can change the limit, pause the agent or take credit back:

curl -X PATCH https://aipaygen.com/v1/keys/agents/AGENT_ID \
  -H "Authorization: Bearer $APG" \
  -H 'content-type: application/json' \
  -d '{"paused":true}'

4. Ask before acting

When the agent is about to do something you'd want to approve, it calls ask_human:

curl -X POST https://aipaygen.com/v1/ask_human \
  -H "Authorization: Bearer $AGENT_KEY" \
  -H 'content-type: application/json' \
  -d '{"question":"Renew the example.com domain for $12?","details":"It expires in 9 days."}'

You get a push in the AIPayGen app on your phone (more on that below) with Approve and Deny. To also reach you on Telegram, Discord, Slack or ntfy, add "notify": {"channel": "...", "target": "..."}.

The response has an id and a status_token. The agent checks the answer for free:

curl -X POST https://aipaygen.com/v1/ask_status \
  -H 'content-type: application/json' \
  -d '{"id":"ID","status_token":"STATUS_TOKEN"}'

The status is pending, answered (with your choice) or expired. Or pass a webhook and the answer is POSTed to you.

5. Add a morning routine

schedule_create runs any tool on repeat and sends the result to your app:

curl -X POST https://aipaygen.com/v1/schedule_create \
  -H "Authorization: Bearer $APG" \
  -H 'content-type: application/json' \
  -d '{"tool":"news_search","input":{"query":"x402 payments","timespan":"1d","limit":10},"every_minutes":1440,"start_at":"2026-12-01T08:00:00Z","deliver":{"channel":"app"}}'

Each run is billed at the tool's normal price. If the key runs out of credit, the routine pauses instead of failing over and over.

For "tell me when something changes", use watch_create: a site goes down, a page changes, a domain nears expiry, or a coin crosses a price. Checks that find nothing cost nothing.

6. Install the phone app

Open aipaygen.com/app on your phone, sign in with your key, and add it to your Home Screen (on iPhone: Share → Add to Home Screen, iOS 16.4 or later for push). From there you can:

  • approve or deny your agents' questions
  • see alerts and routine results
  • see spending per agent and change limits
  • ask the built-in assistant to set things up ("alert me if ETH goes above 5000")

Using it from Claude, Cursor or another MCP client

Add https://mcp.aipaygen.com/mcp as a remote MCP server. Every tool above shows up, including ask_human, schedule_create and watch_create.


That's the whole loop: the agent pays per call, asks before risky steps, runs on a timer, and can't spend past its limit. I'd like to hear what you'd automate first, and what's missing. aipaygen.com

來源:DEV Community · dev.to