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

@ai42/sdk

v0.1.4

Published

<div align="center">

Readme

AI42 SDK

AI42 Logo

True Pay-per-use AI API with automatic crypto payments via HTTP 402

npm version License: MIT TypeScript

DocumentationInstallationQuick StartExamples


Overview

AI42 SDK provides seamless access to multiple AI models with automatic cryptocurrency payments using the X402 protocol. Pay only for what you use - no subscriptions, no API keys, just connect your wallet or use a private key.

✨ Features

  • 🤖 Multiple AI Models: Access Llama, GPT, and Gemini models
  • 💰 Pay-per-use: Automatic payments via Solana/Base using HTTP 402
  • 🌐 Universal: Works in browser (Phantom wallet) and Node.js (private key)
  • Priority Options: Choose between fast, quality, or cheap responses
  • 🔒 Type-safe: Full TypeScript support with comprehensive types
  • 🎯 Simple API: Intuitive methods for common use cases

🎯 Supported Models

| Model | Provider | Identifier | | ---------------- | -------- | ------------------------- | | Llama 3.3 70B | Groq | llama-3.3-70b-versatile | | GPT OSS 120B | OpenAI | openai/gpt-oss-120b | | Gemini 2.5 Flash | Google | gemini-2.5-flash | | Gemini 2.5 Pro | Google | gemini-2.5-pro |


Installation

npm install @ai42/sdk

Core Peer Dependencies

For Browser:

npm install x402-solana

For Node.js:

npm install x402-fetch dotenv

Quick Start

Browser Usage (Phantom Wallet)

import { AI42Client } from "@ai42/sdk";
import { connectWallet } from "@ai42/sdk/wallet";

// Connect wallet
const wallet = await connectWallet();

// Create client
const client = AI42Client.fromWallet(
  {
    apiUrl: "https://ai42.onrender.com",
    network: "solana-devnet",
  },
  wallet
);

// Send a message
const response = await client.chat({
  message: "Explain quantum computing",
  model: "llama-3.3-70b-versatile",
});

console.log(response.content);
console.log(`Cost: $${response.cost}`);

Node.js Usage (Signer/Private Key)

import { AI42Client } from "@ai42/sdk";
import { config } from "dotenv";

config();

// Create client with signer/private key
const signer = await createSigner(config.network, privateKey);

const client = await AI42Client.fromSigner(
  {
    apiUrl: "https://ai42.onrender.com",
    network: "solana-devnet",
  },
  signer
);

// Send a message
const response = await client.chat({
  message: "Write a haiku about AI",
  priority: "fast",
});

console.log(response.content);

Documentation

Client Creation

Browser with Wallet

AI42Client.fromWallet(config: AI42Config, wallet: Wallet): AI42Client

Node.js with Private Key

AI42Client.fromSigner(config: AI42Config, signer: Signer): Promise<AI42Client>

Configuration

interface AI42Config {
  apiUrl: string;
  network?: "solana-mainnet" | "solana-devnet" | "base-sepolia";
}

Chat Methods

Basic Chat

client.chat(options: AI42ChatOptions): Promise<ChatResponse>
interface AI42ChatOptions {
  message: string;
  model?: ModelIdentifier;
  priority?: "fast" | "quality" | "cheap";
}

Chat with Specific Model

client.chatWithModel(
  message: string,
  model: ModelIdentifier
): Promise<ChatResponse>

Chat with Priority

client.chatWithPriority(
  message: string,
  priority: 'fast' | 'quality' | 'cheap'
): Promise<ChatResponse>

Response Format

interface ChatResponse {
  content: string; // AI response text
  model: ModelIdentifier; // Model used
  tokens: {
    prompt: number; // Input tokens
    completion: number; // Output tokens
    total: number; // Total tokens
  };
  cost: number; // Cost in USD
  cached: boolean; // Whether response was cached
  requestId: string; // Unique request ID
  timestamp: number; // Unix timestamp
}

Examples

Example 1: Simple Question

const response = await client.chat({
  message: "What is the capital of France?",
});

console.log(response.content); // "Paris is the capital of France..."

Example 2: Code Generation

const response = await client.chatWithModel(
  "Write a function to calculate fibonacci numbers",
  "llama-3.3-70b-versatile"
);

console.log(response.content);

Example 3: Fast Response

const response = await client.chatWithPriority(
  "Summarize the news today",
  "fast"
);

console.log(response.content);
console.log(`Responded in ${response.tokens.total} tokens`);

Example 4: Quality over Speed

const response = await client.chat({
  message: "Explain the theory of relativity in detail",
  priority: "quality",
  model: "gemini-2.5-pro",
});

console.log(response.content);

Example 5: Error Handling

import { AI42Error } from "@ai42/sdk";

try {
  const response = await client.chat({
    message: "Hello AI",
  });
  console.log(response.content);
} catch (error) {
  if (error instanceof AI42Error) {
    console.error(`Error [${error.code}]: ${error.message}`);
    if (error.code === "PAYMENT_FAILED") {
      console.error("Check your wallet balance");
    }
  }
}

Example 6: Browser Integration

<!DOCTYPE html>
<html>
  <head>
    <title>AI42 Chat</title>
  </head>
  <body>
    <button id="connect">Connect Wallet</button>
    <input id="message" placeholder="Ask me anything..." />
    <button id="send">Send</button>
    <div id="response"></div>

    <script type="module">
      import { AI42Client } from "@ai42/sdk";
      import { connectWallet } from "@ai42/sdk/wallet";

      let client;

      document.getElementById("connect").onclick = async () => {
        const wallet = await connectWallet();
        client = AI42Client.fromWallet(
          { apiUrl: "https://ai42.onrender.com" },
          wallet
        );
        alert("Wallet connected!");
      };

      document.getElementById("send").onclick = async () => {
        const message = document.getElementById("message").value;
        const response = await client.chat({ message });
        document.getElementById("response").innerText = response.content;
      };
    </script>
  </body>
</html>

Environment Setup

Node.js .env File

PRIVATE_KEY=your_solana_or_base_private_key_here
API_URL=https://api.ai42.dev
NETWORK=solana-devnet

Getting a Private Key

Solana:

solana-keygen new --outfile ~/.config/solana/id.json
solana-keygen pubkey ~/.config/solana/id.json

Base (Ethereum): Use MetaMask or any Ethereum wallet to export your private key.

⚠️ Never commit private keys to version control!


Error Handling

The SDK throws AI42Error with specific error codes:

| Error Code | Description | | ------------------ | --------------------------------------- | | INVALID_REQUEST | Malformed request or invalid parameters | | PAYMENT_REQUIRED | Payment needed to proceed | | PAYMENT_FAILED | Payment transaction failed | | MODEL_ERROR | AI model returned an error | | RATE_LIMIT | Too many requests | | INTERNAL_ERROR | Unexpected error occurred |

try {
  await client.chat({ message: "Hello" });
} catch (error) {
  if (error instanceof AI42Error) {
    switch (error.code) {
      case "PAYMENT_FAILED":
        console.error("Payment issue:", error.message);
        break;
      case "MODEL_ERROR":
        console.error("AI model error:", error.message);
        break;
      default:
        console.error("Error:", error.message);
    }
  }
}

Priority Guidelines

| Priority | Use Case | Speed | Cost | Quality | | --------- | ----------------------------------- | ------ | ---- | ------- | | fast | Quick responses, simple queries | ⚡⚡⚡ | $ | ⭐⭐ | | quality | Complex reasoning, detailed answers | ⚡ | $$$ | ⭐⭐⭐ | | cheap | Budget-conscious, simple tasks | ⚡⚡ | $ | ⭐⭐ |


Network Support

| Network | Chain | Mainnet | Testnet | | ------- | ----------- | ---------------- | --------------- | | Solana | Solana | solana-mainnet | solana-devnet | | Base | Ethereum L2 | base-mainnet | base-sepolia |


TypeScript Support

Full TypeScript definitions included:

import type {
  AI42Config,
  AI42ChatOptions,
  ChatResponse,
  ModelIdentifier,
  Priority,
  PaymentInfo,
  AI42Error,
} from "@ai42/sdk";

FAQ

Q: Do I need an API key?

A: No! AI42 uses the X402 protocol for automatic payments. Just connect your wallet or provide a private key.

Q: What cryptocurrencies are supported?

A: Currently Solana (SOL/USDC) and Base (ETH/USDC).

Q: How much does it cost?

A: Pay-per-use pricing based on tokens consumed. Prices vary by model and priority. Check response.cost for exact costs.

Q: Can I use this in production?

A: Yes! Use solana-mainnet or base-mainnet for production. Start with testnets for development.

Q: Is my private key safe?

A: Your private key never leaves your machine. It's only used to sign payment transactions locally.

Q: What if a payment fails?

A: The SDK will throw a PAYMENT_FAILED error. Check your wallet balance and network connectivity.


Contributing

Contributions welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Feat: Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see LICENSE file for details


Support


Acknowledgments

Built with:


Made with ❤️ by the AI42 Team

WebsiteDocumentationGitHub