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

@llmrelai/sdk

v0.1.0

Published

TypeScript SDK for the Relai LLM gateway with multi-region support

Readme

@llmrelai/sdk

TypeScript SDK for the Relai LLM gateway with multi-region support.

Installation

npm install @llmrelai/sdk

Quick Start

import Relai from "@llmrelai/sdk";

// Single API key (simplest setup)
const relai = new Relai({ apiKey: process.env.RELAI_KEY! });

// Chat completion
const response = await relai.chat.completions.create({
  model: "reasoning/cheapest",
  messages: [{ role: "user", content: "Hello!" }],
});

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

Multi-Region Support

Regional Keys (Purist Approach)

For organizations requiring strict data residency, use separate accounts and keys per region:

const relai = new Relai({
  keys: {
    eu: process.env.RELAI_KEY_EU!,
    us: process.env.RELAI_KEY_US!,
  },
});

// Route EU customer requests to EU region
const euResponse = await relai.chat.completions.create(
  { model: "reasoning/cheapest", messages: [...] },
  { region: "eu" }
);

// Route US customer requests to US region
const usResponse = await relai.chat.completions.create(
  { model: "reasoning/cheapest", messages: [...] },
  { region: "us" }
);

Global Keys (Pragmatist Approach)

Use a single global key with per-call routing:

const relai = new Relai({
  apiKey: process.env.RELAI_GLOBAL_KEY!, // relai_sk_gbl_<region>_live_...
});

// Route to specific regions for dispatch
await relai.chat.completions.create(
  { model: "reasoning/cheapest", messages: [...] },
  { region: "eu" } // Request dispatched from EU gateway
);

Per-User Metering

Track usage per end-user:

// Create or update an end user
await relai.users.create({
  external_id: "user_123",
  monthly_quota_dollars: 10.0,
  daily_quota_dollars: 1.0,
  alert_threshold: 0.8,
});

// Include user ID in chat requests
const response = await relai.chat.completions.create({
  model: "reasoning/cheapest",
  messages: [...],
  user: "user_123",
});

// Check for quota warnings
if (response.relai?.warnings) {
  for (const warning of response.relai.warnings) {
    console.log(`${warning.code}: ${warning.message}`);
  }
}

Streaming

const stream = await relai.chat.completions.create(
  {
    model: "reasoning/cheapest",
    messages: [...],
    stream: true,
  },
  {
    onWarning: (warning) => {
      console.log(`Warning: ${warning.message}`);
    },
  }
);

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

Native Resources

Access Relai-specific APIs:

// Balance
const balance = await relai.balance.get();
console.log(`Credits: $${balance.credits_dollars}`);

// Usage statistics
const usage = await relai.usage.list({
  from: "2024-01-01T00:00:00Z",
  to: "2024-01-31T23:59:59Z",
});
console.log(`Total requests: ${usage.total_requests}`);

// API keys
const keys = await relai.keys.list();
const newKey = await relai.keys.create({
  name: "Production Key",
  scope: "regional",
});

// Organization settings
const settings = await relai.orgs.settings.get("my-org");
await relai.orgs.settings.update("my-org", {
  default_user_monthly_quota_dollars: 50.0,
});

// Billing ledger
const ledger = await relai.billing.ledger.list({ limit: 10 });

Error Handling

import {
  AuthenticationError,
  InsufficientBalanceError,
  EndUserQuotaExceededError,
  RateLimitError,
} from "@llmrelai/sdk";

try {
  await relai.chat.completions.create({...});
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error("Invalid API key");
  } else if (error instanceof InsufficientBalanceError) {
    console.error("Add credits to continue");
  } else if (error instanceof EndUserQuotaExceededError) {
    console.error(`User exceeded ${error.period} quota`);
  } else if (error instanceof RateLimitError) {
    console.error("Too many requests, retry later");
  }
}

API Reference

Constructor Options

| Option | Type | Description | |--------|------|-------------| | apiKey | string | Single API key | | keys | { eu?: string, us?: string } | Multi-region keys | | defaultRegion | "eu" \| "us" | Default region for requests | | baseURL | string | Override gateway URL | | timeout | number | Request timeout (ms) | | maxRetries | number | Max retry attempts |

Request Options

| Option | Type | Description | |--------|------|-------------| | region | "eu" \| "us" | Target region | | signal | AbortSignal | Cancellation signal | | headers | Record<string, string> | Additional headers |

License

MIT