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

apinow-sdk

v0.12.6

Published

ApiNow SDK · The endpoint vending machine

Readme

ApiNow SDK

A TypeScript SDK for interacting with ApiNow endpoints, supporting Ethereum and Base chains. This SDK simplifies payments by automatically handling 402 Payment Required responses, including on-the-fly token swaps.

Features

  • Automatic x402 Payments: Intercepts 402 responses to handle payment flows automatically.
  • On-the-fly Token Swaps: If you don't have the required payment token, the SDK can swap a common asset (like ETH, WETH, or USDC) to make the payment, powered by 0x.
  • Flexible Pricing: Supports endpoints that require a fixed token amount or a USD equivalent.
  • Endpoint Discovery: Includes a search method to find endpoints semantically.
  • Configurable Payment: Prioritize which tokens you prefer to pay with.
  • Multi-chain support: Works with Ethereum and Base.
  • Node.js Environment: Designed to work in a Node.js environment.

Installation

npm install apinow-sdk
# or
yarn add apinow-sdk

Quick Example

The primary way to use the SDK is with the execute method. It's a single call that handles all the complexity of API payments for you.

import apiNow from 'apinow-sdk';

// Your private key, securely stored (e.g., in an environment variable).
const YOUR_WALLET_PRIVATE_KEY = process.env.USER_PRIVATE_KEY; 

async function main() {
  try {
    // The `execute` method handles everything automatically.
    // If the API requires a payment (402), the SDK will find the best
    // token you hold, swap if necessary, send the payment, and retry
    // the original request with proof of payment.
    const response = await apiNow.execute(
      'https://apinow.fun/api/endpoints/apinowfun/translate-TRANSLATE',
      YOUR_WALLET_PRIVATE_KEY,
      { // Optional: request options
        method: 'POST',
        data: { 
            text: 'Hello world',
            selectedLanguage: 'es'
        }
      }
    );

    console.log('API Response:', response);
  } catch (error) {
    console.error('Operation failed:', error);
  }
}

main();

For a complete, runnable example, see example.js.

How It Works: Automatic Payments

When you call execute, the SDK makes a request to the endpoint. If the server responds with a 402 Payment Required status, the SDK automatically performs the following steps:

  1. Parses Payment Options: The 402 response contains a list of accepted payment options.
  2. Checks Balances: It checks your wallet balance for each of the accepted payment tokens.
  3. Prioritizes Payment: It attempts to pay using your tokens in a preferred order (default: ['USDC', 'WETH', 'ETH']).
  4. Swaps if Needed: If you don't have any of the required tokens, the SDK will try to swap one of your preferred assets for the required one.
  5. Pays and Retries: Once the payment transaction is sent, the SDK automatically retries the original API request, now with proof of payment.

API Reference

execute(endpoint, privateKey, opts?, paymentConfig?)

Handles a request and its potential payment in a single, automatic call. This is the recommended method.

search(params, privateKey, paymentConfig?)

Performs a semantic search for endpoints.

info(endpointUrl)

Retrieves public, detailed information about an endpoint.

Default RPC URLs

  • Ethereum: https://rpc.ankr.com/eth
  • Base: https://mainnet.base.org

Error Handling

The SDK throws descriptive errors for:

  • Invalid endpoint URLs or configurations.
  • RPC communication errors.
  • Transaction signing or sending failures.
  • Insufficient funds or failure to find a valid swap.
  • Failures during API response fetching.

Wrap calls in try...catch blocks for robust error handling.

Compatibility

This SDK uses node-fetch, making it compatible with:

  • Node.js (v18+ recommended)

It is NOT directly compatible with browsers or edge environments that do not provide a Node.js-compatible fetch API.

License

MIT