@fieldwork-ai/codex-transport

中文文档
0.1.11发布于 2026/11/09(MIT OR Apache-2.0) AND Apache-2.0TypeScriptES Module近 30 天下载 2028

ChatGPT subscription transport and OAuth for the AI SDK, ported from OpenAI Codex.

原始使用文档

@fieldwork-ai/codex-transport

A ChatGPT subscription transport for AI SDK LanguageModelV4, with device-code and browser PKCE OAuth, allowance reads, and refresh leases. Protocol behavior is ported from OpenAI Codex, under Apache-2.0. The pinned upstream revision and source paths are in NOTICE.

Requires Node 24. Install with pnpm add @fieldwork-ai/codex-transport.

import { createOpenAISubscriptionModel } from '@fieldwork-ai/codex-transport';

const model = createOpenAISubscriptionModel({
  modelId: 'gpt-5.6-luna',
  accessToken: credential.accessToken,
  accountId: credential.accountId,
  attribution: { originator: 'your-app', userAgent: 'your-app/1.0' },
});

Pass the model to the AI SDK's generateText or streamText. Subscription credentials belong to the individual using the client. This package does not store credentials or provide a shared proxy. Every network entry point requires caller attribution; it never pretends to be the Codex CLI.

createOpenAISubscriptionModel projects messages into a portable context and uses CodexClient.complete / stream. The client follows Codex's Responses request contract: account and attribution headers, session and thread headers, model/tier routing, encrypted reasoning replay, store: false, and zstd compression. SSE is the default, including transport: 'auto'; explicit transport: 'websocket' uses the same event decoder over Responses WebSockets. Requests can be aborted with the SDK's abortSignal. The provider identity remains openai-subscription, including reasoning metadata saved by earlier clients.

Optional client settings are fedramp, responsesLite, compression, baseUrl, and fetchFn. Responses-lite emits stable per-thread prefix IDs, puts tools into an additional_tools item, and moves instructions into the input. It is opt-in. No conversation history or tool execution loop lives here.

Images default to PNG, JPEG, GIF and WebP; callers can narrow this with isModelImageMime. Unsupported files, foreign reasoning, and provider-specific content degrade without throwing on a stored conversation. URLs are never fetched during projection.

For OAuth, use requestOpenAIDeviceAuthorization, pollOpenAIDeviceAuthorization, and exchangeOpenAIDeviceAuthorization, or loginOpenAISubscriptionDeviceCode for the complete polling flow. Browser clients use beginOpenAIBrowserAuthorization and exchangeOpenAIBrowserAuthorization; the caller owns the listener at http://localhost:1455/auth/callback and securely retains the returned PKCE verifier and state until exchange. OAuth calls validate callback state, constrain destinations, bound response bodies, and redact provider errors.

refreshWithCredentialLease coordinates refresh across an OpenAISubscriptionRefreshStore; InMemoryOpenAISubscriptionRefreshStore is provided. Database-backed callers implement read, tryAcquire, commit, and release, enforcing generation and lease ownership. Encrypt durable credentials in the application's store.

fetchCodexUsage returns normalized usage windows. isOpenAISubscriptionUsageLimitError recognizes the service's allowance error codes. Neither API requires the application's database or billing model.

Development

From the repository root, run pnpm install --frozen-lockfile, pnpm build, and pnpm test. This package lives in packages/codex-transport and releases independently of the CLI. Tests cover message projection, OAuth, concurrent refresh, usage normalization, SSE decoding, request headers/compression, and authenticated WebSockets. Release by publishing this repository first; consumers must pin the published version, not a local path or patched dependency.

License

Fieldwork AI code is dual-licensed under MIT or Apache-2.0, at your option. The OpenAI-derived portions of Codex transport retain their Apache-2.0 terms and attribution. See LICENSE, LICENSE-MIT, LICENSE-APACHE, and the transport NOTICE. Dependencies retain their own licenses. The package metadata uses (MIT OR Apache-2.0) AND Apache-2.0 to record both the choice for Fieldwork contributions and the required upstream terms.

版本与发布记录

@fieldwork-ai/codex-transport 共发布 12 个版本,首次发布于 2026/09/07;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.1.11latest2026/11/096 天前
0.1.102026/11/0510 天前
0.1.92026/10/1927 天前
0.1.82026/09/301 个月前
0.1.72026/09/291 个月前
0.1.62026/09/281 个月前

关于 @fieldwork-ai/codex-transport 的常见问题

@fieldwork-ai/codex-transport 是什么?

ChatGPT subscription transport and OAuth for the AI SDK, ported from OpenAI Codex.

如何安装 @fieldwork-ai/codex-transport?

在项目目录运行 npm install @fieldwork-ai/codex-transport,或使用 pnpm add / yarn add / bun add。

@fieldwork-ai/codex-transport 支持 TypeScript 吗?

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

@fieldwork-ai/codex-transport 支持 ESM 还是 CommonJS?

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

@fieldwork-ai/codex-transport 需要什么版本的 Node.js?

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

@fieldwork-ai/codex-transport 可以商用吗?

@fieldwork-ai/codex-transport 使用 (MIT OR Apache-2.0) AND Apache-2.0 许可。可在 MIT、Apache-2.0) AND Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fieldwork-ai/codex-transport 的下载量有多少?

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

@fieldwork-ai/codex-transport 还在维护吗?

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