@fevex/openai

中文文档
0.1.0-alpha.14发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 3409

OpenAI ModelGateway adapter for Fevex.

原始使用文档

@fevex/openai

Official OpenAI ModelGateway adapter for Fevex. See the compatibility and release policy.

npm install @fevex/core @fevex/openai
import { createOpenAI } from '@fevex/openai';

const model = createOpenAI({
  apiKey: process.env.OPENAI_API_KEY!,
  organization: process.env.OPENAI_ORG_ID,
  project: process.env.OPENAI_PROJECT_ID,
  schemaPolicy: 'strict',
})('gpt-5.6');

The adapter uses native fetch and implements only the Fevex model contract. Runtime behavior such as tool execution, validation, events and retries belongs to @fevex/core. Returned gateways include metadata: { provider: "openai", model: modelId } for traces, eval cost calculators and OpenTelemetry export.

Text, tools and continuation

Without outputSchema, OpenAI text is returned as the exact string supplied by the Responses API, even when it looks like JSON. With outputSchema, the adapter requires valid JSON before Fevex performs local schema validation. Refusals, incomplete responses and malformed function calls fail explicitly.

During tool loops the adapter stores the original response items, including reasoning items required by Responses API, in opaque providerState. Fevex returns that state to the next model step automatically. Direct ModelGateway consumers must do the same; the state is run-local and must not be inspected. The adapter's stateCodec lets Fevex persist it only inside a private durable checkpoint.

Core reasoning efforts are forwarded to reasoning.effort; provider-default leaves provider options untouched. The core contract includes none, minimal, low, medium, high, xhigh and max so current GPT-5.6 models can use their documented effort levels. Model-specific support still belongs to OpenAI, so an unsupported value is reported by the API. Provider-only settings can be supplied through modelOptions.reasoning.

createOpenAI receives the connection settings (apiKey, optional organization, project, baseURL, schema policy and fetch) and the model ID is supplied when creating the gateway. Reasoning effort is intentionally a per-request setting forwarded through ModelInput, not a factory setting.

The adapter always uses the Responses streaming API. It emits only response.output_text.delta as visible output and builds the terminal result from response.completed; reasoning and partial function arguments remain private.

Tool names and schemaName must match [A-Za-z0-9_-]{1,64}. Fevex-owned fields such as model, input, tools, tool choice, schema format, parallel calls and output caps override conflicting modelOptions. Background provider jobs and built-in tools remain outside this gateway.

Schema policy

schemaPolicy defaults to "strict". Before sending a request, the adapter checks tool inputs and final outputs against OpenAI's documented Structured Outputs subset. Every schema must have an object root; every object must require all its properties and set additionalProperties: false. Unsupported keywords and documented size limits throw OpenAIError with code: "PROVIDER_SCHEMA_UNSUPPORTED" before fetch runs.

Set schemaPolicy: "best-effort" to send tools with strict: false. Object outputs use JSON mode and other JSON values use a schema instruction. Fevex still validates the returned value locally, but OpenAI does not guarantee schema adherence in this mode, so the caller may need to retry an invalid result.

PolicyTool inputFinal output
strictOpenAI strict function schemaStructured Outputs
best-effortNon-strict function schemaJSON mode or JSON instruction

版本与发布记录

@fevex/openai 共发布 13 个版本,首次发布于 2026/07/28;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0-alpha.14latest2026/11/113 天前
0.1.0-alpha.132026/11/113 天前
0.1.0-alpha.122026/11/095 天前
0.1.0-alpha.112026/11/086 天前
0.1.0-alpha.102026/11/077 天前
0.1.0-alpha.92026/11/077 天前

其他发布通道:alpha → 0.1.0-alpha.1。

关于 @fevex/openai 的常见问题

@fevex/openai 是什么?

OpenAI ModelGateway adapter for Fevex.

如何安装 @fevex/openai?

在项目目录运行 npm install @fevex/openai,或使用 pnpm add / yarn add / bun add。

@fevex/openai 支持 TypeScript 吗?

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

@fevex/openai 支持 ESM 还是 CommonJS?

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

@fevex/openai 需要什么版本的 Node.js?

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

@fevex/openai 可以商用吗?

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

@fevex/openai 的下载量有多少?

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

@fevex/openai 还在维护吗?

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