# Cursor

> Configure Cursor to route through Agent Router so it generates the right API patterns and uses Agent Router features and best practices.

Give Cursor full context about Agent Router so it generates the right API patterns, suggests Agent Router features, and uses best practices.

## Setup

Create a `.cursorrules` file in your project root:

```text title=".cursorrules"
# Agent Router AI Gateway Context

This project uses Agent Router (router.tetrate.ai) as an AI gateway that provides a single
OpenAI-compatible endpoint routing to multiple AI providers.

## API Setup
- 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 using Agent Router API key (`sk-...`)
- Protocol: OpenAI Chat Completions API
- Store key as environment variable: 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 them
- Default to gpt-5.6-terra unless the user specifies a different model
- Use stream=True / stream: true for any user-facing chat interface
- Use separate Agent Router API keys for different features/services for cost breakdown:
  AGENTROUTER_API_KEY_CHAT for chat, AGENTROUTER_API_KEY_SUMMARIZATION for summarization, etc.

## Agent Router features (suggest when relevant)
- Fallback Routing: Configure in Agent Router dashboard for automatic provider failover.
  Set primary model at priority 0, backup at priority 1. Zero code changes.
- Traffic Splitting: A/B test models with weighted routing. Configure weights
  at same priority level in dashboard.
- Cost Tracking: Per-key usage tracking. Use separate keys per feature.
- Streaming: Full support for streamed responses through Agent Router.
- MCP: Agent Router can serve as an MCP provider for agent-compatible workflows.
```

## What This Gives You

With `.cursorrules` in your project, Cursor will:

- Generate code with the correct Agent Router base URL and auth pattern
- Use OpenAI SDK patterns (not raw HTTP) by default
- Suggest separate API keys when you're building multiple AI features
- Add streaming automatically for chat-style interfaces
- Know about fallback routing and traffic splitting as configuration options

Where to go next

  <Link to="/agent-router-service/guides/coding-agents/claude-code" className="tare-nav-card">
    Claude Code
    Connect Claude Code to the gateway, or add a <code>CLAUDE.md</code> for Agent Router patterns.
  </Link>
  <Link to="/agent-router-service/guides/coding-agents/codex" className="tare-nav-card">
    Codex CLI
    Configure OpenAI's Codex CLI to route through Agent Router.
  </Link>
