# Make an AI API call

> Make a first AI API call through Agent Router: one OpenAI-compatible endpoint for every model, with automatic failover and usage tracking.

Agent Router Enterprise routes any model request through a single endpoint. Agent Router exposes one API that works with every model (OpenAI, Anthropic, Google, and others), with automatic failover, usage tracking, and cost controls.

:::info
All code snippets in this guide are Python. Any OpenAI SDK is supported; Python is not required.
:::

## 1. Get an API key

This step obtains the credential that authenticates every call. Each key identifies the calling consumer and carries the routing policy, budgets, and usage tracking attached to it, so a request is both authorised and governed by the key it presents.

Sign up at [router.tetrate.ai](https://router.tetrate.ai) and create an API key from the dashboard. The key appears under **Settings → API Keys**.

An API key has the form `sk-...` and is required for every request. Keep it secure.

## 2. Make the first request

This step confirms that the credential and endpoint work by sending a single chat completion. Because Agent Router implements the OpenAI API, an existing OpenAI SDK needs only two changes: the base URL and the API key. The request names a model, Agent Router resolves that model to a provider, forwards the call with the right credentials, and returns a standard chat completion response. No provider-specific SDK or code path is involved.

Agent Router is OpenAI-compatible. Point any OpenAI SDK at `https://api.router.tetrate.ai/v1`.

```python title="Python"
from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="https://api.router.tetrate.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{"role": "user", "content": "What is Agent Router?"}],
)

print(response.choices[0].message.content)
```

:::tip
Replace `gpt-5.6-terra` with any model in Agent Router's catalog, such as `claude-sonnet-5` or `gemini-2.5-flash`. Agent Router routes to the right provider automatically. To see which models are routable for your API key, call `GET /v1/models` or `client.models.list()` — see [Models API](/reference/supported-apis#models-api-v1models).
:::

## 3. Stream responses

This step returns the response incrementally instead of in a single block. Setting `stream=True` makes Agent Router forward tokens as the provider generates them, which lowers the time to first token and suits chat-style interfaces. The streamed chunks use the OpenAI event format, so client code written for OpenAI streaming works without modification.

Add `stream: true` for real-time token streaming. This works identically to the OpenAI streaming API.

```python title="Python"
stream = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{"role": "user", "content": "Explain Agent Router in one paragraph."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

## 4. Generate embeddings

This step produces vector embeddings for search, retrieval, or clustering workloads. Embeddings convert text into numeric vectors that capture meaning, and they are requested through the same client and endpoint as chat completions: only the method and model change. The same routing, usage tracking, and cost controls apply.

Agent Router routes embedding requests the same way: one endpoint, any provider.

```python title="Python"
response = client.embeddings.create(
    model="text-embedding-3-small",
    input="What is an AI gateway?",
)

print(f"Dimensions: {len(response.data[0].embedding)}")
```

## 5. Generate images

This step generates images through the same gateway used for text. An image request reaches the provider through the identical endpoint and key, and the response returns a URL to the generated image. Cost is recorded per image by size, quality, and count, and appears in the same usage reports as chat and embedding spend.

Image generation is routed through Agent Router with cost tracking by size, quality, and count.

```python title="Python"
response = client.images.generate(
    model="dall-e-3",
    prompt="A futuristic city powered by AI, digital art",
    size="1024x1024",
)

print(response.data[0].url)
```

## Use the tare CLI and typed SDKs

The steps above use a generic OpenAI SDK pointed at the gateway. Agent Router also ships the `tare` CLI for minting keys and typed SDKs for Go, Python, and TypeScript, each with a runnable `examples/quickstart`. This path suits teams that prefer a typed client and bundled examples over raw HTTP.

All downloads are public, no sign-in required. Substitute the placeholders as follows: replace `<version>` with the version shown on the [SDKs](https://sdk.tetrate.ai/sdks.html) page, `<keyid>.<secret>` with a key minted below, and `api.<your-domain>` with the gateway host for the deployment.

### Install the CLI and mint a key

`tare` is the official Agent Router CLI and the fastest way to verify reach.

```bash
curl -fsSL https://tare.tetrate.ai/tools/install.sh | bash
tare --version
```

Authenticate, then create a long-lived key the SDKs use as `AGENTROUTER_API_KEY` (the `secret` field is shown exactly once):

```bash
tare api login --issuer https://idp.example.com
tare api whoami
tare api keys create --name quickstart
```

See the [TARE CLI reference](/reference/tare-cli/) for the available commands.

### Download and run a typed SDK

Each SDK tarball ships a runnable `examples/quickstart` so a first call needs no copied snippets. Download from the public stable channel, install from the local file (no public registry), then run the example.

#### Go

```bash
curl -fLO https://tare.tetrate.ai/tools/sdks/stable/agentrouter-go-<version>.tar.gz
mkdir -p third_party && tar -xzf agentrouter-go-<version>.tar.gz -C third_party/

# go.mod:
require github.com/tetrateio/agentrouter-go v0.1.0
replace github.com/tetrateio/agentrouter-go => ./third_party/agentrouter-go-<version>

go mod tidy
```

From the extracted SDK root: `go run ./examples/quickstart`.

#### Python

```bash
curl -fLO https://tare.tetrate.ai/tools/sdks/stable/agentrouter-python-<version>.tar.gz
pip install ./agentrouter-python-<version>.tar.gz
```

The sdist unpacks `examples/quickstart` next to the package: `python examples/quickstart/quickstart.py`.

#### TypeScript

```bash
curl -fLO https://tare.tetrate.ai/tools/sdks/stable/agentrouter-typescript-<version>.tgz
npm install ./agentrouter-typescript-<version>.tgz
```

From the extracted SDK root run `bun install` once, then `cd examples/quickstart && bun install && bun run quickstart.ts`.

#### curl

No SDK needed, call the API directly with the key:

```bash
export AGENTROUTER_API_KEY=<keyid>.<secret>
curl -sS https://api.<your-domain>/v1/me \
  -H "Authorization: Bearer ${AGENTROUTER_API_KEY}"
```

Where to go next

  <Link to="/agent-router-service/quickstarts/build-a-chat-app" className="tare-nav-card">
    Build a chat app
    Turn the single call into a streaming, multi-turn chat application with failover.
  </Link>
  <Link to="/agent-router-service/guides/route-requests-across-providers" className="tare-nav-card">
    Route requests across providers
    Attach a routing configuration so requests span more than one backend.
  </Link>
