AISP Agent Skill
Agent Inference Sharing Protocol (AISP) lets agents rent idle DIEM/Venice API capacity via USDC escrow. Providers list capped API keys; agents fund and receive keys automatically.
Architecture
CODEBLOCK0
Agent Workflow (Renting)
- 1. Listings from backend: INLINECODE0
- Approve USDC if needed (contract spends on
fund) - Fund on-chain:
contract.fund(listingId, termDays, diemAmount) → returns INLINECODE3 - Get key:
POST /api/key/{rentalId} with signed message INLINECODE5 - Use
apiKey with Venice API until expiresAt (Unix timestamp)
SDK (Agent)
CODEBLOCK1
Provider Workflow (Listing)
- 1. Create listing on-chain:
contract.list(pricePerDay, termDays, diemMin, diemMax) → INLINECODE9 - Store key on backend:
POST /api/keys with INLINECODE11
- Message:
diem-marketplace:store-key:{listingId}:{timestamp}
- 3. Settle when rental expires:
contract.settle(rentalId) → provider receives 99% (1% protocol fee)
SDK (Provider)
CODEBLOCK2
Key Paths
| Path | Purpose |
|---|
| INLINECODE14 | DiemAgent: getListings, rent, getKey, getMyRentals |
| INLINECODE15 |
DiemProvider: createListing, settle, revokeAndRefund |
|
backend/src/routes.ts | API routes: /api/listings, /api/keys, /api/key/:id |
|
contracts/DiemMarketplace.sol | On-chain escrow, 1% fee |
Backend API
| Endpoint | Method | Purpose |
|---|
| INLINECODE18 | GET | List rentable listings |
| INLINECODE19 |
GET | Single listing |
|
/api/keys | POST | Provider stores API key |
|
/api/key/:rentalId | POST | Agent retrieves key (signature required) |
|
/api/balance | POST | Check DIEM balance for API key |
|
/api/requests | POST | Create rental request |
Signatures
All backend requests requiring auth use EIP-191 signing:
- -
getKey: INLINECODE25 - INLINECODE26 : INLINECODE27
- INLINECODE28 :
apiKey in body (no signature)
Contract (Base)
- - Chain: Base (8453)
- Mainnet: INLINECODE30
- USDC: INLINECODE31
Security & Signing
- - Use an external signer or hardware wallet; never paste raw private keys.
- Require explicit user confirmation before fund transfers or credential usage.
- Venice API keys must be scoped (inference-only), revocable, and minimal for escrow.
Notes
- - Venice API keys must be inference-only (not admin)
- 1% protocol fee deducted at settlement
AISP 代理技能
代理推理共享协议(AISP)允许代理通过USDC托管租用闲置的DIEM/Venice API容量。提供者列出带上限的API密钥;代理自动充值并接收密钥。
架构
代理: fund() → 后端检测到Funded事件 → 密钥释放 → 代理使用Venice API
提供者: list() → 代理充值 → 期限到期 → settle() → 提供者获得报酬(99%,1%手续费)
代理工作流程(租用)
- 1. 从后端获取列表:GET /api/listings
- 如需则批准USDC(合约在fund时支出)
- 链上充值:contract.fund(listingId, termDays, diemAmount) → 返回rentalId
- 获取密钥:POST /api/key/{rentalId},附带签名消息diem-marketplace:get-key:{rentalId}:{timestamp}
- 在expiresAt(Unix时间戳)之前使用apiKey调用Venice API
SDK(代理)
typescript
import { DiemAgent } from diem-marketplace-sdk;
const agent = new DiemAgent({
signer: wallet,
contractAddress: 0x...,
backendUrl: https://diem-marketplace-backend.fly.dev,
usdcAddress: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
});
const listings = await agent.getListings();
const { apiKey, expiresAt } = await agent.rent(
listings[0].listingId,
termDays,
ethers.parseUnits(diemAmount, 6)
);
提供者工作流程(列出)
- 1. 链上创建列表:contract.list(pricePerDay, termDays, diemMin, diemMax) → listingId
- 在后端存储密钥:POST /api/keys,附带{ listingId, apiKey, signature, timestamp }
- 消息:diem-marketplace:store-key:{listingId}:{timestamp}
- 3. 租用到期时结算:contract.settle(rentalId) → 提供者获得99%(1%协议手续费)
SDK(提供者)
typescript
import { DiemProvider } from diem-marketplace-sdk;
const provider = new DiemProvider({
signer: wallet,
contractAddress: 0x...,
backendUrl: https://diem-marketplace-backend.fly.dev,
usdcAddress: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
});
const listingId = await provider.createListing({
pricePerDay: ethers.parseUnits(0.80, 6),
termDays: 30,
diemMin: ethers.parseUnits(1000, 6),
diemMax: ethers.parseUnits(4000, 6),
apiKey: vn-scoped-...,
});
关键路径
| 路径 | 用途 |
|---|
| sdk/src/agent.ts | DiemAgent:getListings, rent, getKey, getMyRentals |
| sdk/src/provider.ts |
DiemProvider:createListing, settle, revokeAndRefund |
| backend/src/routes.ts | API路由:/api/listings, /api/keys, /api/key/:id |
| contracts/DiemMarketplace.sol | 链上托管,1%手续费 |
后端API
| 端点 | 方法 | 用途 |
|---|
| /api/listings | GET | 列出可租用的列表 |
| /api/listings/:id |
GET | 单个列表 |
| /api/keys | POST | 提供者存储API密钥 |
| /api/key/:rentalId | POST | 代理检索密钥(需要签名) |
| /api/balance | POST | 检查API密钥的DIEM余额 |
| /api/requests | POST | 创建租用请求 |
签名
所有需要认证的后端请求均使用EIP-191签名:
- - getKey:diem-marketplace:get-key:{rentalId}:{timestamp}
- storeKey:diem-marketplace:store-key:{listingId}:{timestamp}
- balance:请求体中的apiKey(无需签名)
合约(Base链)
- - 链:Base(8453)
- 主网:0xeeDa7657f2018b3b71B444b7ca2D8dE91b3B08f3
- USDC:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
安全与签名
- - 使用外部签名器或硬件钱包;切勿粘贴原始私钥。
- 在资金转账或凭证使用前要求用户明确确认。
- Venice API密钥必须限定范围(仅推理用途)、可撤销且仅用于托管的最小权限。
备注
- - Venice API密钥必须为仅推理用途(非管理员)
- 结算时扣除1%协议手续费