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/ai-sdk-provider

v0.1.1

Published

Vercel AI SDK provider for Relai LLM gateway

Readme

@llmrelai/ai-sdk-provider

Vercel AI SDK provider for the Relai LLM gateway.

Installation

npm install @llmrelai/ai-sdk-provider ai

Quick Start

import { createRelai } from "@llmrelai/ai-sdk-provider";
import { generateText, streamText } from "ai";

const relai = createRelai({ apiKey: process.env.RELAI_KEY! });

// Generate text
const { text } = await generateText({
  model: relai("reasoning/cheapest"),
  prompt: "What is the capital of France?",
});

// Stream text
const result = await streamText({
  model: relai("reasoning/cheapest"),
  prompt: "Write a haiku about coding.",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Multi-Region Support

Regional Keys (Purist)

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

// Use region-specific provider
const euModel = relai.forRegion("eu")("reasoning/cheapest");
const usModel = relai.forRegion("us")("reasoning/cheapest");

await generateText({ model: euModel, prompt: "Hello from EU!" });
await generateText({ model: usModel, prompt: "Hello from US!" });

Global Keys (Pragmatist)

const relai = createRelai({
  apiKey: process.env.RELAI_GLOBAL_KEY!, // relai_sk_gbl_eu_live_...
});

// Default routing (anycast)
await generateText({
  model: relai("reasoning/cheapest"),
  prompt: "Hello!",
});

// Route to specific region
await generateText({
  model: relai.forRegion("eu")("reasoning/cheapest"),
  prompt: "Hello from EU!",
});

Access Native Relai APIs

The provider exposes the underlying @llmrelai/sdk client for native API access:

const relai = createRelai({ apiKey: process.env.RELAI_KEY! });

// Check balance
const balance = await relai.client.balance.get();

// Manage users
await relai.client.users.create({
  external_id: "user_123",
  monthly_quota_dollars: 10.0,
});

// Get usage
const usage = await relai.client.usage.list({
  from: "2024-01-01T00:00:00Z",
  to: "2024-01-31T23:59:59Z",
});

Error Handling

import { isRelaiError, mapRelaiError, RelaiAPIError } from "@llmrelai/ai-sdk-provider";
import { generateText } from "ai";

try {
  await generateText({
    model: relai("reasoning/cheapest"),
    prompt: "...",
  });
} catch (error) {
  if (error instanceof RelaiAPIError) {
    console.error(`Relai error: ${error.message}`);
    console.error(`Code: ${error.relaiCode}`);
    console.error(`Region: ${error.region}`);
    console.error(`Retryable: ${error.isRetryable}`);
  }
}

Framework Integration

The Vercel AI SDK works with all major frameworks:

Next.js

// app/api/chat/route.ts
import { createRelai } from "@llmrelai/ai-sdk-provider";
import { streamText } from "ai";

const relai = createRelai({ apiKey: process.env.RELAI_KEY! });

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: relai("reasoning/cheapest"),
    messages,
  });

  return result.toDataStreamResponse();
}

React (useChat)

"use client";
import { useChat } from "ai/react";

export function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();

  return (
    <div>
      {messages.map((m) => (
        <div key={m.id}>{m.content}</div>
      ))}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
        <button type="submit">Send</button>
      </form>
    </div>
  );
}

API Reference

createRelai(options)

Creates a Relai provider instance.

| Option | Type | Description | |--------|------|-------------| | apiKey | string | Single API key | | keys | { eu?: string, us?: string } | Multi-region keys | | defaultRegion | "eu" \| "us" | Default region | | name | string | Provider name (default: "relai") |

Provider Methods

| Method | Description | |--------|-------------| | provider(modelId) | Returns a language model for the given ID | | provider.forRegion(region) | Returns a region-specific provider function | | provider.client | Access to the underlying @llmrelai/sdk client |

License

MIT