Codex
OpenAI's Codex agent for AI-assisted coding
Codex is OpenAI's coding agent, powered by GPT models. It's fast, capable, and integrates well with the OpenAI ecosystem.
Overview
| Feature | Details |
|---|---|
| Provider | OpenAI |
| CLI Tool | codex |
| Auth Methods | API key, ChatGPT Plus/Pro subscription |
| Strengths | Speed, broad knowledge, tool use |
Authentication
API Key
- Get an API key from OpenAI Platform
- Add to Sesame:
- Per-user: Settings → API Keys → OpenAI
- System-wide: Set
OPENAI_API_KEYenvironment variable
Subscription (ChatGPT Plus/Pro)
Use your ChatGPT Plus ($20/mo) or ChatGPT Pro ($200/mo) subscription:
-
Enable device code auth in ChatGPT security settings
-
Install the Codex CLI:
npm install -g @openai/codex -
Run the login command:
codex login --device-auth -
Complete the authentication flow in your browser
-
Copy the contents of
~/.codex/auth.json -
In Sesame: Avatar → Agent Credentials → Codex → Enter tokens
Environment Variables
| Variable | Description |
|---|---|
OPENAI_API_KEY | API key for OpenAI |
Capabilities
Codex can:
- Generate code from natural language
- Complete and edit existing code
- Explain code functionality
- Convert between programming languages
- Write unit tests
- Debug and fix issues
Best Practices
Effective Prompts
Good: "Create a React component that displays a paginated
table of users with sorting and filtering capabilities."
Bad: "Make a table"Iterative Development
Codex works well with iterative prompts:
- Start with the basic structure
- Add features incrementally
- Refine based on output
Code Style
Specify your preferences:
"Following the project's ESLint configuration, add error
handling to all API routes with proper TypeScript types."Troubleshooting
"Authentication failed"
- API key: Verify at OpenAI Platform
- Subscription: Ensure device code auth is enabled in ChatGPT settings
- Re-run
codex login --device-authif needed
"Rate limited"
- API has rate limits based on your tier
- Subscription users check usage dashboard
- Wait and retry, or upgrade your plan
"Context length exceeded"
- GPT-4 has 128K token context
- For very large codebases, focus on specific files
- Use targeted prompts
Device auth not working
- Go to ChatGPT security settings
- Ensure "Device code authentication" is enabled
- Try logging out and back in to ChatGPT
- Re-run
codex login --device-auth
CLI Reference
# Basic usage
codex "Your prompt here"
# Interactive mode
codex --interactive
# Specify model
codex --model gpt-4o "prompt"Pricing
| Method | Cost |
|---|---|
| API (GPT-4o) | ~$2.50 / 1M input, ~$10 / 1M output |
| API (GPT-4o-mini) | ~$0.15 / 1M input, ~$0.60 / 1M output |
| ChatGPT Plus | $20/month |
| ChatGPT Pro | $200/month (higher limits) |
For current pricing, see OpenAI Pricing.