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

zawedut-routing

v0.1.2

Published

Unified TypeScript SDK for comparing LLM providers, usage, latency, and cost

Readme

zawedut-routing

A unified TypeScript SDK for calling, comparing, and monitoring multiple LLM providers.

Switch between Gemini, OpenAI, Anthropic, and Typhoon using the same API while tracking token usage, latency, estimated cost, and request logs.

Features

  • One API for multiple LLM providers
  • Select providers using provider/model-id
  • System prompt support
  • Compare multiple models concurrently
  • Input, output, and total token usage
  • Request latency tracking
  • Estimated cost calculation
  • Custom model pricing
  • Success and error logs
  • Export logs as JSON
  • Full TypeScript support

Installation

npm install zawedut-routing

Quick start

Create a client and configure the providers you want to use:

import {
  createClient,
} from "zawedut-routing";

const ai = createClient({
  providers: {
    google: {
      apiKey:
        process.env.GOOGLE_API_KEY ?? "",
    },

    typhoon: {
      apiKey:
        process.env.TYPHOON_API_KEY ?? "",
    },
  },

  defaults: {
    model: "google/gemini-3.5-flash",
    system:
      "Answer clearly and concisely.",
  },
});

You only need to configure API keys once when creating the client.

Generate text

When a default model is configured:

const result = await ai.generate({
  prompt: "Explain RAG in simple terms.",
});

console.log(result.text);

Response:

{
  text: "RAG is...",
  model: "google/gemini-3.5-flash",

  usage: {
    inputTokens: 15,
    outputTokens: 80,
    totalTokens: 95,
  },

  timing: {
    totalMs: 950,
  },
}

You can override the default model for an individual request:

const result = await ai.generate({
  model:
    "typhoon/typhoon-v2.5-30b-a3b-instruct",

  system:
    "Always respond in Thai.",

  prompt:
    "อธิบายว่า LLM คืออะไร",
});

Compare models

Send the same prompt to multiple models concurrently:

const results = await ai.compare({
  models: [
    "google/gemini-3.5-flash",
    "typhoon/typhoon-v2.5-30b-a3b-instruct",
  ],

  system:
    "Respond in Thai using no more than three sentences.",

  prompt:
    "อธิบายว่า RAG คืออะไร",
});

Handle successful and failed results independently:

for (const item of results) {
  if (item.status === "success") {
    console.log(
      item.model,
      item.result.text,
    );
  } else {
    console.error(
      item.model,
      item.error.message,
    );
  }
}

A failed model does not cause the other comparisons to fail.

Request logs

Requests made through createClient() are logged automatically.

await ai.generate({
  prompt: "What is machine learning?",
});

const logs = ai.getLogs();

console.log(logs);

Each log contains:

{
  id: "req_...",
  model: "google/gemini-3.5-flash",
  status: "success",

  usage: {
    inputTokens: 10,
    outputTokens: 50,
    totalTokens: 60,
  },

  timing: {
    totalMs: 720,
  },

  cost: {
    inputCost: 0.000015,
    outputCost: 0.00045,
    totalCost: 0.000465,
    currency: "USD",
    pricingFound: true,
    estimated: true,
  },

  error: null,
  createdAt: "2026-09-15T00:00:00.000Z",
}

Clear logs held by the client:

ai.clearLogs();

Export logs

Export logs as formatted JSON:

const json = ai.exportLogs();

console.log(json);

Export compact JSON:

const json = ai.exportLogs({
  pretty: false,
});

exportLogs() returns a JSON string. It does not write files automatically, so it works in both Node.js and browser environments.

Custom pricing

Provider prices may change over time. You can override prices for any model:

const ai = createClient({
  providers: {
    typhoon: {
      apiKey:
        process.env.TYPHOON_API_KEY ?? "",
    },
  },

  pricing: {
    "typhoon/typhoon-v2.5-30b-a3b-instruct": {
      inputPerMillionTokens: 0.3,
      outputPerMillionTokens: 1.2,
      currency: "USD",
    },
  },
});

Custom prices are defined per one million tokens.

Custom pricing overrides the built-in pricing table only for that client instance.

Cost values are estimates based on the configured pricing. They may differ from the provider's final bill, free tier, discounts, caching, batch processing, or additional tool charges.

Standalone API

You can use generate() without creating a client:

import {
  generate,
} from "zawedut-routing";

const result = await generate(
  {
    model: "google/gemini-3.5-flash",
    system: "Respond in Thai.",
    prompt: "อธิบาย machine learning",
  },
  {
    google: {
      apiKey:
        process.env.GOOGLE_API_KEY ?? "",
    },
  },
);

console.log(result.text);

Standalone calls do not retain logs because no client instance owns the log store.

Calculate cost directly

import {
  calculateCost,
} from "zawedut-routing";

const cost = calculateCost({
  model: "my-provider/my-model",
  inputTokens: 1_000,
  outputTokens: 500,

  pricing: {
    "my-provider/my-model": {
      inputPerMillionTokens: 1,
      outputPerMillionTokens: 2,
      currency: "USD",
    },
  },
});

console.log(cost.totalCost);

Supported providers

| Provider | Model format | Configuration | |---|---|---| | Google Gemini | google/model-id | providers.google | | OpenAI | openai/model-id | providers.openai | | Anthropic Claude | anthropic/model-id | providers.anthropic | | Typhoon | typhoon/model-id | providers.typhoon |

Example model identifiers:

"google/gemini-3.5-flash"
"openai/model-id"
"anthropic/model-id"
"typhoon/typhoon-v2.5-30b-a3b-instruct"

Available model identifiers and access permissions depend on each provider.

Environment variables

Create a .env file in your application:

GOOGLE_API_KEY=
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
TYPHOON_API_KEY=

The library does not load .env automatically. Your application is responsible for loading environment variables.

For Node.js:

node --env-file=.env app.js

Or install dotenv in your application:

npm install dotenv

Then import it before reading environment variables:

import "dotenv/config";

Never commit real API keys to Git.

Error handling

generate() throws when a request fails:

try {
  const result = await ai.generate({
    prompt: "Hello",
  });

  console.log(result.text);
} catch (error) {
  console.error(error);
}

The failed request is also available through:

ai.getLogs();

compare() returns errors separately instead of throwing for every failed model.

Development

Install dependencies:

npm install

Build the package:

npm run build

Run tests:

npm test

Create a local npm package:

npm pack

Roadmap

  • [x] Multiple LLM providers
  • [x] Text generation
  • [x] System prompts
  • [x] Model comparison
  • [x] Token and latency tracking
  • [x] Cost estimation
  • [x] Request logging
  • [x] JSON export
  • [ ] Streaming responses
  • [ ] Retry and fallback
  • [ ] Smart model routing
  • [ ] Dashboard

Security

  • API keys are used only to configure provider clients.
  • API keys are not included in request logs.
  • Prompts and system prompts are not logged automatically.
  • Never expose provider API keys in client-side browser code.

License

ISC

Repository

https://github.com/zawedut/zawedut-routing