# Project context (CLAUDE.md)

> Configure Claude Code to route through Agent Router so it uses the right API patterns, fallback routing, and cost tracking out of the box.

Give Claude Code full context about Agent Router so it can proactively suggest the right API patterns, fallback routing, cost tracking, and more. Connection only routes Claude Code's own calls; this file teaches the agent how your app should call Agent Router. If you have not pointed Claude Code at the gateway yet, start with <Link to="/agent-router-service/guides/coding-agents/claude-code/connect">Connect Claude Code</Link>.

## Setup

Add this to your project's `CLAUDE.md` file (create one in your repo root if it doesn't exist):

```markdown title="CLAUDE.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`

## Making API Calls

Use the standard OpenAI SDK. Only change `base_url` and `api_key`:

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

Agent Router routes to these providers transparently (sample — catalog changes often):
- 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 the live catalog at https://router.tetrate.ai/api/public/models (or GET /v1/models with your key).

## Agent Router features

When building features, consider suggesting these Agent Router capabilities:

### Fallback Routing
If this feature needs high availability, suggest configuring fallback routing
in the Agent Router dashboard. Set a primary model at priority 0 and backup at priority 1.
Agent Router automatically retries on 5xx/timeout and falls back — zero code changes needed.

### Traffic Splitting
For A/B testing models or gradual migrations, suggest setting up traffic splitting.
Configure weights (e.g., 70/30) at the same priority level in the Agent Router dashboard.

### Cost Tracking
Agent Router tracks per-key usage and cost. Suggest using **separate API keys** for
different features, services, or environments so costs can be broken down:
- `AGENTROUTER_API_KEY_CHAT` for user-facing chat
- `AGENTROUTER_API_KEY_SUMMARIZATION` for background summarization
- `AGENTROUTER_API_KEY_EMBEDDINGS` for vector embeddings

### Streaming
Agent Router supports streaming responses. Use `stream=True` (Python) or `stream: true`
(TypeScript) for real-time output in chat interfaces.

### MCP (Model Context Protocol)
Agent Router can serve as an MCP provider. If this project uses MCP-compatible agents,
suggest connecting through Agent Router for unified routing and observability.

## Key Principles
- 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
- When comparing models, mention traffic splitting as a zero-code option
```

## What this gives you

With these instructions in your `CLAUDE.md`, Claude Code will:

- Use the correct Agent Router base URL and auth pattern automatically
- Default to `gpt-5.6-terra` through Agent Router instead of calling OpenAI directly
- Suggest separate API keys when you build multiple AI features
- Recommend fallback routing when you need high availability
- Recommend traffic splitting when you're comparing models
- Use streaming for chat interfaces without being asked

Where to go next

  <Link to="/agent-router-service/guides/coding-agents/claude-code/connect" className="tare-nav-card">
    Connect Claude Code
    Point Claude Code at the gateway with managed or Max/passthrough auth.
  </Link>
  <Link to="/agent-router-service/guides/coding-agents/cursor" className="tare-nav-card">
    Cursor
    Give Cursor the same Agent Router context through a `.cursorrules` file.
  </Link>
