Back to Llama Index

Apertis

docs/examples/llm/apertis.ipynb

0.14.212.3 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/apertis.ipynb" target="_parent"></a>

Apertis

Apertis provides a unified API gateway to access multiple LLM providers including OpenAI, Anthropic, Google, and more through an OpenAI-compatible interface. You can find out more on their documentation.

Supported Endpoints:

  • /v1/chat/completions - OpenAI Chat Completions format (default)
  • /v1/responses - OpenAI Responses format compatible
  • /v1/messages - Anthropic format compatible

If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

python
%pip install llama-index-llms-apertis
python
!pip install llama-index
python
from llama_index.llms.apertis import Apertis
from llama_index.core.llms import ChatMessage

Call chat with ChatMessage List

You need to either set env var APERTIS_API_KEY or set api_key in the class constructor

python
# import os
# os.environ['APERTIS_API_KEY'] = '<your-api-key>'

llm = Apertis(
    api_key="<your-api-key>",
    max_tokens=256,
    context_window=4096,
    model="gpt-5.2",
)
python
message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)

Streaming

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

Call complete with Prompt

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

Model Configuration

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
python
# Using Claude
llm = Apertis(model="claude-sonnet-4.5")
python
resp = llm.complete("Write a story about a dragon who can code in Rust")
print(resp)
python
# Using Gemini
llm = Apertis(model="gemini-3-flash-preview")
python
resp = llm.complete("Explain quantum computing in simple terms")
print(resp)