@dbx-tools/appkit-model-gateway

中文文档
0.9.206发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 8184

AppKit model gateway for Databricks OpenAI, Anthropic, Codex, and AI Gateway APIs

原始使用文档
文档目录9 节
  1. Choose embedded, foreground, or service mode
  2. Register the AppKit plugin
  3. Connect a client
  4. Use Smart Router
  5. Discover models
  6. Request compatibility
  7. Configure Codex
  8. Configure model policy
  9. Package API

@dbx-tools/appkit-model-gateway

Expose models in a Databricks workspace through OpenAI Responses, OpenAI Chat Completions, Anthropic Messages, embeddings, and Codex-compatible APIs. The gateway discovers the workspace catalogue and selects a compatible Databricks route for each request.

Choose embedded, foreground, or service mode

Register the AppKit plugin when model routes belong to an existing application. Run dbx model-gateway for a foreground loopback endpoint used by local tools. Use dbx model-gateway service install when that local endpoint must continue after the terminal closes.

Register the AppKit plugin

import { createApp, server } from "@databricks/appkit";
import { modelGateway } from "@dbx-tools/appkit-model-gateway";

await createApp({
  plugins: [modelGateway(), server()],
});

AppKit mounts the plugin routes under /api/model-gateway/v1/*. The @dbx-tools/cli provides foreground server construction, current-user service management, and standard root compatibility paths.

Connect a client

Use the standalone CLI when a tool expects an OpenAI-compatible base URL:

dbx model-gateway \
  --profile PRIMARY-PROFILE \
  --profile FALLBACK-PROFILE \
  --listen tcp://127.0.0.1:4000

Profiles are tried in declaration order. Model discovery and routing use the first profile. When an inference request receives HTTP 429, the gateway retries the same upstream model through the next profile whose workspace is available. Cooldowns are shared by workspace and model id, so two profiles for the same workspace do not bypass the same limit. After the reported retry interval expires, requests return to the first profile automatically.

Retry-After takes precedence over a JSON retry_after value. When Databricks reports a workspace tokens-per-minute limit without either value, the gateway uses a 60-second cooldown; other 429 responses use 15 seconds.

The system-model preference routes non-exact Responses requests, including Codex traffic, through system.ai.* AI Gateway services instead of workspace serving endpoints. Codex model slugs follow the same choice. An exact endpoint id or system.ai.* name always wins.

Configure the client with http://127.0.0.1:4000/v1. For an embedded AppKit route, use the app origin plus /api/model-gateway/v1.

The gateway supports:

  • OpenAI Responses and Chat Completions.
  • Anthropic Messages.
  • OpenAI-compatible embeddings.
  • Codex model discovery and Responses traffic.

Use Smart Router

Select the virtual smart-router model from any supported chat protocol:

{
  "model": "smart-router",
  "input": "Refactor the authorization layer across the repository"
}

Before returning GET /v1/models, the gateway makes one memoized task_v3 capability request to Databricks /ai-gateway/routing/v1/routes:select. The virtual model is listed only when that request succeeds for the active identity and live system.ai.* candidates. Positive probes are shared for five minutes and concurrent probes coalesce into one request. Stale values are returned immediately while @dbx-tools/cache refreshAfterWrite coalesces one access-triggered background refresh. An explicit inference request skips this synthetic preflight because its real route selection is already the availability check.

For inference, the gateway extracts bounded task context from Responses input, Chat Completions or Anthropic messages, plain text, or generic JSON objects. It excludes credentials, tool schemas, and tool arguments. OpenAI-shaped requests use the codex Smart Router harness policy; Anthropic Messages uses claude. The selected route must match one of the offered, protocol-compatible live models. There is no local tier classifier or fallback selector.

The same smart-router id works with Responses, Chat Completions, Anthropic Messages, and Codex-compatible Responses traffic. Embeddings require an explicit model. Explicit concrete models and model-class headers continue to win.

Smart Router selections are pinned for the logical user turn. The default store uses AppKit CacheManager, so configured Lakebase/PostgreSQL persistence is reused across app replicas. Supply smartRouterStore to use another storage implementation with the same get/set contract, including a SQLite-backed adapter. Only the selected model and bounded route metadata are stored; prompts and responses are not.

This state is a TTL route pin, not conversation history. The gateway does not read Mastra PostgresStore: supported chat requests already carry the portable transcript, and coupling routing to Mastra would exclude other chat clients. AppKit cache persistence is also preferable to a gateway-owned file or a second expiring table because it already handles process-local reuse, project-scoped disk fallback, and configured Lakebase/PostgreSQL storage. A consumer can still inject a different store when its deployment needs another backend.

Response headers expose the selected concrete model, returned route model, harness, cache source, and any task_v3 task tier, served tier, or profiler status without rewriting the upstream response body's model identity.

Select a model without starting the server by passing a JSON or text file, or - for standard input:

dbx model-gateway --profile PROFILE --select-model-from request.json

Discover models

import { createModelGatewayClient } from "@dbx-tools/shared-model-gateway";

const client = createModelGatewayClient({ baseUrl: "http://127.0.0.1:4000/" });
const models = await client.listModels({ search: "sonnet" });

Use { codex: true } when a Codex client needs its native catalogue shape.

Request compatibility

Requests stay on a native streaming path when the selected model supports the client protocol. When protocols differ, the gateway translates the request and response through Vercel AI SDK messages while preserving text, function tools, reasoning, usage, finish reasons, streaming, and cancellation. Embeddings use a direct Databricks embeddings route and are not translated.

The gateway rejects stateful Responses options it cannot preserve, including previous_response_id, store: true, and background: true.

Explicit temperature: null is omitted. For Databricks models with published models.dev metadata, unsupported temperatures are omitted and supported values are clamped to Databricks' 0..2 range. Unknown custom endpoints keep finite numeric temperatures unchanged.

See request parameter translation for the temperature and reasoning flows.

Web-search and custom-tool requests use a direct route only when the discovered model advertises the required capability. OpenAI model-list capabilities.web_search and Codex supports_search_tool use that same discovered value.

Configure Codex

GET /v1/models includes Codex metadata when the request carries an Originator header containing codex (case-insensitive), or a nonblank client_version query parameter. Codex slugs prefer fully qualified Databricks model service names.

Add metadata=true to either the standard or Codex request to include the optional dbx-tools metadata object on each model. Its latency and rating fields each expose a root sortable score plus nested measurements or source rankings. The default response omits the field so existing OpenAI and Codex clients keep their current payload shape.

Codex merges provider models with its bundled catalogue. The gateway reserves a separate provider priority range so bundled recommendations remain together, then places Smart Router before the Databricks model list. Codex-specific model ordering puts GPT models first and newer family versions before older versions. Databricks GPT labels include the Databricks prefix so they remain distinct from bundled GPT models after Codex applies its compact label formatting.

Point a Codex provider at:

http://127.0.0.1:4000/v1

Use wire_api = "responses" and supports_websockets = false.

Configure model policy

model and modelClass set the default selection. preferSystemModels selects system.ai.* AI Gateway services for non-exact eligible requests. An exact serving endpoint or system.ai.* name still wins.

Smart Router defaults to smartRouter: "auto" and is advertised only after its capability probe succeeds. Set smartRouter: "true" to make model discovery fail when the router is unavailable, or smartRouter: "false" to disable it. Configure smartRouterTimeoutMs, smartRouterContextTokenBudget, smartRouterProbeTtlMs, smartRouterProbeRefreshIntervalMs, and smartRouterRouteTtlSeconds to tune transport, context, request-driven probe expiry, background probe refresh, and turn-pinning behavior. A failed real selection immediately invalidates the positive probe.

Use overrides when workspace metadata must be corrected for a specific model. For example, disable an advertised capability that the selected gateway route cannot use:

import { modelGateway } from "@dbx-tools/appkit-model-gateway";

modelGateway({
  overrides: [
    {
      model: "databricks-gpt-example",
      capabilities: { webSearch: false },
    },
  ],
});

Overrides affect routing and the OpenAI and Codex model catalogues.

Package API

  • modelGateway() registers the AppKit plugin.
  • gateway handles protocol-neutral gateway requests.
  • registry discovers and resolves workspace models.
  • router selects a compatible route from model capabilities.
  • smartRouter builds task context, probes availability, and calls task_v3.
  • transport sends requests to Databricks model APIs.

版本与发布记录

@dbx-tools/appkit-model-gateway 共发布 97 个版本,首次发布于 2026/10/06;过去 12 个月发布了 97 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.206latest2026/11/11今天
0.9.2052026/11/111 天前
0.9.2032026/11/074 天前
0.9.2022026/11/065 天前
0.9.2012026/11/056 天前
0.9.2002026/11/056 天前

关于 @dbx-tools/appkit-model-gateway 的常见问题

@dbx-tools/appkit-model-gateway 是什么?

AppKit model gateway for Databricks OpenAI, Anthropic, Codex, and AI Gateway APIs

如何安装 @dbx-tools/appkit-model-gateway?

在项目目录运行 npm install @dbx-tools/appkit-model-gateway,或使用 pnpm add / yarn add / bun add。

@dbx-tools/appkit-model-gateway 支持 TypeScript 吗?

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

@dbx-tools/appkit-model-gateway 支持 ESM 还是 CommonJS?

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

@dbx-tools/appkit-model-gateway 可以商用吗?

@dbx-tools/appkit-model-gateway 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dbx-tools/appkit-model-gateway 的下载量有多少?

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

@dbx-tools/appkit-model-gateway 还在维护吗?

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