Node/npm and Codex CLI
Run node -v and npm -v. If missing, install Node.js first, then run npm install -g @openai/codex@latest to update Codex CLI.
CODEX CONFIGURATION
Register, fund the account, create an API key, check the local environment, configure Codex, verify Usage, and troubleshoot the 42tokens OpenAI-compatible Responses API.
This public guide only shows placeholders; real API keys are only visible on the signed-in API Keys page. Log out of any old Codex account, fully quit the app, then restart after setup.
Follow the real setup path: prepare account credit, create a key, then use import or manual Codex configuration.
Create a 42tokens account and open the console.
STEP 01Make sure the account or subscription has usable balance; insufficient balance will make Codex calls fail.
STEP 02Create a key on API Keys and confirm it belongs to an available OpenAI group.
STEP 03Prefer the one-click import on API Keys; for audited setup, write config.toml and auth.json manually. No environment variable is needed.
STEP 04Fully quit Codex, restart it, then verify with /v1/models, a test prompt, and Usage records.
STEP 05Check the local runtime first, then choose one-click import, manual setup, or file-level review, all through the OpenAI-compatible API.
Run node -v and npm -v. If missing, install Node.js first, then run npm install -g @openai/codex@latest to update Codex CLI.
Run codex once in a terminal. If ~/.codex or %USERPROFILE%\.codex does not exist, let the client create it before writing config.
Back up existing config, then write config.toml and auth.json under the user-level .codex directory. Put the real user key from API Keys in auth.json.
These snippets come from the same generator as the Use API Key dialog on API Keys: Claude Code uses the API address without /v1 and Codex uses /v1. Sign in and pick a model your group allows and your shell to get the version with your real key.
Terminal
claude --settings '{"env":{"ANTHROPIC_BASE_URL":"https://api.42tokens.xyz","ANTHROPIC_AUTH_TOKEN":"<42tokens API key>","ANTHROPIC_MODEL":"claude-opus-5-5","ANTHROPIC_DEFAULT_OPUS_MODEL":"claude-opus-5-5","ANTHROPIC_DEFAULT_SONNET_MODEL":"claude-opus-5-5","ANTHROPIC_DEFAULT_HAIKU_MODEL":"claude-opus-5-5"}}'~/.codex/config.toml
model_provider = "42tokens"
model = "claude-opus-5-5"
review_model = "claude-opus-5-5"
disable_response_storage = true
[model_providers.42tokens]
name = "42tokens"
base_url = "https://api.42tokens.xyz/v1"
wire_api = "responses"
supports_websockets = false
requires_openai_auth = true~/.codex/auth.json
{
"OPENAI_API_KEY": "<42tokens API key>"
}When troubleshooting or auditing, work file by file. Do not confuse a project-level .codex directory with the user-level config directory.
Use ~/.codex on macOS/Linux and %USERPROFILE%\.codex on Windows. If it does not exist, run codex once first.
FILE 01Copy config.toml and auth.json to timestamped backup files before editing.
FILE 02Keep model_provider = "42tokens", base_url = "https://api.42tokens.xyz/v1", wire_api = "responses", supports_websockets = false, and requires_openai_auth = true.
FILE 03Store only OPENAI_API_KEY, using a real user key generated on 42tokens API Keys. Public guide keys are placeholders.
FILE 04Save config.toml and auth.json, then fully quit and restart Codex to load the configuration.
FILE 05After Codex is configured, continue with Web chat, Responses, and Image APIs.
Useful for checking model behavior, prompts, and balance without a local Codex runtime.
Codex uses wire_api = "responses"; applications can also call /v1/responses directly.
Use /v1/images/generations for generation and /v1/images/edits for edits; use /v1/responses for image tools inside text workflows.
A common question is "which models can my account use?" The most accurate answer comes from /v1/models, which only returns models the current key can actually call.
Run curl https://api.42tokens.xyz/v1/models -H "Authorization: Bearer <42tokens API key>". It returns the OpenAI list shape {object:"list", data:[{id, owned_by, ...}]}; the id values are exactly the models this key can call, already filtered by the group and platform whitelist.
CHECK 01After signing in, visit /available-channels to see the models, groups, and pricing multipliers your account supports. It redirects to /login when not signed in.
CHECK 02Use /keys to create or manage a key. A key without an assigned group has no model quota, so confirm the group is set.
CHECK 03If a model id is absent from /v1/models, the key's group does not include it. Check /available-channels or contact support.
CHECK 04Base URL is https://api.42tokens.xyz/v1, authenticated with Authorization: Bearer. The endpoints below are the OpenAI-compatible routes actually served today.
Root-level aliases without /v1 also work, but configure clients with /v1 for consistency.
Check in this order to isolate key, endpoint, model, or client-cache issues.
A key without an assigned group cannot use model quota.
CHECK 01Codex needs the OpenAI-compatible API root path; import and config generators append it automatically.
CHECK 02If ~/.codex or %USERPROFILE%\.codex does not exist, run codex once so the client creates it.
CHECK 03If Codex / ChatGPT is still signed in with an old account, sign out first. Fully restart Codex after changing key, model, or Base URL.
CHECK 04Usage is the final verification. A matching request should appear with model, request count, and spend.
CHECK 05These cover common OpenAI-compatible Codex setup issues.
Call GET /v1/models (curl https://api.42tokens.xyz/v1/models -H "Authorization: Bearer <42tokens API key>"); the returned id values are the models this key can use. You can also sign in and open /available-channels to see supported models and pricing visually.
Prefer the /v1 endpoint for Codex OpenAI-compatible config. The guide and modal generator append /v1 automatically.
Confirm Node.js and npm are available, then install or update Codex CLI with npm install -g @openai/codex@latest. Run codex once before setup so the user-level .codex directory exists.
Use ~/.codex on macOS/Linux and %USERPROFILE%\.codex on Windows. On macOS, press Command+Shift+G in Finder and enter ~/.codex. On Windows, press Win+R and enter %userprofile%\.codex. If the directory does not exist, run codex once first, then create config.toml and auth.json if needed.
Codex has reserved meanings for built-in provider ids. This guide uses 42tokens as a custom provider to avoid confusion with official OpenAI config.
Check account balance, order status, or redeemed credit first, then confirm the API key group enables the target OpenAI model. Use /v1/models before changing model IDs.
No. Standard Responses mode is enough. WebSocket is an advanced option, and the Codex Desktop Fast toggle still depends on client capability detection.
Check terminal font and encoding first. If it still happens, press Win+R, run intl.cpl, open the Administrative tab, choose Change system locale, enable Unicode UTF-8 for worldwide language support, save, reboot, and open Codex again.
Keep base_url ending in /v1, for example https://api.42tokens.xyz/v1; do not put /responses in base_url. From the exact machine or container that runs the failing task, curl both /v1/models and /v1/responses. If /v1/models also returns connection refused, check DNS, outbound 443, firewall rules, HTTP(S)_PROXY/NO_PROXY, CLI sandboxing, or container networking. If image workers work but vision/review workers fail, compare proxy, DNS, and API key inheritance between those workers.
The guide asks you to back up config.toml and auth.json first. Do not delete old files; restore from the backup if needed.
Rotate keys by editing auth.json only; no environment variable needs updating on any OS. Change service URLs by updating base_url with /v1, and check /v1/models before updating both model and review_model.
Global instructions should live in the AGENTS.md file that Codex reads; restart Codex or the editor after changing it. Web search is a client capability. If your Codex version supports it, enable it using Codex config semantics; 42tokens only handles OpenAI-compatible API forwarding and Usage records.
Restart Codex, send a test prompt, and confirm Model provider is 42tokens - https://api.42tokens.xyz/v1, Account is API key configured, and a matching request appears on Usage.
42tokens keeps image support on OpenAI-compatible paths: use /v1/images/generations for image generation and /v1/images/edits for edits. When a text workflow calls an image tool, use /v1/responses with an image_generation tool. Images are returned in data[0].b64_json by default; decode the Base64 payload into a PNG. Set n for multiple images, and keep uploaded edit inputs under 50MB. The API key group must enable allow_image_generation, otherwise the API returns Image generation is not enabled for this group. curl https://api.42tokens.xyz/v1/images/generations \ -H "Authorization: Bearer <42tokens API key>" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-image-2", "prompt": "A clean product rendering of an AI API dashboard", "size": "1024x1024", "quality": "high", "response_format": "b64_json" }' curl https://api.42tokens.xyz/v1/images/edits \ -H "Authorization: Bearer <42tokens API key>" \ -F "model=gpt-image-2" \ -F "image[]=@input.png" \ -F "prompt=Replace the background with a clean office scene" \ -F "size=1024x1024" \ -F "quality=high" \ -F "response_format=b64_json" curl https://api.42tokens.xyz/v1/responses \ -H "Authorization: Bearer <42tokens API key>" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.5", "input": "Generate a product hero image for an AI API gateway.", "tools": [ { "type": "image_generation", "model": "gpt-image-2", "size": "1024x1024", "quality": "high" } ], "tool_choice": { "type": "image_generation" } }' import OpenAI from "openai"; import { writeFileSync } from "fs"; const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: "https://api.42tokens.xyz/v1", }); const result = await client.images.generate({ model: "gpt-image-2", prompt: "A clean product rendering of an AI API dashboard", size: "1024x1024", quality: "high", response_format: "b64_json", }); writeFileSync("out.png", Buffer.from(result.data[0].b64_json, "base64"));
42tokens
Sign in, open API Keys, copy the real key or use import, then restart Codex.