content/providers/03-community-providers/13-codex-cli.mdx
The ai-sdk-provider-codex-cli community provider enables using OpenAI's GPT-5 series models through the Codex CLI. It's useful for developers who want to use their ChatGPT Plus/Pro subscription or API key authentication.
| Provider Version | AI SDK Version | NPM Tag | Status |
|---|---|---|---|
| 1.x | v6 | latest | Stable |
| 0.x | v5 | ai-sdk-v5 | Maintenance |
# AI SDK v6 (default)
npm install ai-sdk-provider-codex-cli ai
# AI SDK v5
npm install ai-sdk-provider-codex-cli@ai-sdk-v5 ai@^5.0.0
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}> <Tab> <Snippet text="pnpm add ai-sdk-provider-codex-cli" dark /> </Tab> <Tab> <Snippet text="npm install ai-sdk-provider-codex-cli" dark /> </Tab> <Tab> <Snippet text="yarn add ai-sdk-provider-codex-cli" dark /> </Tab> <Tab> <Snippet text="bun add ai-sdk-provider-codex-cli" dark /> </Tab> </Tabs>
You can import the default provider instance codexCli from ai-sdk-provider-codex-cli:
import { codexCli } from 'ai-sdk-provider-codex-cli';
If you need a customized setup, you can import createCodexCli and provide default settings that apply to every model:
import { createCodexCli } from 'ai-sdk-provider-codex-cli';
const codexCli = createCodexCli({
defaultSettings: {
reasoningEffort: 'medium',
approvalMode: 'on-failure',
sandboxMode: 'workspace-write',
verbose: true,
},
});
Or pass settings per-model:
const model = codexCli('gpt-5.1-codex', {
reasoningEffort: 'high',
approvalMode: 'on-failure',
sandboxMode: 'workspace-write',
});
Model settings:
Create models that call GPT-5 through the Codex CLI using the provider instance:
const model = codexCli('gpt-5.2-codex');
Current Generation Models:
xhigh reasoning)Legacy Models (still supported):
import { codexCli } from 'ai-sdk-provider-codex-cli';
import { generateText } from 'ai';
const { text } = await generateText({
model: codexCli('gpt-5.2-codex'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
const model = codexCli('gpt-5.1-codex-max', {
reasoningEffort: 'high', // 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'
reasoningSummary: 'detailed',
});
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
gpt-5.3-codex | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.2-codex | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.2 | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.1-codex-max | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.1-codex-mini | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.1 | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
gpt-5.1-codex | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
The provider uses your existing ChatGPT Plus/Pro subscription through the Codex CLI:
npm install -g @openai/codex
codex # Follow the interactive authentication setup
Alternatively, you can use an OpenAI API key by setting the OPENAI_API_KEY environment variable.
For more details, see the provider documentation.