npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

x402pp-client

v0.1.0

Published

Client SDK for x402++ protocol - enables agents and applications to negotiate, transact, and verify with providers

Readme

x402pp-client

Client SDK for AI agents and applications to interact with x402++ providers.

Installation

npm install x402pp-client

What is This?

This package enables AI agents and applications to:

  • 🤝 Negotiate pricing with API providers
  • 💰 Create prepaid sessions
  • 🚀 Execute requests with automatic payment
  • ✅ Verify cryptographic receipts
  • 💵 Get refunds for unused balance

Quick Start

import { Connection, Keypair } from '@solana/web3.js';
import { X402Client } from 'x402pp-client';

// Initialize
const connection = new Connection('https://api.devnet.solana.com');
const wallet = Keypair.generate(); // Your agent's wallet
const client = new X402Client({ connection, wallet });

// 1. Create Intent (express your needs)
const intent = client.createIntent({
  capability: 'gpt-4-inference',
  maxPricePerRequest: 0.01,
  token: 'USDC',
  sla: { maxLatencyMs: 2000 }
});

// 2. Negotiate with provider
const offer = await client.negotiate('https://api.provider.com', intent);

// 3. Create prepaid session
const session = await client.createSession(offer);

// 4. Execute requests (payment automatic!)
const result = await client.executeRequest(session.sessionId, {
  prompt: 'Explain quantum computing'
});

console.log(result.data);     // API response
console.log(result.receipt);  // Cryptographic proof

// 5. Close session and get refund
await client.closeSession(session.sessionId);

Core Features

Automatic Negotiation

// Agent expresses maximum price
const intent = client.createIntent({
  maxPricePerRequest: 0.01,
  capability: 'ai-inference'
});

// Provider responds with actual price
const offer = await client.negotiate(endpoint, intent);

// Verify it's within budget
if (offer.pricePerRequest <= intent.maxPricePerRequest) {
  // Accept!
}

Prepaid Sessions

// Deposit once, make many requests
const session = await client.createSession(offer, {
  depositAmount: 1.0  // 1 USDC
});

// Make multiple requests without per-request transactions
await client.executeRequest(session.sessionId, request1);
await client.executeRequest(session.sessionId, request2);
await client.executeRequest(session.sessionId, request3);

Receipt Verification

const result = await client.executeRequest(sessionId, data);

// Every request gets a cryptographic receipt
console.log(result.receipt);
/*
{
  receiptId: "receipt_123",
  inputHash: "sha256(...)",    // Tamper-proof
  outputHash: "sha256(...)",   // Tamper-proof
  signature: "...",            // Provider's signature
  slaVerification: {
    met: true,
    metrics: { latency: { expected: 2000, actual: 1234 } }
  }
}
*/

SLA Enforcement

// Request SLA guarantees
const intent = client.createIntent({
  sla: {
    maxLatencyMs: 2000,      // Must respond within 2s
    minUptimePercent: 99.0,  // Must have 99% uptime
  }
});

// If provider breaches SLA, automatic refund!

API Reference

X402Client

Constructor

new X402Client({
  connection: Connection,    // Solana connection
  wallet: Keypair,          // Your wallet
  httpConfig?: {            // Optional HTTP settings
    timeout?: number,
    headers?: Record<string, string>
  }
})

Methods

createIntent(options)

client.createIntent({
  capability: string,
  maxPricePerRequest: number,
  token: 'SOL' | 'USDC' | 'USDT' | 'BONK',
  sla?: { maxLatencyMs?, minUptimePercent? },
  maxSessionBudget?: number,
  sessionDurationMs?: number,
  metadata?: Record<string, any>
})

negotiate(endpoint, intent)

const offer = await client.negotiate(
  'https://api.provider.com',
  intent
);

createSession(offer, options?)

const session = await client.createSession(offer, {
  depositAmount?: number,      // Custom deposit
  anchorOnChain?: boolean      // Store on Solana (optional)
});

executeRequest(sessionId, data)

const result = await client.executeRequest(
  sessionId,
  { prompt: 'Hello' }
);
// Returns: { data, receipt }

closeSession(sessionId)

const refund = await client.closeSession(sessionId);
// Returns: { refundAmount, txSignature }

getSession(sessionId)

const session = client.getSession(sessionId);

getActiveSessions()

const sessions = client.getActiveSessions();

Examples

AI Inference

const intent = client.createIntent({
  capability: 'gpt-4-inference',
  maxPricePerRequest: 0.01,
  token: 'USDC'
});

const offer = await client.negotiate('https://ai-api.com', intent);
const session = await client.createSession(offer);

const result = await client.executeRequest(session.sessionId, {
  prompt: 'Write a poem about Solana'
});

console.log(result.data.text);

Image Generation

const intent = client.createIntent({
  capability: 'image-generation',
  maxPricePerRequest: 0.05,
  token: 'USDC'
});

const offer = await client.negotiate('https://image-api.com', intent);
const session = await client.createSession(offer);

const result = await client.executeRequest(session.sessionId, {
  prompt: 'A futuristic city on Mars',
  style: 'photorealistic'
});

console.log(result.data.imageUrl);

Data Analysis

const intent = client.createIntent({
  capability: 'data-analysis',
  maxPricePerRequest: 0.001,
  token: 'USDC'
});

const offer = await client.negotiate('https://data-api.com', intent);
const session = await client.createSession(offer);

const result = await client.executeRequest(session.sessionId, {
  dataset: myData,
  operation: 'statistical-summary'
});

console.log(result.data.analysis);

Error Handling

try {
  const offer = await client.negotiate(endpoint, intent);
  const session = await client.createSession(offer);
  const result = await client.executeRequest(session.sessionId, data);
} catch (error) {
  if (error instanceof InvalidOfferError) {
    console.error('Offer validation failed');
  } else if (error instanceof SessionExpiredError) {
    console.error('Session expired, create new one');
  } else if (error instanceof InsufficientFundsError) {
    console.error('Session balance depleted');
  }
}

Related Packages

License

Apache 2.0