ai-sdk-codex-provider
v0.0.1
Published
The `ai-sdk-codex-provider` package provides a Codex SDK-backed provider for the [AI SDK](https://ai-sdk.dev/docs), using [`@openai/codex-sdk`](https://www.npmjs.com/package/@openai/codex-sdk) under the hood.
Downloads
189
Maintainers
Readme
AI SDK - Codex SDK Provider
The ai-sdk-codex-provider package provides a Codex SDK-backed provider for the AI SDK, using @openai/codex-sdk under the hood.
Setup
Install the provider with ai:
npm i ai-sdk-codex-provider aiSkill for Coding Agents
If you use coding agents such as Claude Code or Cursor, we recommend adding the AI SDK skill to your repository:
npx skills add vercel/aiProvider Instance
You can import the default provider instance codexSdk:
import { codexSdk } from "ai-sdk-codex-provider";Or create a customized provider instance:
import { createCodexSdk } from "ai-sdk-codex-provider";
const provider = createCodexSdk({
name: "codex-sdk",
baseURL: process.env.OPENAI_BASE_URL,
threadOptions: {
workingDirectory: process.cwd(),
sandboxMode: "read-only",
approvalPolicy: "never",
},
});Example
import { codexSdk } from "ai-sdk-codex-provider";
import { generateText } from "ai";
const { text } = await generateText({
model: codexSdk("gpt-5"),
prompt: "Summarize the repository state in one paragraph.",
});
console.log(text);Including Model IDs for Auto-Completion
import { createCodexSdk } from "ai-sdk-codex-provider";
type CodexModelIds = "gpt-5.3-codex" | "gpt-5.2-codex" | (string & {});
const provider = createCodexSdk<CodexModelIds>();
provider("gpt-5.3-codex");To refresh the generated model catalog (model ids + metadata) from upstream Codex:
bun --cwd packages/ai-sdk-codex-provider run sync:model-catalogRead generated model metadata at runtime:
import { getCodexSdkModelInfo } from "ai-sdk-codex-provider";
const info = getCodexSdkModelInfo("gpt-5.3-codex");
console.log(info?.contextWindow);Notes
- This provider targets
LanguageModelV3only. - AI SDK tools are ignored by the provider because Codex executes tools autonomously.
- Provider-executed Codex tools are surfaced through stream events (
tool-call,tool-result). - Set
includeRawChunks: truein AI SDK call options to receive raw CodexThreadEventpayloads in the stream. - Codex SDK authentication (ChatGPT account or API key) must already be configured in your environment.
Option Coverage
Audited against @openai/[email protected].
CodexOptionssupport:createCodexSdk(...)forwards all currentCodexOptionsfields.baseUrlis supported viabaseURL(preferred) andbaseUrl(deprecated alias). If both are provided,baseURLwins.ThreadOptionssupport: supported at all adapter layers:- Provider default:
createCodexSdk({ threadOptions: ... }) - Model default:
codexSdk(modelId, modelSettings) - Per-call override:
providerOptions["<provider-name>"]
- Provider default:
- Resume support:
providerOptions["<provider-name>"].threadIdmaps tocodex.resumeThread(threadId, threadOptions). - Provider options lookup supports both
providerOptions["codex-sdk"](canonical key) andproviderOptions["<provider-name>"](custom provider name). If both are present, custom-key values override canonical values. - Turn options support: AI SDK
abortSignalmaps to CodexTurnOptions.signal; AI SDK JSON response schema maps to CodexTurnOptions.outputSchema(responseFormat.name/descriptionare mapped to schematitle/descriptionwhen missing).
Not fully passthrough:
ThreadOptions.modelis intentionally overridden by the AI SDK model id (codexSdk("<model-id>")) on every call.
AI SDK call options currently not forwarded to Codex (warnings emitted):
tools,toolChoiceheaderstemperature,topP,topKmaxOutputTokensstopSequencespresencePenalty,frequencyPenaltyseed
Documentation
- AI SDK community custom provider guide: https://ai-sdk.dev/providers/community-providers/custom-providers
- Codex SDK docs: https://github.com/openai/codex/tree/main/sdk/typescript
