Skip to main content

Codex CLI

Point Codex CLI at your Agent Router gateway with tare integrate, then give it project context so generated code uses the right API endpoint, auth patterns, and available models.


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 a AGENTS.md file in your project 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 — 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 dashboard config

## Agent Router features
- Fallback Routing: Configure in Admin dashboard for automatic provider failover
- Traffic Splitting: A/B test models with weighted routing in the dashboard
- 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 Codex will do

With this context, Codex CLI will:

  • Use the Agent Router endpoint (https://api.router.tetrate.ai/v1) instead of direct provider APIs
  • Use environment variables for API keys (AGENTROUTER_API_KEY)
  • Default to gpt-5.6-terra unless you specify a different model
  • Suggest streaming for chat interfaces
  • Recommend separate API keys per feature for cost tracking
  • Mention Agent Router features like fallback routing when building resilient applications