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

@tokenosdeai/a2e-agent-sdk

v1.0.0

Published

Wallet-rooted AI agent SDK for TokenOS DeAI. Register an agent, fund an x402 session on Solana, call OpenAI-compatible inference with atomic per-call cap enforcement.

Readme

@tokenosdeai/a2e-agent-sdk

Wallet-rooted AI agent SDK for TokenOS DeAI. Register an agent, fund an x402 session on Solana, call OpenAI-compatible inference with atomic per-call cap enforcement.

Install

npm install @tokenosdeai/a2e-agent-sdk
# or
pnpm add @tokenosdeai/a2e-agent-sdk

Requires Node 18+ (uses native fetch).

Quickstart

import nacl from 'tweetnacl'
import { A2EAgent } from '@tokenosdeai/a2e-agent-sdk'

// 1. Generate (or load) a Solana ed25519 keypair.
const keypair = nacl.sign.keyPair()

// 2. Register. One-time per wallet; idempotent (409 on re-register).
const agent = await A2EAgent.register({ keypair, name: 'my-trading-bot' })
console.log('Save this api key:', agent.apiKey)
// agent.apiKey: 'a2e-agent-<48 hex>'

// 3. Open an x402-funded session. signPayment is your hook — wire it
//    to a Solana wallet adapter, @x402/svm-client, or any signer that
//    can produce the base64-encoded PaymentPayload for a TransferChecked.
const session = await agent.openSession({
  signPayment: async ({ requirements, amountUsd }) => {
    // Your code: build the Solana SPL TransferChecked tx from the
    // requirements, sign it with the agent's wallet, base64-encode
    // the x402 PaymentPayload, return.
    return await signX402TransferChecked(keypair, requirements)
  },
})
// session.info: { id, capUsd, spentUsd, status, fundingTxHash, ... }

// 4. Call inference. The meter atomically debits session.spentUsd
//    against capUsd; cap exhausted -> 402 + session CLOSED.
const result = await session.chat({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'What is the capital of Japan?' }],
})

Why a signPayment callback?

x402 payments are Solana SPL TransferChecked transactions. Signing them needs the full Solana toolchain (@solana/web3.js, @solana/spl-token, an RPC connection). The SDK doesn't pull those in — instead you provide a small callback that does the signing with whatever wallet infrastructure you already have:

  • A Phantom / Solflare wallet adapter
  • @x402/svm-client from the x402 reference implementation
  • A serverless KMS that holds the agent's private key
  • An anchor Program signer if you're orchestrating from a Solana program

The keypair the SDK DOES use (passed to register) is only for one thing: signing the registration nonce. That's a single nacl.sign.detached(message, keypair.secretKey) call — pure tweetnacl, no Solana RPC needed — so the SDK handles it.

API

A2EAgent.register({ keypair, name?, apiBase? })

One-shot: request a challenge, sign with the keypair, submit. Returns an A2EAgent instance.

A2EAgent.fromApiKey({ apiKey, walletAddress, agentId, apiBase? })

Construct from a previously-saved api key. Use this in long-running processes to skip re-registration.

agent.openSession({ signPayment, preferredAmountAtomic? })

Opens an x402-funded session. The SDK handles the 402-challenge dance (probe → decode requirements → call your signPayment → retry with PAYMENT-SIGNATURE).

preferredAmountAtomic picks which tier to fund. Default tiers on TokenOS: 1000000 ($1), 5000000 ($5), 10000000 ($10), 25000000 ($25). Omit to use the smallest tier (accepts[0]).

session.chat(args) / session.embeddings(args)

OpenAI-compatible inference, billed to the session.

session.close() / session.refresh()

Self-close (forfeits unused cap) or re-fetch current state.

agent.revoke()

Revoke this agent's api key + cascade-close all open sessions. Permanent.

decodePaymentRequired(headerValue)

Exported utility: decode the base64-encoded payment-required header into the structured x402 PaymentRequirements. Useful if you want to show the user a tier picker before signing.

Errors

All thrown errors are A2EAgentError instances with .code and .status (HTTP status when applicable). Common codes:

  • nonce_expired — challenge expired (>5 min between challenge and register)
  • nonce_wallet_mismatch — signed challenge for wallet A, submitting as wallet B
  • signature_signature_mismatch — signature didn't verify
  • wallet_already_registered — 409, same wallet registered before
  • agent_rate_limited — 429, per-agent RPM limit hit (default 100/min)
  • session_over_cap / session_closed / session_not_found — meter-side rejections (402)

Spec

The full agent-auth specification lives at docs/AGENT_AUTH.md on the main repo. This SDK is a thin client over the protocol there — no platform-specific behavior baked in beyond URL paths.

License

MIT.