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

ai-sdk-provider-env

v0.5.1

Published

A dynamic, environment-variable-driven provider for Vercel AI SDK — resolves provider configurations from env var conventions at runtime

Readme

For AI agent (llms.txt) | 中文

ai-sdk-provider-env

Environment-variable-driven provider for Vercel AI SDK. Switch AI providers and models without code changes.

npm version license

Quick Start

pnpm add ai-sdk-provider-env
# .env
OPENAI_API_KEY=sk-xxx
import { generateText } from 'ai'
import { envProvider } from 'ai-sdk-provider-env'

const provider = envProvider()

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

The config set name openai auto-matches the built-in preset — only an API key is needed.

Any valid env var prefix becomes a config set. Two endpoints, zero code changes:

# .env
FAST_BASE_URL=https://fast-api.example.com/v1
FAST_API_KEY=key-fast

SMART_BASE_URL=https://smart-api.example.com/v1
SMART_API_KEY=key-smart
provider.languageModel('fast/llama-3-8b')
provider.languageModel('smart/gpt-4o')

Environment Variables

Model ID format: {configSet}/{modelId}. The config set maps to an uppercased env var prefix.

Config set names must match [A-Za-z_][A-Za-z0-9_-]* — ASCII letters, digits, underscores, and hyphens. Hyphens are automatically normalized to underscores for env var lookup:

# Config set "my-api" → reads MY_API_* env vars
MY_API_BASE_URL=https://api.example.com/v1
MY_API_API_KEY=sk-xxx
provider.languageModel('my-api/some-model')  // reads MY_API_* env vars
provider.languageModel('my_api/some-model')  // same env vars

For config set names outside these rules (e.g. Unicode, dots), use the configs option instead.

| Variable | Required | Description | |---|---|---| | {PREFIX}_API_KEY | Yes | API key | | {PREFIX}_BASE_URL | Unless preset matches | API base URL | | {PREFIX}_PRESET | No | Built-in preset name (e.g. openai) | | {PREFIX}_COMPATIBLE | No | openai · anthropic · gemini · openai-compatible (default) | | {PREFIX}_HEADERS | No | Custom HTTP headers (JSON) | | {PREFIX}_NATIVE_ROUTING | No | Enable/disable native model routing (true/false) |

When _PRESET is set or auto-detected, _BASE_URL and _COMPATIBLE fall back to preset defaults.

Compatibility modes

| Value | SDK | Fallback | |---|---|---| | openai | @ai-sdk/openai | @ai-sdk/openai-compatible if not installed | | anthropic | @ai-sdk/anthropic | None | | gemini | @ai-sdk/google | None | | openai-compatible | @ai-sdk/openai-compatible (default) | — |

Install provider SDKs as needed: pnpm add @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google

Built-in Presets

When the config set name matches a preset, it auto-applies — only _API_KEY is needed:

DEEPSEEK_API_KEY=sk-xxx          # config set "deepseek" matches the preset
provider.languageModel('deepseek/deepseek-chat')   // just works

| Preset | Base URL | Compatible | |---|---|---| | openai | https://api.openai.com/v1 | openai | | anthropic | https://api.anthropic.com | anthropic | | google | https://generativelanguage.googleapis.com/v1beta | gemini | | opencode-zen | https://opencode.ai/zen/v1 | openai-compatible (nativeRouting enabled) | | opencode-go | https://opencode.ai/zen/go/v1 | openai-compatible | | deepseek | https://api.deepseek.com | openai-compatible | | groq | https://api.groq.com/openai/v1 | openai-compatible | | together | https://api.together.xyz/v1 | openai-compatible | | fireworks | https://api.fireworks.ai/inference/v1 | openai-compatible | | mistral | https://api.mistral.ai/v1 | openai-compatible | | moonshot | https://api.moonshot.ai/v1 | openai-compatible | | moonshot-china | https://api.moonshot.cn/v1 | openai-compatible | | perplexity | https://api.perplexity.ai | openai-compatible | | openrouter | https://openrouter.ai/api/v1 | openai-compatible | | siliconflow | https://api.siliconflow.com/v1 | openai-compatible | | siliconflow-china | https://api.siliconflow.cn/v1 | openai-compatible | | xai | https://api.x.ai/v1 | openai-compatible | | zai | https://api.z.ai/api/paas/v4 | openai-compatible | | zhipu | https://open.bigmodel.cn/api/paas/v4 | openai-compatible |

To disable auto-detection: envProvider({ presetAutoDetect: false }). See Advanced Usage for details.

Native Routing

When a config set uses a gateway that exposes multiple AI providers (like opencode-zen), nativeRouting auto-detects the model family from the model ID prefix and routes it to the appropriate native SDK:

  • claude-*@ai-sdk/anthropic
  • gemini-*@ai-sdk/google
  • gpt-*@ai-sdk/openai
  • Other models fall back to the config set's default compatible mode
# opencode-zen preset has nativeRouting enabled — just set API key
OPENCODE_ZEN_API_KEY=zen-xxx
// Routes to native Anthropic SDK automatically
provider.languageModel('opencode-zen/claude-sonnet-4-20250514')

// Routes to native Google SDK automatically
provider.languageModel('opencode-zen/gemini-3-flash')

// Other models use openai-compatible
provider.languageModel('opencode-zen/minimax-m2.5')

To disable: OPENCODE_ZEN_NATIVE_ROUTING=false

Known limitation: o1-*, o3-*, chatgpt-* models are not automatically routed. Use {PREFIX}_COMPATIBLE=openai explicitly for these.

Documentation

  • API ReferenceenvProvider() options, types, model ID format
  • Advanced Usage — Code-based configs, custom fetch/headers, custom separator, provider registry
  • Bundler Usage — For bun build, vite build, and other bundlers