# Using Bob

One API for every LLM. Get a key from [relay.ai5labs.com](https://relay.ai5labs.com) — one key for 30+ models across chat, image gen, voice, OCR, and more.

---

## Quick start

OpenAI-compatible — any SDK that accepts a `base_url` works.

```python
from openai import OpenAI

client = OpenAI(
    api_key="sk-relay-...",                           # from relay.ai5labs.com/dashboard/api-keys
    base_url="https://api.relay.ai5labs.com/v1",
)

# Chat (supports streaming with stream=True)
resp = client.chat.completions.create(
    model="claude-sonnet-4.6",
    messages=[{"role": "user", "content": "Hello!"}],
)

# Images
img = client.images.generate(model="flux-schnell", prompt="a cat", n=1, size="1024x1024")

# Text-to-speech
audio = client.audio.speech.create(model="gemini-tts", input="Hello.", voice="Kore")

# Speech-to-text
transcript = client.audio.transcriptions.create(model="whisper-large-v3", file=open("audio.mp3","rb"))
```

Switch models by changing the `model` string — no config, no setup.

---

## Bob SDK

```bash
pip install relay-ai-sdk
```

```python
from relay_ai import Relay as Bob

client = Bob(api_key="sk-relay-...")

# Chat
response = client.chat("claude-sonnet-4.6", messages=[
    {"role": "user", "content": "Hello!"}
])
print(response.text)

# Streaming
for chunk in client.chat("gemini-3.5-flash", messages=[
    {"role": "user", "content": "Write a haiku about code."}
], stream=True):
    print(chunk.text, end="", flush=True)

# Tool calling
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]
response = client.chat("claude-sonnet-4.6", messages=[
    {"role": "user", "content": "What's the weather in Tokyo?"}
], tools=tools)

# Image generation
result = client.images("flux-schnell", prompt="A cat astronaut on Mars")

# Async
from relay_ai import AsyncRelay as AsyncBob

async with AsyncBob() as client:
    resp = await client.chat("claude-opus-4.8", messages=[...])
```

---

## Environment variable

Set `RELAY_API_KEY` to skip passing it explicitly:

```bash
export RELAY_API_KEY=sk-relay-...
```

```python
from relay_ai import Relay as Bob
client = Bob()  # picks up from env
```

---

## Available models

```python
from relay_ai import Relay as Bob
client = Bob()
print(client.models())
```

Chat, image, voice, and video models — all through one API key. See the full list at [relay.ai5labs.com/dashboard/models](https://relay.ai5labs.com/dashboard/models).

---

## Rules for agents

- **One key for everything.** No per-model setup. Switch by changing the `model` string.
- **Never inline API keys.** Use `RELAY_API_KEY` env var.
- Cost and usage are tracked on your dashboard automatically.
- All calls go through `api.relay.ai5labs.com/v1`.
