Codex.
Prerequisites
- You have completed Create an account.
- You have completed Get an API Key.
- Node.js 18 or later is installed.
- Codex CLI is installed and
codex --versionworks. - You have a TypeScript or JavaScript project.
Use cases
Codex SDK is useful when you need to place Codex inside an existing engineering workflow.
If you only want to use 4096bytes from a local terminal, start with Codex CLI. Use the SDK when you need to control Codex from code.
Install the SDK
Install Codex SDK in your project.Copy connection values
1
Open API Keys
Open the dashboard and go to API Keys.
2
Choose an API Key
Find the API Key you want to use with the SDK, then click Use key.
3
Copy SDK values
Copy the Base URL, API Key, and model name shown in the dashboard. Replace every placeholder in the example with the live dashboard value.
Configure environment variables
Store the API Key, Base URL, and model name in server-side environment variables..env file, write:
Initialize Codex
Create aCodex instance in server-side code. Pass apiKey and baseUrl to the constructor.
CODEX_API_KEY to the API Key you created in the dashboard. Copy CODEX_BASE_URL and CODEX_MODEL from the dashboard.
Verify the connection
Start with a read-only prompt.Code review example
OpenAI’s official cookbook shows an automated code review workflow. The workflow triggers Codex in a CI/CD runner, has Codex read the PR diff, asks for structured JSON schema output, and then calls the SCM API to publish inline comments. You can use this pattern for:- Automated PR review.
- Review workflows for on-premise repositories or non-GitHub SCMs.
- Creating tickets, sending Slack notifications, or updating internal quality dashboards from structured results.
Common issues
Which Base URL should I use
Which Base URL should I use
Use the current Base URL shown in the dashboard. Do not copy a fixed address from docs, screenshots, or old config.
Which model name should I use
Which model name should I use
Use the model name shown in the dashboard. Copy the full value, including casing, hyphens, and version suffixes.
Can I call it from browser frontend code
Can I call it from browser frontend code
This is not recommended. Frontend code exposes the API Key. Call the SDK from server-side code, backend jobs, or controlled automation.
Authentication failed
Authentication failed
Check that the API Key was copied completely, the runtime can read the environment variables, and the Base URL belongs to the same dashboard account or environment.