Skip to content
Night Owls.dev
Jump to a page

@nightowlsdev/provider-vercel-gateway

Adapter/Model

Any model via the Vercel AI Gateway for Night Owls swarms, one key, all providers.

What it does

Exposes `vercelGatewayModels(opts?)`, a model factory for `defineSwarm({ modelFactory })`. It wraps `@ai-sdk/gateway`'s `createGateway`, mapping a `provider/model` id (e.g. `anthropic/claude-sonnet-4-6`) to an AI SDK `LanguageModelV3` routed through the Vercel AI Gateway, so a single key reaches every provider. Reads `AI_GATEWAY_API_KEY` by default; pass `{ apiKey }` to override. Ships a `nightOwlsPlugin` manifest for CLI scaffolding; it composes with the other `provider-*` adapters, so `createModelFactory` can route some agents through the gateway and others direct. Like the other model adapters it imports only its AI SDK provider (`@ai-sdk/gateway`), zero `@mastra/*`.

Install

pnpm add @nightowlsdev/provider-vercel-gateway

Key exports

  • vercelGatewayModels
  • nightOwlsPlugin

Usage

provider-vercel-gateway.ts
import { defineSwarm } from "@nightowlsdev/core";
import { vercelGatewayModels } from "@nightowlsdev/provider-vercel-gateway";

// One key, all providers via the Vercel AI Gateway. Reads AI_GATEWAY_API_KEY.
const swarm = defineSwarm({ agents, modelFactory: vercelGatewayModels() });

What it provides

A one-line model provider that reaches every vendor through one key AND is the only adapter in the family with a live model listing: vercelGatewayModels() returns a modelFactory mapping a provider/model id (anthropic/claude-sonnet-4-6, openai/gpt-4o, google/gemini-2.5-pro, …) to an AI SDK LanguageModelV3 routed through the Vercel AI Gateway (via @ai-sdk/gateway). It reads AI_GATEWAY_API_KEY (pass { apiKey } to override). vercelGatewayProvider() ships a genuine models() — backed by the gateway's getAvailableModels() — returning real ids, display names, and per-token pricing, plus a small static fallback catalog. One of six interchangeable provider-* packages that compose via createModelFactory.

When to use it

  • You want one key across every vendor WITH a live model listing and per-model pricing feeding the picker — the roster and prices reflect reality, not a hand-transcribed snapshot.
  • You want provider-qualified cost caps that actually enforce, because the live prices flow into the cost governor.
  • You want a central gateway (spend controls, failover, observability) in front of many models rather than N direct integrations.

When not to

  • You want to go direct to a single vendor — a native provider (provider-anthropic / provider-openai) means direct billing and no routing hop.
  • You want local / offline inference with no per-token cost — use provider-ollama.
  • You don't have (or don't want) a Vercel AI Gateway account — provider-openrouter gives similar breadth from one key without it.

Alternatives

  • provider-openrouterYou want the same one-key breadth but without a Vercel account — accepting an unpriced catalog and no live listing.
  • A native provider (anthropic / openai)You want one vendor directly, with a priced catalog and no gateway hop.
  • provider-ollamaYou want local, free, offline open models instead of a hosted gateway.

Strengths

  • The ONE adapter with a live models(): real ids, display names, and per-token pricing from getAvailableModels(), so the picker and cost caps track the gateway instead of a snapshot.
  • One key, every provider — switch vendor by editing a provider/model string in models.allow.
  • The live listing is called LAZILY (never at construction), so vercelGatewayProvider() stays network-free and the CLI's pure/no-network commands are untouched.
  • Engine-wall clean: a single dependency (@ai-sdk/gateway), zero @mastra and zero @nightowlsdev/core.

Limits & trade-offs

  • Requires a Vercel AI Gateway account and AI_GATEWAY_API_KEY.
  • An extra routing hop versus going direct to a native provider.
  • The gateway fronts non-chat models (embeddings, image, video, reranking) too; the adapter's models() filters to language models for a chat picker, but the raw gateway roster is broader.
  • provider/model ids contain a slash — like OpenRouter, never recover a provider by prefix-parsing a stored id; and the static fallback catalog is unpriced (the LIVE listing is the pricing authority), so offline, vercel-gateway:* expands to nothing unless you pass allowUnpriced.

How it works

vercelGatewayModels(opts) calls createGateway and returns a (modelId) => provider(modelId) factory. vercelGatewayProvider() returns the adapter-object form whose models() lazily calls provider.getAvailableModels(), keeps only language models, and maps each entry through gatewayEntryToModelInfo — converting the gateway's USD-per-token price strings into core's USD-per-million-token Price, and leaving metadata the gateway doesn't report (context window, tool calling, vision) unset (tri-state: unknown is not 'no'). A small static GATEWAY_CATALOG is the fallback merged with the live list, so the picker still offers something when the gateway is unreachable or unkeyed.

Examples

One key, every provider

modelId is a provider/model string; the key comes from AI_GATEWAY_API_KEY.

provider-vercel-gateway-example-1.ts
import { defineSwarm } from "@nightowlsdev/core";
import { vercelGatewayModels } from "@nightowlsdev/provider-vercel-gateway";

export default defineSwarm({
  modelFactory: vercelGatewayModels(),                 // reads AI_GATEWAY_API_KEY
  models: { allow: ["anthropic/claude-sonnet-4-6"] },
  agents,
});

A live-priced model picker

vercelGatewayProvider() is the only adapter whose models() returns a live listing with per-model pricing.

provider-vercel-gateway-example-2.ts
import { createModelProviderRegistry, resolveModelAllowList } from "@nightowlsdev/core";
import { vercelGatewayProvider } from "@nightowlsdev/provider-vercel-gateway";

const registry = createModelProviderRegistry({ providers: [vercelGatewayProvider()] });

// Live prices flow in, so vercel-gateway:* expands with real rates and cost caps enforce.
const resolved = await resolveModelAllowList(registry, ["vercel-gateway:*"]);

Doing the parts it doesn't support

  • Going direct to a single vendor (no gateway hop)Install that vendor's native provider-* package. If you want some agents direct and some via the gateway, compose both factories in createModelFactory.
  • Local / offline modelsThe gateway is a hosted router. For local, key-free inference use provider-ollama and route to it per agent via createModelFactory.
  • Pricing when the gateway is unreachableThe static fallback catalog is unpriced (the live listing is the authority), so vercel-gateway:* expands to nothing offline unless you pass allowUnpriced or supply rates via cost.prices.

Related

  • provider-openrouterThe other one-key-many-vendors adapter — but without a live listing or per-model pricing.
  • provider-anthropicGo direct to Claude instead of routing through the gateway (priced catalog, no hop).
  • coredefineSwarm / modelFactory consume the factory; createModelProviderRegistry + resolveModelAllowList turn the live listing into a priced allow-list.
  • model-providersThe guide to registering providers, listing what each exposes, and pricing every run at the provider that ran it.
  • cliowl install provider-vercel-gateway scaffolds the env vars and the modelFactory config marker.