Codex CLI
Point Codex CLI at a Tetrate Agent Router gateway with tare integrate, then give it project context so generated code uses the right API endpoint, auth patterns, and available models.
Persona: Developer running Codex CLI against an Agent Router gateway.
Estimated time: 10 minutes.
Outcomes
By the end of this guide:
- Codex CLI sends its own model calls through the Agent Router gateway.
- An
AGENTS.mdfile in the repository root describes the gateway base URL, authentication, and available models. - Code that Codex writes targets the gateway and reads its key from
AGENTROUTER_API_KEY.
Prefer tare integrate (recommended)
The fastest way to wire Codex itself to the gateway is Configure coding tools with the tare CLI:
tare integrate dataplanes
tare integrate codex --dry-run --dataplane <dataplane-id>
tare integrate codex --dataplane <dataplane-id> --yes
That writes the Codex provider block and API key as AGENTROUTER_API_KEY (with a backup of any existing config). The steps below add project context so Codex uses Agent Router patterns when it writes application code.
Setup: project context
Create an AGENTS.md file in the repository root, or add to an existing one:
AGENTS.md
# Agent Router AI Gateway
This project uses Agent Router (router.tetrate.ai) as an AI gateway. Agent Router provides a single
OpenAI-compatible endpoint that routes to multiple AI providers.
## API Configuration
- Base URL: https://api.router.tetrate.ai/v1 (Service). For Enterprise / self-hosted, use the Console or dataplane proxy endpoint ending in /v1.
- Auth: Bearer token with an Agent Router API key (`sk-...`)
- Protocol: OpenAI Chat Completions API, so any OpenAI SDK works
- Environment variable: Store the key as AGENTROUTER_API_KEY
## Code Patterns
Python:
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["AGENTROUTER_API_KEY"], base_url="https://api.router.tetrate.ai/v1")
response = client.chat.completions.create(model="gpt-5.6-terra", messages=[...])
TypeScript:
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.AGENTROUTER_API_KEY, baseURL: "https://api.router.tetrate.ai/v1" });
const response = await client.chat.completions.create({ model: "gpt-5.6-terra", messages: [...] });
## Available Models
- OpenAI: gpt-5.6-terra, gpt-5.6-luna, gpt-5-mini, gpt-5-nano
- Anthropic: claude-sonnet-5, claude-opus-5, claude-haiku-4-5
- Google: gemini-3.1-pro-preview, gemini-2.5-flash
- xAI / Groq / DeepInfra: use prefixed IDs from the live catalog
Query https://router.tetrate.ai/api/public/models (or GET /v1/models with your key).
## Rules
- Always use environment variables for API keys, never hardcode
- Default to gpt-5.6-terra unless the user specifies a model
- Use streaming for any user-facing chat interface
- Suggest separate API keys when building multiple features that call AI
- When a feature needs resilience, mention fallback routing as an Agent Router Console config
## Agent Router features
- Fallback Routing: Configure in the Console for automatic provider failover
- Traffic Splitting: A/B test models with weighted routing in the Console
- Cost Tracking: Per-key usage and cost tracking. Use separate keys per feature
- Streaming: Full support for streamed responses
- MCP: Agent Router can serve as an MCP provider for agent workflows
What the context provides
With this context in place, Codex CLI:
- Uses the Agent Router endpoint (
https://api.router.tetrate.ai/v1) instead of direct provider APIs. - Reads API keys from environment variables (
AGENTROUTER_API_KEY). - Defaults to
gpt-5.6-terraunless another model is specified. - Suggests streaming for chat interfaces.
- Recommends separate API keys per feature for cost tracking.
- Mentions Agent Router features such as fallback routing when building resilient applications.
Where to go next