SDK quickstart for Python
This quickstart installs the typed Agent Router SDK for Python, then makes a first read-only identity lookup (whoami) against the gateway. The lookup resolves the identity behind an API key with a GET /v1/me call and is safe to run as-is, so it confirms that the SDK, the key, and the base URL are wired together correctly before any billable request is sent.
Prerequisites
Two values and a runtime are required before starting:
- An Agent Router API key. Keys are minted in the Console or with the
tareCLI. The secret is shown once, in the form<keyid>.<secret>, so it must be copied immediately. See Make an API call for the key-minting steps. - The gateway base URL for the deployment, in the form
https://api.<your-domain>. For the hosted service this ishttps://api.tetrate.ai. - A currently supported Python 3 runtime, with
pipavailable.
The SDK reads both values from the environment:
export AGENTROUTER_BASE_URL=https://api.<your-domain>
export AGENTROUTER_API_KEY=<keyid>.<secret>
Install the SDK
The Python SDK is distributed as a source distribution (sdist) from the public stable channel and is installed from the local file rather than from PyPI. Replace <version> with the version shown on the SDKs page.
curl -fLO https://tare.tetrate.ai/tools/sdks/stable/agentrouter-python-<version>.tar.gz
pip install ./agentrouter-python-<version>.tar.gz
Installing into a virtual environment is recommended, so the SDK and its dependencies are isolated from other projects:
python -m venv .venv && source .venv/bin/activate
pip install ./agentrouter-python-<version>.tar.gz
Make the first call
Save the program below as main.py. It constructs a client from the two environment variables, calls client.me.get() (the read-only GET /v1/me endpoint), and prints the resolved identity.
"""Runnable example for the Agent Router Python SDK.
Set AGENTROUTER_BASE_URL and AGENTROUTER_API_KEY in the environment, then run `python main.py`.
"""
import os
from agentrouter_sdk import Client
client = Client(
base_url=os.environ["AGENTROUTER_BASE_URL"],
api_key=os.environ["AGENTROUTER_API_KEY"],
)
try:
result = client.me.get()
print(result)
except Exception as err:
print("Error:", err)
Run the program from the directory containing main.py:
python main.py
A successful run prints the identity associated with the API key. Because GET /v1/me only reads identity metadata, the call incurs no model usage and can be repeated freely while verifying setup.
Related references