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

@opperai/ai-sdk-provider

v0.1.1

Published

Vercel AI SDK provider for Opper — run any model with a single API key

Downloads

491

Readme

@opperai/ai-sdk-provider

Vercel AI SDK provider for Opper — run any model through a single API key with built-in tracing and guardrails.

Installation

npm install @opperai/ai-sdk-provider ai

Quick start

import { opper } from '@opperai/ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: opper('openai/gpt-4o'),
  prompt: 'Hello!',
});

Set your API key via the OPPER_API_KEY environment variable, or pass it explicitly (see below).

Provider setup

import { createOpper } from '@opperai/ai-sdk-provider';

const opper = createOpper({
  apiKey: process.env.OPPER_API_KEY, // default: OPPER_API_KEY env var
  baseURL: 'https://api.opper.ai/v3/compat', // default
});

Models

Pass any Opper model string — the provider routes it to the right backend:

opper('openai/gpt-4o')
opper('anthropic/claude-sonnet-4-5')
opper('google/gemini-2.0-flash')
opper('default') // your configured default model

Streaming

import { streamText } from 'ai';

const { textStream } = streamText({
  model: opper('openai/gpt-4o'),
  prompt: 'Write a haiku about TypeScript.',
});

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

Tool calling

import { generateText, tool } from 'ai';
import { z } from 'zod';

const { toolCalls } = await generateText({
  model: opper('openai/gpt-4o'),
  tools: {
    getWeather: tool({
      description: 'Get current weather',
      parameters: z.object({ location: z.string() }),
      execute: async ({ location }) => ({ temperature: 22, unit: 'celsius' }),
    }),
  },
  prompt: "What's the weather in Stockholm?",
});

Embeddings

import { embed } from 'ai';

const { embedding } = await embed({
  model: opper.embeddingModel('openai/text-embedding-3-small'),
  value: 'Hello world',
});

Opper-specific options

Pass per-call Opper options via providerOptions.opper:

Session tracing with opperSpan

opperSpan creates an Opper span that groups all model calls in a session under the same trace. Pass it to wrapLanguageModel once and every call is automatically linked — no need to pass span IDs manually.

import { wrapLanguageModel, generateText, streamText } from 'ai';
import { opper, opperSpan } from '@opperai/ai-sdk-provider';

const { middleware, handle } = opperSpan({ name: 'my-chat-session' });

const model = wrapLanguageModel({
  model: opper('openai/gpt-4o'),
  middleware,
});

// Every call is linked to the same session span in Opper
const { text } = await generateText({ model, prompt: 'Hello!' });
await generateText({ model, prompt: 'Follow-up question...' });

// Close the span when the session ends (e.g. conversation over, request done)
await handle.end(text);

The span is created lazily on the first model call. handle.end() is a no-op if no calls were made. The span name defaults to 'aisdk-session' if not specified.

You can also read the span ID if you need it elsewhere:

const spanId = await handle.spanId; // e.g. 'span_032ZZczKjASAvGMnE5sdnd'

Per-call tracing

To attach a name or parent span to individual calls without a session wrapper:

await generateText({
  model: opper('openai/gpt-4o'),
  prompt: 'Summarise this document...',
  providerOptions: {
    opper: {
      name: 'document-summariser',
      parentSpanId: 'uuid-of-parent-span',
    },
  },
});

Guardrails

Apply input/output safety checks:

await generateText({
  model: opper('openai/gpt-4o'),
  prompt: userMessage,
  providerOptions: {
    opper: {
      guardInput: 'pii,secrets',   // comma-separated checks
      guardOutput: 'toxicity',
      guardAction: 'block',        // 'flag' | 'block' | 'redact' (default: 'flag')
    },
  },
});

For TypeScript autocomplete on these options, import the OpperCallOptions type:

import type { OpperCallOptions } from '@opperai/ai-sdk-provider';

const opperOptions: OpperCallOptions = {
  name: 'my-function',
  guardInput: 'pii',
};

Requirements

License

MIT