Codex

Use Case:

Suitable for users who want to use MaiToken models in the terminal or local Codex client for code understanding, code modification, and Agent tasks.
Codex custom model providers use the Responses protocol. Since MaiToken provides the Responses API, set Base URL to https://api.maitoken.net/v1 and Codex will automatically call /v1/responses.

1. Verify the Responses API Is Available

Select the test command for your OS 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.net/v1/responses \  -H "Authorization: Bearer $MAITOKEN_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model":"'"$MAITOKEN_MODEL"'","input":"Reply 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 OK only"  stream = $false} | ConvertTo-Json Invoke-RestMethod `  -Method Post `  -Uri "https://api.maitoken.net/v1/responses" `  -Headers $headers `  -ContentType "application/json" `  -Body $body
If the endpoint returns a normal response object or output text, you can proceed with configuration. If it returns 404, verify the exact path of the MaiToken Responses API first. Endpoints that only support Chat Completions cannot be used with this configuration.

2. macOS / Linux Configuration

  1. Check Codex: Open a terminal and run codex --version. If the command is not found, install Codex according to its installation instructions first.

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

export MAITOKEN_API_KEY="<Your MaiToken Key>"

This environment variable expires when you close the current terminal window. Using temporary environment variables during testing is safer.

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

You must edit the global configuration file in your user home directory—do not write this into a project's .codex/config.toml.

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

  2. Launch Codex: Navigate to a test project directory and run codex. After startup, confirm that the current model shows the Model ID you configured.

10.3 Windows PowerShell Configuration

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

Paste the following into the configuration file:

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

How to Test After Setup

  1. Test Basic Chat: Enter "Reply OK only". Receiving a normal reply confirms that your API Key, Base URL, and Model ID are basically correct.

  2. Test Project Reading: Open a test project and enter "Please list the top-level files in the current directory first without modifying any files."

  3. Test Agent: After receiving the directory listing, ask the Agent to create a new file named test-maitoken.txt containing hello. Do not run initial tests on a real production project.

Troubleshooting

Issue Suggested Fix
401 / Unauthorized Ensure MAITOKEN_API_KEY is set in the same terminal window where you launch codex, and check for extra spaces before or after the Key.
404 /responses Make sure base_url ends at /v1. If your platform's Responses API uses a path other than /v1/responses, adjust it according to the actual 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 replies work but tool calling fails The model or gateway may not fully support Responses tool calling—switch to a model that supports coding Agents and tool calling.