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.| Scenario | What it is good for |
|---|---|
| CI/CD automation | Trigger code checks, root-cause analysis, fix suggestions, or structured reports in a pipeline. |
| Automated code review | Run review tasks in GitHub Actions, GitLab CI/CD, Azure DevOps Pipelines, or Jenkins, then publish findings as code comments. |
| Internal developer tools | Add Codex to internal platforms for migration plans, repository analysis, or build failure diagnosis. |
| In-app engineering assistant | Start Codex threads from your application and let Codex handle multi-step engineering tasks. |
| Structured output workflows | Ask Codex for JSON schema output, then call your SCM, Slack, ticketing system, or internal APIs. |
Install the SDK
Install Codex SDK in your project.Copy connection values
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.