Back to Llama Index

LlamaIndex LLMs Integration: Apertis

llama-index-integrations/llms/llama-index-llms-apertis/README.md

0.14.213.5 KB
Original Source

LlamaIndex LLMs Integration: Apertis

Apertis provides a unified API gateway to access multiple LLM providers including OpenAI, Anthropic, Google, and more through an OpenAI-compatible interface.

Installation

bash
pip install llama-index-llms-apertis

Supported Endpoints

Apertis supports multiple API formats:

EndpointFormatDescription
/v1/chat/completionsOpenAI Chat CompletionsDefault format used by this integration
/v1/responsesOpenAI ResponsesOpenAI Responses format compatible
/v1/messagesAnthropicAnthropic format compatible

Setup

Get Your API Key

Obtain your API key from Apertis API.

Initialize Apertis

You can set either the environment variable APERTIS_API_KEY or pass your API key directly in the class constructor:

python
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:

bash
export APERTIS_API_KEY="<your-api-key>"
python
from llama_index.llms.apertis import Apertis

llm = Apertis(model="gpt-5.2")

Generate Chat Responses

Send a list of ChatMessage instances to generate a chat response:

python
from llama_index.core.llms import ChatMessage

message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)

Streaming Responses

To stream responses, use the stream_chat method:

python
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="")

Complete with Prompt

Generate completions with a prompt using the complete method:

python
resp = llm.complete("Tell me a joke")
print(resp)

Streaming Completion

To stream completions, use the stream_complete method:

python
resp = llm.stream_complete("Tell me a story in 250 words")
for r in resp:
    print(r.delta, end="")

Supported Models

Apertis supports models from multiple providers:

ProviderExample Models
OpenAIgpt-5.2, gpt-5-mini-2025-08-07
Anthropicclaude-sonnet-4.5
Googlegemini-3-flash-preview

Using Different Models

python
# 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",
)

Configuration Options

ParameterDescriptionDefault
api_keyYour Apertis API keyAPERTIS_API_KEY env var
api_baseAPI base URLhttps://api.apertis.ai/v1
modelModel to usegpt-5.2
temperatureSampling temperature0.1
max_tokensMaximum tokens to generate256
max_retriesMaximum retry attempts5

Documentation

For more information, visit the Apertis Documentation.