How it Works for Agents

Integrate with Parley Protocol over plain HTTP — no SDK required.

Overview

Any AI agent can interact with Parley Protocol over HTTP. The flow is linear: browse articles → hit the 402 paywall → optionally negotiate → pay via x402 → receive full content.

Consumer Agent
     │
     ├─ 1. GET /api/content              → article list
     │
     ├─ 2. GET /api/content/:id          → HTTP 402 + payment requirements
     │
     ├─ 3. POST /api/agent/negotiate     → negotiate price (optional)
     │        └─ checks ERC-8004 reputation on Base Sepolia
     │        └─ Claude AI returns: accept / counter / reject
     │
     ├─ 4. Sign EIP-3009 authorization
     │        └─ ExactEvmSchemeV1 (EIP-712 typed data)
     │
     └─ 5. GET /api/content/:id          → HTTP 200 + full content + txHash
              X-PAYMENT: <base64url>

Step 1 — Browse Articles

GET /api/content

Response:
[
  {
    "id": "abc123",
    "title": "The Future of AI Micropayments",
    "summary": "...",
    "basePrice": 0.002,
    "publisher": { "walletAddress": "0x..." }
  }
]

Step 2 — Hit the x402 Paywall

GET /api/content/:id

HTTP 402 Payment Required
{
  "x402Version": 1,
  "accepts": [{
    "scheme": "exact",
    "network": "base-sepolia",
    "maxAmountRequired": "2000",   // micro-USDC (2000 = $0.002)
    "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
    "payTo": "0xPublisherWallet...",
    "description": "Access: The Future of AI Micropayments",
    "maxTimeoutSeconds": 300,
    "extra": { "name": "USDC", "version": "2" }
  }]
}

Note

The extra.name and extra.version are the EIP-712 domain parameters required by ExactEvmSchemeV1 to produce a valid TransferWithAuthorization signature.

Step 3 — Negotiate Price

Negotiation is optional but allows agents to get discounts based on on-chain reputation.

POST /api/agent/negotiate
Content-Type: application/json

{
  "articleId": "abc123",
  "consumerAddress": "0xYourAgentWallet",
  "offer": 0.001,
  "sessionId": null   // null for first round, use returned sessionId for follow-ups
}

Response:
{
  "decision": "counter",       // "accept" | "counter" | "reject"
  "price": 0.0018,
  "counterOffer": 0.0018,
  "reasoning": "Reputation score 50/100, no discount applied. Counter at $0.0018.",
  "sessionId": "sess_abc...",
  "agreed": false
}

Reputation-based Pricing

ERC-8004 ScoreEffect
≥ 8020% discount applied
≥ 6010% discount applied
40 – 59No adjustment
< 4010% premium applied

Step 4 — Pay via x402

Use @x402/fetch with ExactEvmSchemeV1 to auto-handle payment:

import { wrapFetchWithPaymentFromConfig } from '@x402/fetch';
import { ExactEvmSchemeV1 } from '@x402/evm/v1';
import { toClientEvmSigner } from '@x402/evm';
import { privateKeyToAccount } from 'viem/accounts';
import { createPublicClient, http } from 'viem';
import { baseSepolia } from 'viem/chains';

const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY');
const publicClient = createPublicClient({ chain: baseSepolia, transport: http() });
const signer = toClientEvmSigner(account, publicClient);
const schemeV1 = new ExactEvmSchemeV1(signer);

const x402Fetch = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: 'base-sepolia', client: schemeV1, x402Version: 1 }],
});

// This automatically handles the 402, signs, and retries
const res = await x402Fetch('https://parley-protocol.vercel.app/api/content/abc123', {
  headers: { 'x-agreed-price': '0.0018' },  // pass negotiated price
});
const { content, title, txHash } = await res.json();

Tip

Pass x-agreed-price header with the negotiated price so the 402 paywall uses the agreed amount rather than base price.

Running the Consumer Agent

# Connect to OpenServ cloud
npm run agent:consumer

# Local only (port 7379)
npm run agent:consumer:local
  • The agent runs as an HTTP server and exposes capabilities via OpenServ SDK
  • autonomous_content_purchase runs the full browse → negotiate → pay → read loop
  • All transactions are logged to agent_log.json with decision reasoning