Use MagmaRouter with LlamaIndex

Use MagmaRouter with LlamaIndex

LlamaIndex reaches a custom OpenAI-compatible endpoint through OpenAILike, not the plain OpenAI class, which rejects unknown model names.

Base URL
https://api.magmarouter.com/v1
API key
Get one, starts sk-mr-
Example model
glm-5.3-xploded

OpenAILike

Python
# pip install llama-index-llms-openai-like
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="glm-5.3-xploded",
    api_base="https://api.magmarouter.com/v1",
    api_key="sk-mr-...",
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=1048576,
)
print(llm.complete("Hello"))
Two settings that trip people up is_chat_model=True is required, or LlamaIndex calls a completions endpoint MagmaRouter does not serve. Set context_window to the model's real value (the default is 3900). Set is_function_calling_model=True only for a tool-capable model. Do not use llama_index.llms.openai.OpenAI, which raises "Unknown model" for non-OpenAI ids.

Related guides