Connect LlamaIndex
Python framework for retrieval-augmented apps, connected through OpenAILike.
Use cases
Good for Python projects doing retrieval-augmented generation or document Q&A with LlamaIndex. OpenAILike speaks the OpenAI-compatible API and does not validate model names, so the platform's model ID works as is.
Tips
Set is_chat_model=True so requests go to the chat endpoint. For long documents, also set context_window to the model's context length so LlamaIndex splits text to fit.
If it cannot connect
- Use
https://modelportal.ai/v1as the API host, without/chat/completions. - The key starts with
mp-(older keys:key_) and is not paused or revoked;invalid_api_keymeans the key cannot be used. - The model ID matches the catalog and is in the key's allowed models.
insufficient_balancemeans the balance is too low; see common errors for more.
Setup
- Install the dependency: pip install llama-index-llms-openai-like.
- Create OpenAILike with api_base set to the API host below, your own key as api_key, and is_chat_model=True.
- Assign it to Settings.llm so indexes and query engines use it.
Settings
- API host:
https://modelportal.ai/v1 - API key:
YOUR_API_KEY - Model:
MODEL_ID
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="MODEL_ID",
api_base="https://modelportal.ai/v1",
api_key="YOUR_API_KEY",
is_chat_model=True,
)
print(llm.complete("你好"))
FAQ
- Can I connect embedding models the same way?
- Use OpenAILikeEmbedding from llama-index-embeddings-openai-like with the same api_base https://modelportal.ai/v1, and pick a model with the embedding capability.