---
name: jpyon-agent
description: Use when an AI agent needs to pay for APIs or services with JPYC (Japanese Yen stablecoin) on Polygon using gasless x402 payments. Triggers for JPYC gasless payment, agent wallet setup, x402 protocol, or autonomous API purchasing with JPYC.
---

# JPYON Agent — AIエージェント向け JPYC 決済インフラ

AIエージェントが **JPYC（日本円ステーブルコイン）** で API・サービスを自律決済するためのインフラです。
x402 プロトコル対応。ガスレス。ワンライナーで即使用可能。

**提供元**: JPYON ウォレット  
**対象チェーン**: Polygon Mainnet（Chain ID: 137）  
**サービスサイト**: https://jpyon.jp.ai  
**npm**: https://www.npmjs.com/package/@jpyonchain/aiagent

---

## できること

- **x402 自動決済**: `402 Payment Required` を受け取ったら自動で JPYC 署名・送信・リトライ
- **ガスレス決済**: EIP-3009 署名のみ。MATIC 不要（Plan 配分内）。配分はサーバーが管理
- **予算管理**: リクエスト上限・時間窓上限をローカルポリシーで設定
- **監査ログ**: 全支払い試行を記録（成功・失敗・dry-run）
- **Dry-run**: 実際に送金せずシミュレーション可能
- **Plan 管理**: JPYC でガスレス配分を購入・拡張

---

## インストール

```bash
# CLI として使う場合
npm install -g @jpyonchain/aiagent

# ライブラリとして使う場合
npm install @jpyonchain/aiagent
```

---

## クイックスタート（API）

```typescript
import { createAgent } from "@jpyonchain/aiagent/agent";

const agent = await createAgent({
  relayUrl: "https://jpyon.jp.ai",
  policy: {
    maxPerRequestJpyc: "10",
    maxPerWindowJpyc: "100",
  },
});

// x402 保護 API を自動決済でフェッチ
const response = await agent.fetch("https://api.example.com/premium-data");
const data = await response.json();
```

---

## クイックスタート（CLI）

```bash
jpyon init                                              # ウォレット初期化
jpyon status                                           # ウォレット状態 + Plan 確認
jpyon fetch https://api.example.com/premium-data       # 自動決済フェッチ
jpyon fetch https://api.example.com/premium --dry-run  # シミュレーション
jpyon plan status                                       # Plan・ガスレス残配分確認
jpyon plan buy standard                                 # Plan 購入（500 JPYC）
jpyon services list                                     # 登録サービス一覧
jpyon services compare weather                          # 価格比較
jpyon audit                                             # 支払い履歴
```

---

## アーキテクチャ原則

- **サーバー制御**: ガスレス可否・配分はすべて JPYON サーバーが決定。エージェントが自分で変更不可
- **自動フォールバック**: ガスレス枠を超えた場合、エージェントが自動で通常決済（MATIC 自払い）に切り替え
- **非カストディアル**: 秘密鍵はローカルにのみ保存。サーバーに送信されない

---

## Plan 制度

| Plan | ガスレス上限 | 月額 |
|------|-------------|------|
| Free | 10回/日 | 無料（初回自動付与） |
| Standard | 100回/日 | 500 JPYC/月 |
| Pro | 1,000回/日 | 3,000 JPYC/月 |
| Enterprise | 無制限 | 要契約 |

Plan 購入自体は JPYON がガスレスで relay（MATIC 不要）。

---

## 環境変数

| 変数名 | 説明 |
|--------|------|
| `JPYON_RELAY_URL` | リレー URL（デフォルト: https://jpyon.jp.ai） |
| `ENCRYPTION_KEY` | 秘密鍵暗号化キー（推奨） |
| `POLYGON_RPC_URL` | 通常決済フォールバック用 RPC |
| `JPYON_DRY_RUN` | `true` でシミュレーションのみ |

---

## サービスレジストリ API（企業向け）

自社 API を JPYON レジストリに登録すると、エージェントが自動発見・購入できるようになります。

**認証方式**: API key 不要。ウォレット署名で認証します。1つのウォレットで複数サービスを管理可能。

### 署名の生成（Node.js）

```javascript
import { ethers } from "ethers";

const wallet = new ethers.Wallet("YOUR_PRIVATE_KEY");
const authTimestamp = Math.floor(Date.now() / 1000);
const authSignature = await wallet.signMessage(`jpyon-registry:${authTimestamp}`);
const ownerAddress = wallet.address;
```

### サービス登録

```bash
curl -X POST https://jpyon.jp.ai/api/services/register \
  -H "Content-Type: application/json" \
  -d '{
    "serviceId": "my-api",
    "name": "My Premium API",
    "nameJa": "プレミアム API",
    "endpoint": "https://api.example.com/v1",
    "capabilities": ["data", "analytics"],
    "provider": "My Company",
    "ownerAddress": "0xYOUR_WALLET_ADDRESS",
    "authTimestamp": 1234567890,
    "authSignature": "0x...",
    "pricing": [{
      "chainId": 137,
      "tokenAddress": "0x6AE7Dfc73E0dDE2aa99ac063DcF7e8A63265108c",
      "tokenSymbol": "JPYC",
      "amount": "100000000000000000",
      "displayAmount": "0.1 JPYC per request",
      "unit": "per-request"
    }]
  }'
```

レスポンス例:
```json
{
  "ok": true,
  "serviceId": "my-api",
  "ownerAddress": "0x..."
}
```

### サービス一覧取得（エージェントが使用）

```bash
# 全件取得
curl https://jpyon.jp.ai/api/services

# capabilities でフィルタ
curl "https://jpyon.jp.ai/api/services?capabilities=weather,forecast"

# オーナーのサービス一覧
curl "https://jpyon.jp.ai/api/services?owner=0xYOUR_WALLET_ADDRESS"
```

### サービス詳細取得

```bash
curl https://jpyon.jp.ai/api/services/my-api
```

### サービス更新（ウォレット署名必須）

```bash
curl -X PUT https://jpyon.jp.ai/api/services/my-api \
  -H "Content-Type: application/json" \
  -d '{
    "ownerAddress": "0xYOUR_WALLET_ADDRESS",
    "authTimestamp": 1234567890,
    "authSignature": "0x...",
    "description": "Updated description"
  }'
```

### サービス削除（ウォレット署名必須）

```bash
curl -X DELETE https://jpyon.jp.ai/api/services/my-api \
  -H "Content-Type: application/json" \
  -d '{
    "ownerAddress": "0xYOUR_WALLET_ADDRESS",
    "authTimestamp": 1234567890,
    "authSignature": "0x..."
  }'
```

---

## 参考リンク

- [JPYON Agent ガイド](https://jpyon.jp.ai/agent-guide.html)
- [npm パッケージ](https://www.npmjs.com/package/@jpyonchain/aiagent)
- [x402 仕様](https://x402.org)
- [EIP-3009](https://eips.ethereum.org/EIPS/eip-3009)
- [JPYC 公式](https://jpyc.co.jp)
- お問い合わせ: jpyon@email.jp.ai
