LlamaIndex with an OpenAI-compatible API: setup
Use Claude, GPT, Gemini and open models in LlamaIndex through one OpenAI-compatible key: OpenAILike setup, embeddings, function calling and the common errors.
To use UplinkSwitch in LlamaIndex, install llama-index-llms-openai-like and create OpenAILike(model="claude-sonnet-5-5", api_base="https://api.uplinkswitch.com/v1", api_key=..., is_chat_model=True). Every chat model in the catalog then works in query engines, chat engines and agents, priced per token from prepaid credit.
Install
pip install llama-index-core llama-index-llms-openai-likeThe LLM
import os
from llama_index.llms.openai_like import OpenAILike
from llama_index.core import Settings
Settings.llm = OpenAILike(
model="claude-sonnet-5-5",
api_base="https://api.uplinkswitch.com/v1",
api_key=os.environ["UPLINKSWITCH_API_KEY"],
is_chat_model=True,
is_function_calling_model=True, # for models that support tool calling
context_window=200000, # set to what you'll actually send, at most the model's window
)is_chat_model=True sends requests to the Chat Completions endpoint. Leave it off and LlamaIndex uses the legacy completions route, which many chat models don't serve well.
Embeddings on the same key
The catalog includes embedding models such as bge-m3 ($0.0295 per million tokens) and gemini-embedding-001 ($0.15), served at /v1/embeddings. Use OpenAILikeEmbedding from llama-index-embeddings-openai-like with the same api_base.
Which model for which job
| Job | Model id | Price per 1M (in / out) |
|---|---|---|
| Answer synthesis over retrieved chunks | claude-sonnet-5-5 | $1.164 / $2.91 |
| High-volume summarising and routing | deepseek-v4.1-flash | $0.0564 / $0.1692 |
| Long documents in one call | gemini-4-argon (1M) | $0.582 / $2.91 |
Errors you may see
- "Unknown model": the plain
OpenAIclass validates names against OpenAI's list. UseOpenAILike. - 401: the key is missing or mistyped; it starts with
sk-uplink-live-. - 402
insufficient_balance: top up; nothing was charged.