@frogbotai/gateway

中文文档
0.42.0发布于 2026/11/15MITTypeScriptES Module近 30 天下载 9167

The open-source, self-hostable AI gateway built on the Vercel AI SDK. The server side of what Vercel kept closed-source.

原始使用文档
文档目录13 节
  1. Features
  2. Quickstart
  3. Use it with the OpenAI SDK
  4. Or with curl
  5. Endpoints
  6. Providers
  7. Configuration
  8. Embedding
  9. Hooks
  10. Observability
  11. Errors
  12. Part of FrogBot
  13. License

FrogBot logo

@frogbotai/gateway

The open-source, self-hostable, embeddable AI gateway built on the Vercel AI SDK.
The server side of what Vercel kept closed-source — fully MIT licensed.

License   npm   npm downloads   Discord   Node


Explore the Docs  ·  Join the Discord


One endpoint, every provider. Point any OpenAI-compatible client at the gateway and route to OpenAI, Anthropic, Google, Groq, Mistral, Bedrock, Vertex, and 30+ more providers — with streaming, hooks, and full OpenTelemetry observability. Run it standalone from the CLI, or embed it as a fetch handler inside any server you already have.

FrogBot's core framework embeds this exact package to power its own ai config block — see Configure AI in FrogBot. This package has zero FrogBot dependencies, so it also runs completely on its own: standalone from the CLI, or embedded in any Node/Bun/Deno/Workers server.

Features

  • OpenAI-compatible wire formats — Chat Completions, the Responses API, and Anthropic's Messages API, so existing SDKs and clients work unchanged
  • 36+ built-in providers plus generic OpenAI-compatible endpoints for anything self-hosted (vLLM, Ollama, LM Studio, ...)
  • Every modality — chat, embeddings, images, speech, transcription, reranking, and video
  • Streaming everywhere — SSE on chat completions, responses, and messages
  • Embeddable — createGateway() returns a WinterCG fetch handler that mounts in Hono, Next.js, Bun, Deno, or Cloudflare Workers
  • Lifecycle hooks — beforeOperation → beforeUpstream → afterUpstream/afterError → afterOperation, with token usage aggregated across tool loops
  • Observability built in — structured logging (bring your own pino-compatible logger) and OpenTelemetry tracing
  • Wire-correct errors — OpenAI's error envelope on every route; same-provider upstream errors forwarded verbatim with their original status
  • Fully MIT open source — no gated features, no hosted tier required

Quickstart

OPENAI_API_KEY=sk-... npx @frogbotai/gateway

The CLI auto-discovers providers from environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, GROQ_API_KEY, ...) and listens on 0.0.0.0:3939 by default (HOST / PORT / --port to change). If no providers are found it exits with a friendly error listing every env var it looked for.

Model IDs are namespaced as provider/model — the prefix tells the gateway which provider to dispatch to.

Use it with the OpenAI SDK

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'unused', // the gateway holds the upstream keys
  baseURL: 'http://localhost:3939/v1',
});

const res = await client.chat.completions.create({
  model: 'anthropic/claude-sonnet-5-5',
  messages: [{ role: 'user', content: 'Hello' }],
  stream: true,
});

Or with curl

curl http://localhost:3939/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Endpoints

RouteCompatibilityStreaming
POST /v1/chat/completionsOpenAI Chat CompletionsYes
POST /v1/responsesOpenAI Responses APIYes
POST /v1/messagesAnthropic Messages APIYes
POST /v1/embeddingsOpenAI Embeddings—
POST /v1/images/generationsOpenAI Images—
POST /v1/audio/speechOpenAI Speech—
POST /v1/audio/transcriptionsOpenAI Transcriptions—
POST /v1/rerankReranking—
POST /v1/videos/generationsVideo generation—
GET /v1/modelsOpenAI Models (catalog discovery)—

Routes are also served at their bare paths (/chat/completions), so mounting the handler under any prefix just works.

Providers

Alibaba, Anthropic, Anthropic (AWS), AssemblyAI, Azure, Baseten, Amazon Bedrock, Black Forest Labs, ByteDance, Cerebras, Cohere, Deepgram, DeepInfra, DeepSeek, ElevenLabs, fal, Fireworks, Gladia, Google, Google Vertex, Groq, Hugging Face, Hume, Kling AI, LMNT, Luma, Mistral, Moonshot AI, OpenAI, Perplexity, Prodia, Replicate, Together AI, Vercel, Voyage, xAI — plus any number of custom OpenAI-compatible endpoints under any other key in providers (Ollama, LM Studio, vLLM, ...).

Configuration

Drop a gateway.config.ts next to where you run the CLI (or point at one with --config):

import { defineConfig } from '@frogbotai/gateway';

export default defineConfig({
  providers: {
    openai: {},
    anthropic: {},
    ollama: { baseURL: 'http://localhost:11434/v1' },
  },
  upstreamTimeoutMs: 60_000,
  hooks: {
    afterOperation: [
      ({ operation, model, usage }) => {
        console.log(operation, model, usage?.totalTokens);
      },
    ],
  },
});

Other options include enabled_providers / disabled_providers allow/deny lists, a custom catalog for GET /v1/models, basePath, maxBodyBytes, logger, tracing, and tracer.

Embedding

createGateway() returns a WinterCG fetch handler — mount it anywhere:

import { serve } from '@hono/node-server';
import { createGateway } from '@frogbotai/gateway';

const gw = createGateway({
  providers: { openai: {} },
});

serve({ fetch: gw.handler, port: 3939 });

Inside an existing Hono app:

app.mount('/v1', gw.handler);

Or as a Next.js route handler, a Bun/Deno server, or a Cloudflare Worker — anything that speaks (req: Request) => Promise<Response>.

Hooks

Every route runs the same lifecycle: beforeOperation → beforeUpstream → afterUpstream/afterError → afterOperation. Hooks receive the operation name, the canonical provider/model ID, a shared mutable context bag, and (on the way out) aggregated token usage — summed across every round of a tool loop. Use them for auth, rate limiting, cost tracking, or audit logging.

Observability

  • Logging — pass any pino-compatible logger (or anything satisfying GatewayLogger), or let the gateway create its console logger
  • Tracing — provide an OpenTelemetry Tracer, or use the Node-only @frogbotai/gateway/setup export to bootstrap one; the CLI honors OTEL_EXPORTER_OTLP_ENDPOINT out of the box

Errors

All error responses use OpenAI's envelope:

{
  "error": {
    "message": "...",
    "type": "invalid_request_error",
    "code": "string | null",
    "param": "string | null"
  }
}

Same-provider upstream errors (e.g. an invalid OpenAI key on an OpenAI call) are forwarded verbatim with the upstream HTTP status. Gateway-originated errors follow the same shape with the gateway's own code values. Error helpers are exported from @frogbotai/gateway/errors so embedders can produce matching envelopes.

Part of FrogBot

This package has zero FrogBot dependencies and works great entirely on its own. It's also the exact package FrogBot — the config-first AI agent framework — embeds internally for its ai config block. See Configure AI in FrogBot for that integration.

License

MIT © Colby Gilbert

版本与发布记录

@frogbotai/gateway 共发布 42 个版本,首次发布于 2026/07/20;过去 12 个月发布了 42 个版本。

版本发布日期距今
0.42.0latest2026/11/15今天
0.41.02026/11/097 天前
0.40.02026/11/069 天前
0.39.02026/11/0213 天前
0.38.02026/11/0115 天前
0.37.02026/10/2917 天前

关于 @frogbotai/gateway 的常见问题

@frogbotai/gateway 是什么?

The open-source, self-hostable AI gateway built on the Vercel AI SDK. The server side of what Vercel kept closed-source.

如何安装 @frogbotai/gateway?

在项目目录运行 npm install @frogbotai/gateway,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 frogbotai-gateway,可以用 npx frogbotai-gateway 直接运行。

@frogbotai/gateway 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@frogbotai/gateway 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@frogbotai/gateway 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.22.3。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frogbotai/gateway 可以商用吗?

@frogbotai/gateway 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frogbotai/gateway 的下载量有多少?

根据 npm 官方下载统计,@frogbotai/gateway 在 2026/10/16 – 2026/11/14 这 30 天内被下载 9,167 次,日均约 306 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frogbotai/gateway 还在维护吗?

最新版本 0.42.0 发布于 2026/11/15(今天);至今共发布 42 个版本,其中过去 12 个月发布了 42 个;首次发布于 2026/07/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。