Codex

Use Cases

Suitable for users who want to use MaiToken models in the terminal or Codex desktop app for code understanding, code modification, and Agent tasks.
Custom model providers in Codex use the Responses protocol. MaiToken provides a Responses API, so set the Base URL to https://api.maitoken.com/v1 . Codex will automatically send requests to /v1/responses.

1. Verify That the Responses API Is Available

Select the corresponding test command for your operating system, and replace the MaiToken Key and Model ID with your actual values.

macOS / Linux
export MAITOKEN_API_KEY="<your MaiToken Key>"export MAITOKEN_MODEL="<Model ID>" curl -sS https://api.maitoken.com/v1/responses \  -H "Authorization: Bearer $MAITOKEN_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model":"'"$MAITOKEN_MODEL"'","input":"Reply with OK only","stream":false}'
Windows PowerShell
$env:MAITOKEN_API_KEY="<your MaiToken Key>"$env:MAITOKEN_MODEL="<Model ID>" $headers = @{  Authorization = "Bearer $env:MAITOKEN_API_KEY"} $body = @{  model  = $env:MAITOKEN_MODEL  input  = "Reply with OK only"  stream = $false} | ConvertTo-Json Invoke-RestMethod `  -Method Post `  -Uri "https://api.maitoken.com/v1/responses" `  -Headers $headers `  -ContentType "application/json" `  -Body $body
If the API returns a valid response object or generated text, you can continue with the configuration. If it returns 404, verify the correct path for the MaiToken Responses API. An endpoint that only supports Chat Completions cannot be used for this configuration.

2. macOS / Linux Configuration

  1. Check Codex: Open a terminal and run codex --version. If the command is not found, install Codex by following the Codex installation instructions.

  2. Set the API Key for the Current Session: Run the following command:

export MAITOKEN_API_KEY="<your MaiToken Key>"

The environment variable will expire after you close the current terminal window. Using a temporary environment variable is safer during testing.

  1. Create the Configuration Directory: Run the following command:
mkdir -p ~/.codex
  1. Open the Global Configuration File: Run the following command:
nano ~/.codex/config.toml

You must edit the global configuration file in your user directory. Do not create .codex/config.toml inside the project directory.

  1. Paste the Configuration: Paste the following content into config.toml, and replace <Model ID> with the exact ID shown in the model restriction list.
model = "<Model ID>"model_provider = "maitoken" [model_providers.maitoken]name = "MaiToken"base_url = "https://api.maitoken.com/v1"env_key = "MAITOKEN_API_KEY"wire_api = "responses"
  1. Save the File: In nano, press Control + O, press Enter to confirm, and then press Control + X to exit.

  2. Start Codex: Open a test project directory and run codex. After Codex starts, confirm that the current model matches the Model ID you entered.

10.3 Windows PowerShell Configuration

  1. Set the API Key: Open PowerShell and run the following command:
$env:MAITOKEN_API_KEY="<your MaiToken Key>"
  1. Create the Configuration Directory: Run the following command:
New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex"
  1. Open the Configuration File: Run the following command:
notepad "$env:USERPROFILE\.codex\config.toml"

Paste the following content into the configuration file:

model = "<Model ID>"model_provider = "maitoken" [model_providers.maitoken]name = "MaiToken"base_url = "https://api.maitoken.com/v1"env_key = "MAITOKEN_API_KEY"wire_api = "responses"
  1. Start Codex: Save the configuration file, return to the same PowerShell window in which you set the API Key, open a test project, and run codex.
Field Value
Configuration File macOS/Linux: ~/.codex/config.toml; Windows: %USERPROFILE%\.codex\config.toml
model <Model ID>
base_url https://api.maitoken.com/v1
env_key MAITOKEN_API_KEY
wire_api responses

Test the Configuration

  1. Test a Basic Conversation: Enter “Reply with OK only.” If you receive a valid response, the API Key, Base URL, and Model ID are configured correctly.

  2. Test Project Reading: Open a test project and enter “List the files in the current directory at the first level only. Do not modify any files.”

  3. Test Agent Capabilities: After receiving the directory listing, ask the Agent to create a file named test-maitoken.txt and write hello into it. Do not use a real production project for testing.

Common Issues

Issue Solution
401 / Unauthorized Confirm that MAITOKEN_API_KEY was set in the same terminal window used to start codex, and check the Key for leading or trailing spaces.
404 /responses Confirm that base_url ends at /v1. If the platform's Responses API path is not /v1/responses, adjust it according to the API documentation.
model_not_found Copy the exact Model ID from the model restriction list and confirm that the model supports the Responses format.
Basic responses work but tool calls fail The model or gateway may not fully support Responses tool calling. Switch to a model that supports code Agent tasks and tool calling.