> ## Documentation Index
> Fetch the complete documentation index at: https://docs.altrum.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SDKs

> Point the OpenAI, Anthropic and Google SDKs at the AI Gateway by changing the base URL and the key.

Keep the SDK you use. Change two things: its base URL, to the AI Gateway, and its API key, to your [virtual key](/ai-gateway/virtual-keys.md). Each SDK sends the key in its usual header, and Altrum reads it there. Every example reads the key from the `ALTRUM_VIRTUAL_KEY` environment variable.

**OpenAI**

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.altrum.ai/openai/v1", api_key=os.environ["ALTRUM_VIRTUAL_KEY"])

reply = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarise this ticket in one line."}],
)
print(reply.choices[0].message.content)
```

```typescript theme={null}
import OpenAI from 'openai'

const client = new OpenAI({ baseURL: 'https://api.altrum.ai/openai/v1', apiKey: process.env.ALTRUM_VIRTUAL_KEY })

const reply = await client.chat.completions.create({
  model: 'openai/gpt-4o-mini',
  messages: [{ role: 'user', content: 'Summarise this ticket in one line.' }],
})
console.log(reply.choices[0].message.content)
```

**Anthropic**

```python theme={null}
import os
from anthropic import Anthropic

client = Anthropic(base_url="https://api.altrum.ai/anthropic", api_key=os.environ["ALTRUM_VIRTUAL_KEY"])

reply = client.messages.create(
    model="anthropic/claude-sonnet-4-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Summarise this ticket in one line."}],
)
print(reply.content[0].text)
```

**Google**

```python theme={null}
import os
from google import genai
from google.genai import types

client = genai.Client(
    api_key=os.environ["ALTRUM_VIRTUAL_KEY"],
    http_options=types.HttpOptions(base_url="https://api.altrum.ai/genai"),
)

reply = client.models.generate_content(
    model="gemini/gemini-3.5-flash",
    contents="Summarise this ticket in one line.",
)
print(reply.text)
```

Any of these clients can call any model your key allows: the provider prefix in the model name decides where the request goes. The Google SDK cannot list models through Altrum. See the [API reference](/api-reference/introduction.md).

## Send Altrum headers

To use a saved prompt, steer the cache or set your own request reference, send the [request headers](/api-reference/request-headers.md) with the client or with one request:

```python Python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.altrum.ai/v1",
    api_key=os.environ["ALTRUM_VIRTUAL_KEY"],
    default_headers={"x-alt-cache-key": "customer-881"},
)

reply = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Where is my order?"}],
    extra_headers={"x-alt-prompt-id": "support-reply"},
)
print(reply.choices[0].message.content)
```

```typescript TypeScript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.altrum.ai/v1",
  apiKey: process.env.ALTRUM_VIRTUAL_KEY,
  defaultHeaders: { "x-alt-cache-key": "customer-881" },
});

const reply = await client.chat.completions.create(
  { model: "openai/gpt-4o-mini", messages: [{ role: "user", content: "Where is my order?" }] },
  { headers: { "x-alt-prompt-id": "support-reply" } },
);
console.log(reply.choices[0].message.content);
```

## Handle a refusal

When a guardrail, a budget or a rate limit stops a request, the SDK raises its usual API error, with the status and a message from Altrum saying what stopped it. Catch it as you catch any provider error. [Handle errors](/ai-gateway/handle-errors.md) shows which errors to retry and has code to copy, and [Errors](/api-reference/errors.md) lists every code.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.