# Connect LiteLLM to Apertis

Add Apertis as the upstream of the LiteLLM Proxy you already run, so OpenAI and Anthropic SDK clients keep their local endpoint while requests route through one Apertis key.

Source: https://apertis.ai/integrations/litellm

## Before you configure the upstream

No card is required to create an account. Choose a Coding Plan or add PAYG balance before your first API request.

## Configure the Apertis upstream

Add Apertis to the `model_list` in the LiteLLM Proxy `config.yaml` with LiteLLM’s built-in `apertis/` provider. Set `api_base` to the Apertis base URL explicitly, because the provider’s built-in default is a legacy address, and read the key from the `APERTIS_API_KEY` environment variable rather than writing it into the file. With an explicit `api_key`, the provider’s own `STIMA_API_KEY` variable is not needed. Keep `allowed_openai_params`: without it, LiteLLM can refuse a request that carries `tools` for a model ID it has no function-calling record for.

Official docs: https://docs.litellm.ai/docs/providers/apertis

```yaml
# config.yaml
# export APERTIS_API_KEY=YOUR_APERTIS_API_KEY
model_list:
  - model_name: YOUR_MODEL_ID
    litellm_params:
      model: apertis/YOUR_MODEL_ID
      api_base: https://api.apertis.ai/v1
      api_key: os.environ/APERTIS_API_KEY
      allowed_openai_params: ["tools", "tool_choice", "parallel_tool_calls"]
```

## Select a current model

Model IDs, availability, capabilities, and pricing change faster than a static setup guide. Copy the exact ID from the [live model catalog](https://apertis.ai/models) and replace `YOUR_MODEL_ID` in your tool configuration.

Clients call the `model_name` alias, so you can rename it without changing the upstream ID. Add more model entries only after verifying each one.

## Start the proxy

Install the proxy with its extras, then start it with this configuration. Recent LiteLLM releases need Python 3.10 or later.

```bash
uv tool install 'litellm[proxy]'
litellm --config config.yaml
```

## Use either SDK in both response modes

Each example calls the local proxy on its default port, `4000`, with the proxy’s own key: its `LITELLM_MASTER_KEY`, or any value when none is set. Never send your Apertis key to the proxy.

### OpenAI SDK · Non-streaming

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_LOCAL_PROXY_KEY",
    base_url="http://localhost:4000/v1",
)

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Reply with OK"}],
    stream=False,
)
print(response.choices[0].message.content)
```

### OpenAI SDK · Streaming

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_LOCAL_PROXY_KEY",
    base_url="http://localhost:4000/v1",
)

stream = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Reply with OK"}],
    stream=True,
)

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

### Anthropic SDK · Non-streaming

```python
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_LOCAL_PROXY_KEY",
    base_url="http://localhost:4000",  # no /v1: the SDK appends /v1/messages
)

message = client.messages.create(
    model="YOUR_MODEL_ID",
    max_tokens=128,
    messages=[{"role": "user", "content": "Reply with OK"}],
)
print(message.content[0].text)
```

### Anthropic SDK · Streaming

```python
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_LOCAL_PROXY_KEY",
    base_url="http://localhost:4000",  # no /v1: the SDK appends /v1/messages
)

with client.messages.stream(
    model="YOUR_MODEL_ID",
    max_tokens=128,
    messages=[{"role": "user", "content": "Reply with OK"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

## Verify the routed request

Run one non-streaming request first, then its streaming equivalent. A completed setup is a model response followed by a matching request record in [Activity](https://apertis.ai/setting?tab=activity). Repeat the check with the second SDK before moving a larger workload.

## Common setup failures

| Error | Meaning | Next step |
| --- | --- | --- |
| 401 Unauthorized | The API key is missing, expired, or entered incorrectly. | Create or replace the key, then retry without exposing it in logs. |
| 404 Model Not Found | The selected model ID is unavailable for the current access path. | Copy a current model ID from the live Apertis model catalog. |
| 429 Too Many Requests | The request reached a rate or quota boundary. | Review the current plan, PAYG balance, and key quota before retrying. |
| Tool call failed | The selected model or endpoint may not support the tool pattern. | Choose a model with the required capability in the live catalog. |
