Skip to main content

Make an AI API call through Agent Router

Agent Router Enterprise routes any model request through a single endpoint. The platform 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 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 the platform implements the OpenAI API, an existing OpenAI SDK needs only two changes: the base URL and the API key. The request names a model, the platform 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.

The platform is OpenAI-compatible. Point any OpenAI SDK at https://api.router.tetrate.ai/v1.

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.5",
messages=[{"role": "user", "content": "What is Agent Router?"}],
)

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

Replace gpt-5.5 with any model in the platform's catalog, such as claude-sonnet-4-6 or gemini-2.5-flash. The platform routes to the right provider automatically.

3. Stream responses

This step returns the response incrementally instead of in a single block. Setting stream=True makes the platform 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
stream = client.chat.completions.create(
model="gpt-5.5",
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.

The platform routes embedding requests the same way: one endpoint, any provider.

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 the platform with cost tracking by size, quality, and count.

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 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.

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):

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

See Install the tare CLI for installation details.

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

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

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

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:

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