
Research
/Security News
Laravel Lang Compromised with RCE Backdoor Across 700+ Versions
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.
codex-ai-provider
Advanced tools
An AI SDK provider for ChatGPT's Codex API, enabling seamless integration with the Vercel AI SDK using authentication from the codex CLI tool.
~/.codex/auth.json (created by codex login)npm install codex-ai-provider
# or
yarn add codex-ai-provider
# or
pnpm add codex-ai-provider
Before using this provider, you need to authenticate with the ChatGPT Codex service:
codex CLI tool (if not already installed)codex login to authenticate~/.codex/auth.json with your authentication tokensimport { streamText } from 'ai';
import { codex } from 'codex-ai-provider';
// Simple text generation (streaming only)
const result = await streamText({
model: codex('gpt-5'),
prompt: 'Write a haiku about coding.',
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
import { streamText } from 'ai';
import { codex } from 'codex-ai-provider';
const result = await streamText({
model: codex('gpt-5'),
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' },
{ role: 'assistant', content: 'The capital of France is Paris.' },
{ role: 'user', content: 'Tell me more about it.' },
],
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
import { streamText } from 'ai';
import { codex } from 'codex-ai-provider';
const result = await streamText({
model: codex('gpt-5'),
prompt: 'Explain quantum computing.',
});
// Stream the response
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
// Get usage statistics
const usage = await result.usage;
console.log('\nTokens:', usage);
// Output includes: inputTokens, outputTokens, totalTokens, reasoningTokens, cachedInputTokens
import { streamText } from 'ai';
import { codex } from 'codex-ai-provider';
import { z } from 'zod';
const result = await streamText({
model: codex('gpt-5'),
prompt: 'What is the weather in NYC?',
tools: {
getWeather: {
description: 'Get weather for a location',
inputSchema: z.object({
location: z.string().describe('City name'),
}),
execute: async ({ location }) => {
// Your weather API call here
return { temperature: 72, conditions: 'sunny' };
},
},
},
toolChoice: 'required', // Force tool usage for better results
});
// Get the tool calls
const toolCalls = await result.toolCalls;
console.log('Tool calls:', toolCalls);
import { createCodex } from 'codex-ai-provider';
// Use custom authentication
const customCodex = createCodex({
// Use API key from OPENAI_API_KEY env var
useApiKey: true,
baseURL: 'https://api.openai.com/v1',
});
// Or provide API key directly
const codexWithKey = createCodex({
apiKey: 'your-api-key',
baseURL: 'https://api.openai.com/v1',
});
// Use with custom settings
const result = await streamText({
model: codex('gpt-5', {
temperature: 0.7,
maxOutputTokens: 1000,
topP: 0.9,
reasoning: {
effort: 'medium',
summary: 'auto'
}
}),
prompt: 'Explain quantum computing',
});
gpt-5 - Latest GPT-5 modelgpt-4o - GPT-4 Optimizedgpt-4o-mini - GPT-4 Optimized Minio1 - OpenAI o1 reasoning modelo1-mini - OpenAI o1 miniNote: The Codex API only supports streaming responses. Use streamText() instead of generateText().
import { codex } from 'codex-ai-provider';
// Automatically uses ~/.codex/auth.json
const model = codex('gpt-4o');
import { createCodex } from 'codex-ai-provider';
const codex = createCodex({
useApiKey: true, // Uses OPENAI_API_KEY env var
baseURL: 'https://api.openai.com/v1',
});
import { createCodex } from 'codex-ai-provider';
const codex = createCodex({
apiKey: 'sk-...',
baseURL: 'https://api.openai.com/v1',
});
createCodex(options?: CodexProviderSettings)Creates a new Codex provider instance.
Options:
baseURL?: string - API endpoint (default: https://chatgpt.com/backend-api)apiKey?: string - Custom API keyuseApiKey?: boolean - Use OPENAI_API_KEY env varheaders?: Record<string, string> - Custom headersfetch?: FetchFunction - Custom fetch implementationcodex(modelId: string, settings?: CodexSettings)Creates a language model instance.
Settings:
temperature?: number - Sampling temperature (0.0-1.0)maxOutputTokens?: number - Maximum tokens to generatetopP?: number - Top-p samplingfrequencyPenalty?: number - Frequency penalty (-2.0 to 2.0)presencePenalty?: number - Presence penalty (-2.0 to 2.0)stopSequences?: string[] - Stop sequencesreasoning?: { effort?: 'low'|'medium'|'high', summary?: 'auto'|'none' } - Reasoning modeverbosity?: 'low'|'medium'|'high' - Response verbosityseed?: number - Seed for deterministic generationCodexAuthAuthentication utility class.
Methods:
validateAuth(): Promise<boolean> - Check if authentication is validgetAuthFilePath(): string - Get path to auth.jsongetAccessToken(): Promise<string> - Get current access tokengetAccountId(): Promise<string> - Get account IDimport { CodexAuth } from 'codex-ai-provider';
// Check authentication before making requests
const isValid = await CodexAuth.validateAuth();
if (!isValid) {
console.error('Please run "codex login" first');
process.exit(1);
}
// Handle API errors
try {
const result = await generateText({
model: codex('gpt-4o'),
prompt: 'Hello',
});
} catch (error) {
if (error.message.includes('Authentication')) {
console.error('Auth error:', error.message);
} else {
console.error('API error:', error.message);
}
}
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run examples
pnpm run example:simple # Basic text generation
pnpm run example:streaming # Streaming with tools
pnpm run example:auth # Check authentication
pnpm run example:refresh # Test token refresh
# Development mode
pnpm dev # Watch mode for development
pnpm typecheck # Type checking
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
AI SDK provider for ChatGPT Codex API
The npm package codex-ai-provider receives a total of 7 weekly downloads. As such, codex-ai-provider popularity was classified as not popular.
We found that codex-ai-provider demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.

Security News
Socket found a malicious postinstall hook across 700+ GitHub repos, including PHP packages on Packagist and Node.js project repositories.

Security News
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain