Integrate the Martian Gateway With Codex

This document describes how to set up OpenAI Codex CLI to route all your LLM requests through the Martian Gateway.

Ensure you have your Martian API key from the Martian Dashboard before continuing.

Prerequisites

Ensure you have Codex installed. See the Codex quickstart for more options, or use one of the following:

npm install -g @openai/codex

Configuration

Step 1: Store Your API Key

Add your Martian API key to your shell profile (~/.zshrc, ~/.bashrc, etc.) or a secure location like a .env file:

# Add to ~/.zshrc, ~/.bashrc, etc.
export MARTIAN_API_KEY="your-martian-api-key"

Replace your-martian-api-key with your actual Martian API key from the Martian Dashboard.

Then reload your shell:

source ~/.zshrc  # or source ~/.bashrc etc.

Step 2: Configure the Martian Provider

Create or edit ~/.codex/config.toml:

Current Codex versions use the Responses API. Martian's provider must therefore use wire_api = "responses".

[model_providers.martian-responses]
name = "Martian /responses"
base_url = "https://api.withmartian.com/v1"
env_key = "MARTIAN_API_KEY"
wire_api = "responses"

Step 3: Create Model Profiles

Codex 0.134.0 and later load profiles from separate files. Create a profile for each model you want to use:

model = "openai/gpt-5.2"
model_provider = "martian-responses"

Add [features] with multi_agent = false to ~/.codex/config.toml if your selected model or Martian's /responses implementation does not support Codex's multi-agent tools:

[features]
multi_agent = false

The provider stays in the shared config.toml; each profile file contains only its model-specific settings. See the Codex profiles documentation and Available Models.

Start Using Codex

Navigate to your project directory and start Codex with a profile:

cd your-project
codex --profile gpt-5.2

Codex will now route all requests through the Martian Gateway. You can switch between profiles using the --profile flag or the /model command within Codex.


Next Steps

View Available Models

Browse 200+ AI models from leading providers with real-time pricing.

Read more

View Other Integrations

Explore other ways to integrate the Martian Gateway with your development workflow.

Read more