Browse by type
A community provider for Vercel AI SDK v6 that integrates OpenAI's Codex CLI with current GPT models such as gpt-5.5, gpt-5.2, and gpt-5.1, plus Codex-specific slugs like gpt-5.3-codex, gpt-5.2-codex, *-codex-max, and *-codex-mini, using your ChatGPT Plus/Pro subscription.
This package ships two provider modes:
codexExec: non-interactive codex exec (spawn a new process per call)codexAppServer: persistent codex app-server JSON-RPC client (shared process, true delta streaming, optional stateful threads)
Works with generateText, streamText, and generateObject
codex login (tokens in ~/.codex/auth.json) or OPENAI_API_KEY| Provider Version | AI SDK Version | NPM Tag | NPM Installation |
|---|---|---|---|
| 1.x.x | v6 | latest |
npm i ai-sdk-provider-codex-cli ai@^6.0.0 |
| 0.x.x | v5 | ai-sdk-v5 |
npm i ai-sdk-provider-codex-cli@ai-sdk-v5 ai@^5.0.0 |
npm i -g @openai/codex
codex login # or set OPENAI_API_KEY
npm i ai ai-sdk-provider-codex-cli
npm i ai@^5.0.0 ai-sdk-provider-codex-cli@ai-sdk-v5
⚠️ Codex CLI Version: Requires the current stable Codex CLI 0.130.x for full support of both provider modes (
codexExecandcodexAppServer). This package pins its optional@openai/codexdependency to^0.130.0, the latest non-alpha release validated for this maintenance update. If you supply your own Codex CLI (global install or customcodexPath), check it withcodex --versionand upgrade if needed.
bash npm i -g @openai/codex@latest
codexExec) — process-per-callimport { generateText } from 'ai';
import { codexExec } from 'ai-sdk-provider-codex-cli';
const model = codexExec('gpt-5.5', {
allowNpx: true,
skipGitRepoCheck: true,
approvalMode: 'on-failure',
sandboxMode: 'workspace-write',
});
const { text } = await generateText({
model,
prompt: 'Reply with a single word: hello.',
});
console.log(text);
createCodexAppServer) — persistent processimport { streamText } from 'ai';
import { createCodexAppServer } from 'ai-sdk-provider-codex-cli';
const provider = createCodexAppServer({
defaultSettings: {
minCodexVersion: '0.130.0',
autoApprove: false,
personality: 'pragmatic',
},
});
const { textStream } = await streamText({
model: provider('gpt-5.5'),
prompt: 'Write two short lines of encouragement.',
});
for await (const chunk of textStream) process.stdout.write(chunk);
await provider.close();
By default, codexAppServer is stateless (new ephemeral thread per call). To continue a prior conversation across calls, start a persistent thread and then pass its threadId in providerOptions['codex-app-server'].
import { generateText } from 'ai';
import { createCodexAppServer } from 'ai-sdk-provider-codex-cli';
const provider = createCodexAppServer();
const first = await generateText({
model: provider('gpt-5.5'),
prompt: 'Start a migration checklist.',
providerOptions: {
'codex-app-server': { threadMode: 'persistent' },
},
});
const threadId = first.providerMetadata?.['codex-app-server']?.threadId;
const second = await generateText({
model: provider('gpt-5.5'),
prompt: 'Continue from step 2.',
providerOptions: {
'codex-app-server': { threadId },
},
});
await provider.close();
import { generateObject } from 'ai';
import { z } from 'zod';
import { codexExec } from 'ai-sdk-provider-codex-cli';
const schema = z.object({ name: z.string(), age: z.number().int() });
const { object } = await generateObject({
model: codexExec('gpt-5.5', { allowNpx: true, skipGitRepoCheck: true }),
schema,
prompt: 'Generate a small user profile.',
});
console.log(object);
codexExec / createCodexExec for codex execcodexAppServer / createCodexAppServer for codex app-servercodexCli / createCodexCli map to exec mode--output-schema (API-enforced with strict: true)on-failure, workspace-write, --skip-git-repo-check)npx @openai/codex when not on PATH (allowNpx)The provider supports multimodal (image) inputs for vision-capable models:
import { generateText } from 'ai';
import { codexExec } from 'ai-sdk-provider-codex-cli';
import { readFileSync } from 'fs';
const model = codexExec('gpt-5.5', { allowNpx: true, skipGitRepoCheck: true });
const imageBuffer = readFileSync('./screenshot.png');
const { text } = await generateText({
model,
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'What do you see in this image?' },
{ type: 'image', image: imageBuffer, mimeType: 'image/png' },
],
},
],
});
console.log(text);
Supported image formats:
data:image/png;base64,...)Buffer / Uint8Array / ArrayBufferRemote image URLs:
codexExec mode: HTTP/HTTPS image URLs are not supported (provide binary/image data)codexAppServer mode: HTTP/HTTPS image URLs are supported and forwarded to app-server as remote image inputsLocal image data is written to temporary files and passed to Codex CLI via --image (or app-server localImage). Temp files are automatically cleaned up after each request.
See examples/exec/image-support.mjs and examples/app-server/image-support.mjs for complete working examples.
The provider supports comprehensive tool streaming, enabling real-time monitoring of Codex CLI's autonomous tool execution:
import { streamText } from 'ai';
import { codexExec } from 'ai-sdk-provider-codex-cli';
const result = await streamText({
model: codexExec('gpt-5.5', { allowNpx: true, skipGitRepoCheck: true }),
prompt: 'List files and count lines in the largest one',
});
for await (const part of result.fullStream) {
if (part.type === 'tool-call') {
console.log('🔧 Tool:', part.toolName);
}
if (part.type === 'tool-result') {
console.log('✅ Result:', part.result);
}
}
What you get:
providerExecuted: true on all tool calls (Codex executes autonomously, app doesn't need to)Current behavior:
codexExec: tool outputs are delivered in final tool-result events.codexAppServer: when Codex emits tool output delta notifications, the provider surfaces tool-result parts with result.type === 'output-delta' during streaming.See examples/exec/streaming-tool-calls.mjs, examples/exec/streaming-multiple-tools.mjs, and their app-server counterparts under examples/app-server/.
Control logging verbosity and integrate with your observability stack:
import { codexExec } from 'ai-sdk-provider-codex-cli';
// Default: warn/error only (clean production output)
const model = codexExec('gpt-5.5', {
allowNpx: true,
skipGitRepoCheck: true,
});
// Verbose mode: enable debug/info logs for troubleshooting
const verboseModel = codexExec('gpt-5.5', {
allowNpx: true,
skipGitRepoCheck: true,
verbose: true, // Shows all log levels
});
// Custom logger: integrate with Winston, Pino, Datadog, etc.
const customModel = codexExec('gpt-5.5', {
allowNpx: true,
skipGitRepoCheck: true,
verbose: true,
logger: {
debug: (msg) => myLogger.debug('Codex:', msg),
info: (msg) => myLogger.info('Codex:', msg),
warn: (msg) => myLogger.warn('Codex:', msg),
error: (msg) => myLogger.error('Codex:', msg),
},
});
// Silent: disable all logging
const silentModel = codexExec('gpt-5.5', {
allowNpx: true,
skipGitRepoCheck: true,
logger: false, // No logs at all
});
Log Levels:
debug: Detailed execution traces (verbose mode only)info: General execution flow (verbose mode only)warn: Warnings and misconfigurations (always shown)error: Errors and failures (always shown)Default Logger: Adds level tags [DEBUG], [INFO], [WARN], [ERROR] to console output. Use a custom logger or logger: false if you need different formatting.
See examples/exec/logging-*.mjs and examples/app-server/logging-*.mjs for complete examples, and docs/ai-sdk-v5/guide.md for detailed configuration.
codexExec mode: Incremental streaming is not currently available with codex exec --experimental-json.
The --experimental-json output format (introduced Sept 25, 2025) currently only emits item.completed events with full text content. Incremental streaming via item.updated or delta events is not yet implemented by OpenAI.
What this means in exec mode:
streamText() works functionally but delivers the entire response in a single chunk after generation completescodexAppServer mode: supports true incremental text deltas via item/agentMessage/delta, so streamText() emits progressively as tokens arrive.
When OpenAI adds streaming support to codex exec --experimental-json, this provider will surface those deltas in exec mode as well.
docs/:npm run validate:docs checks markdown links and example command pathsnpm run validate:examples:app-server runs all app-server examples with intent checksnpm run validate:full runs build/type/lint/test plus docs and app-server example validationcodex login (stores tokens at ~/.codex/auth.json)OPENAI_API_KEY in the provider’s env settings (forwarded to the spawned process)allowNpx: If true, falls back to npx -y @openai/codex when Codex is not on PATHcwd: Working directory for CodexaddDirs: Extra directories Codex may read/write (repeats --add-dir)fullAuto (equivalent to --full-auto)dangerouslyBypassApprovalsAndSandbox (bypass approvals and sandbox; dangerous)-c approval_policy=... and -c sandbox_mode=... for you; defaults to on-failure and workspace-writeskipGitRepoCheck: enable by default for CI/non‑repo contextscolor: always | never | autooutputLastMessageFile: by default the provider sets a temp path and rea$ claude mcp add ai-sdk-provider-codex-cli \
-- python -m otcore.mcp_server <graph>