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

@waterfall-finance/sdk

v0.4.0

Published

TypeScript SDK for x402 payments with OpenRouter

Downloads

11

Readme

Waterfall TypeScript SDK

TypeScript SDK for x402 payments with OpenRouter. This is a 1:1 port of the Python waterfall SDK.

Installation

npm install @waterfall-finance/sdk

Quick Start

import { WaterfallClient, createClient } from "@waterfall-finance/sdk";

// Option 1: Use the convenience function
const client = await createClient("wf_your_api_key");

// Option 2: Manual initialization
const client = new WaterfallClient({
  apiKey: "wf_your_api_key",
});
await client.configureWallet(); // Uses default wallet

// Make a chat completion request
const response = await client.chat.send({
  model: "openai/gpt-3.5-turbo",
  messages: [{ role: "user", content: "Hello!" }],
});

console.log(response.choices[0].message.content);

Features

  • Automatic x402 Payment Handling: The SDK automatically handles 402 Payment Required responses
  • OpenRouter Integration: Full access to OpenRouter's model catalog
  • Wallet Management: Create, list, and manage wallets
  • Streaming Support: Stream chat completions for real-time responses
  • TypeScript First: Full type definitions included

API Reference

WaterfallClient

The main client class for interacting with Waterfall.

const client = new WaterfallClient({
  apiKey: "wf_...", // Your Waterfall API key
  walletId: "...", // Optional: specific wallet ID
  backendUrl: "...", // Optional: custom backend URL
  proxyUrl: "...", // Optional: custom x402 proxy URL
});

Client Methods

configureWallet(options?)

Configure which wallet to use for payments.

// Use default wallet
await client.configureWallet();

// Use wallet by name
await client.configureWallet({ walletName: "My Wallet" });

// Use wallet by ID
await client.configureWallet({ walletId: "wallet_123" });

listWallets()

List all wallets associated with your API key.

const wallets = await client.listWallets();
console.log(wallets);
// [{ id: "...", name: "...", address: "0x...", network: "base-mainnet" }, ...]

createWallet(options)

Create a new wallet.

const wallet = await client.createWallet({
  name: "My New Wallet",
  useTestnet: false, // Optional: use Base Sepolia testnet
  teamId: "...", // Optional: team ID
});

Chat API

chat.send(options)

Send a chat completion request.

const response = await client.chat.send({
  model: "openai/gpt-4",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "What is the capital of France?" },
  ],
  temperature: 0.7,
  maxTokens: 1000,
});

chat.stream(options)

Stream a chat completion response.

const stream = await client.chat.stream({
  model: "openai/gpt-3.5-turbo",
  messages: [{ role: "user", content: "Tell me a story" }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Supported Models

Any model available on OpenRouter can be used:

  • openai/gpt-4
  • openai/gpt-3.5-turbo
  • anthropic/claude-3-opus
  • anthropic/claude-3-sonnet
  • google/gemini-pro
  • meta-llama/llama-3-70b-instruct
  • And many more...

How It Works

  1. Initial Request: Client sends request to the x402 proxy
  2. 402 Response: Proxy returns 402 Payment Required with payment details
  3. Payment Signing: SDK automatically signs the payment via Coinbase CDP wallet
  4. Retry: SDK retries the request with the payment signature
  5. Success: Proxy verifies signature and forwards to OpenRouter
Your Code
    ↓
WaterfallClient.chat.send()
    ↓
x402 Proxy
    ↓
[402 Payment Required]
    ↓
Waterfall Backend (signs payment)
    ↓
[Payment Signature]
    ↓
Retry with signature
    ↓
OpenRouter API
    ↓
AI Model Response

Configuration

Environment Variables

You can also set the API key via environment variable:

export WATERFALL_API_KEY=wf_your_api_key
const client = new WaterfallClient({
  apiKey: process.env.WATERFALL_API_KEY,
});

Custom URLs

Override default URLs if needed:

const client = new WaterfallClient({
  apiKey: "wf_...",
  backendUrl: "https://your-custom-backend.convex.site",
  proxyUrl: "https://your-custom-proxy.com",
});

Error Handling

try {
  const response = await client.chat.send({
    model: "openai/gpt-4",
    messages: [{ role: "user", content: "Hello!" }],
  });
} catch (error) {
  if (error.message.includes("Invalid or missing Waterfall API key")) {
    console.error("Check your API key");
  } else if (error.message.includes("Payment failed")) {
    console.error("Payment signing failed - check wallet balance");
  } else {
    console.error("Unexpected error:", error);
  }
}

License

MIT