llama-index-integrations/llms/llama-index-llms-apertis/README.md
Apertis provides a unified API gateway to access multiple LLM providers including OpenAI, Anthropic, Google, and more through an OpenAI-compatible interface.
pip install llama-index-llms-apertis
Apertis supports multiple API formats:
| Endpoint | Format | Description |
|---|---|---|
/v1/chat/completions | OpenAI Chat Completions | Default format used by this integration |
/v1/responses | OpenAI Responses | OpenAI Responses format compatible |
/v1/messages | Anthropic | Anthropic format compatible |
Obtain your API key from Apertis API.
You can set either the environment variable APERTIS_API_KEY or pass your API key directly in the class constructor:
from llama_index.llms.apertis import Apertis
from llama_index.core.llms import ChatMessage
llm = Apertis(
api_key="<your-api-key>",
model="gpt-5.2",
)
Or using environment variables:
export APERTIS_API_KEY="<your-api-key>"
from llama_index.llms.apertis import Apertis
llm = Apertis(model="gpt-5.2")
Send a list of ChatMessage instances to generate a chat response:
from llama_index.core.llms import ChatMessage
message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)
To stream responses, use the stream_chat method:
message = ChatMessage(role="user", content="Tell me a story in 250 words")
resp = llm.stream_chat([message])
for r in resp:
print(r.delta, end="")
Generate completions with a prompt using the complete method:
resp = llm.complete("Tell me a joke")
print(resp)
To stream completions, use the stream_complete method:
resp = llm.stream_complete("Tell me a story in 250 words")
for r in resp:
print(r.delta, end="")
Apertis supports models from multiple providers:
| Provider | Example Models |
|---|---|
| OpenAI | gpt-5.2, gpt-5-mini-2025-08-07 |
| Anthropic | claude-sonnet-4.5 |
gemini-3-flash-preview |
# Using Claude
llm = Apertis(
api_key="<your-api-key>",
model="claude-sonnet-4.5",
)
# Using Gemini
llm = Apertis(
api_key="<your-api-key>",
model="gemini-3-flash-preview",
)
| Parameter | Description | Default |
|---|---|---|
api_key | Your Apertis API key | APERTIS_API_KEY env var |
api_base | API base URL | https://api.apertis.ai/v1 |
model | Model to use | gpt-5.2 |
temperature | Sampling temperature | 0.1 |
max_tokens | Maximum tokens to generate | 256 |
max_retries | Maximum retry attempts | 5 |
For more information, visit the Apertis Documentation.