LlamaIndex (Python)
Use eWest as the LLM and embedding model in LlamaIndex.
LlamaIndex talks to eWest through its OpenAI-compatible classes: OpenAILike for chat and OpenAILikeEmbedding for embeddings. Indexes, query engines and agents then use them like any other model.
Setup
Install the two integrations (Python 3.10 or newer):
pip install llama-index-llms-openai-like llama-index-embeddings-openai-likeCreate an API key and put it in the EWEST_KEY environment variable (export EWEST_KEY=sk-…). The examples read it from there; never put the key in browser code.
Create the models with api_base="https://api.ewest.ai/v1". is_chat_model=True sends chat requests, is_function_calling_model=True turns on tool calling, and context_window (from the model page) tells LlamaIndex how much text fits.
import os
from llama_index.core import Settings
from llama_index.embeddings.openai_like import OpenAILikeEmbedding
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="ewest/claude-haiku",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=200000, # from the model page
max_tokens=256,
)
embed_model = OpenAILikeEmbedding(
model_name="ewest/gemini-embedding",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
)
# Use them everywhere (indexes, query engines, agents):
Settings.llm = llm
Settings.embed_model = embed_modelChoose a model
Use the full model ID, including the ewest/ prefix. The table has good starting points; Models lists every model with its context window and limits, and GET /v1/models returns the models your key may use. Chat models go in OpenAILike(model=…), embedding models in OpenAILikeEmbedding(model_name=…). Set context_window to the model's value (200,000 for Claude models, 1,048,576 for ewest/gemini-flash).
| Use | Model ID |
|---|---|
| Fast and cheap chat, tools | ewest/claude-haiku |
| Stronger reasoning and coding | ewest/claude-sonnet |
| Long context (1M tokens), images, audio and video input | ewest/gemini-flash |
| Embeddings for search and RAG | ewest/gemini-embedding |
Verify it works
A first chat request:
import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="ewest/claude-haiku",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=200000, # from the model page
max_tokens=256,
)
response = llm.chat([ChatMessage(role="user", content="Say hello in one short sentence.")])
print(response.message.content)The request shows up in the console under Requests within a few seconds, with its tokens and cost. Every response carries an x-request-id header, its trace ID.
Streaming and tools
stream_chat (or stream_complete) yields the answer as it is generated; each chunk has the new text in delta.
import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="ewest/claude-haiku",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=200000, # from the model page
max_tokens=256,
)
for chunk in llm.stream_chat([ChatMessage(role="user", content="Write a haiku about the sea.")]):
print(chunk.delta, end="", flush=True)
print()Tools: wrap a Python function in FunctionTool. predict_and_call lets the model pick a tool and runs it; agents such as FunctionAgent use the same tools.
import os
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"18 C and cloudy in {city}"
llm = OpenAILike(
model="ewest/claude-haiku",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=200000, # from the model page
max_tokens=256,
)
# Picks the tool, runs it and returns its output.
result = llm.predict_and_call([FunctionTool.from_defaults(fn=get_weather)], "What is the weather in Yerevan?")
print(result)Embeddings for indexes and retrieval:
import os
from llama_index.embeddings.openai_like import OpenAILikeEmbedding
embed_model = OpenAILikeEmbedding(
model_name="ewest/gemini-embedding",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
)
vector = embed_model.get_text_embedding("How do I reset my password?")
print(len(vector))Troubleshooting
- 404 `model_not_found`: the model name needs the
ewest/prefix (ewest/claude-haiku, notclaude-haiku). Check the spelling against Models. - Empty answer from `ewest/gemini-flash`:
ewest/gemini-flashdoes not think unless reasoning is on (low, medium or high); then thinking uses output tokens and a small output limit can be used up. Allow at least 256 output tokens, or turn reasoning off (below). This is a known limitation. - Follow-up turns forget the conversation: on the Responses API, pass the earlier response's
idasprevious_response_id(conversations are stored by default), or send the full message history with every request; chat completions and Messages are always stateless. See Responses. - 401, 402 or 403: the key is missing or wrong, out of budget, or not allowed to use this model. Errors explains each code; a trace ID finds the request in the console.
- Tools are ignored: set
is_function_calling_model=True. Plain completions instead of chat: setis_chat_model=True.
Turning reasoning off: pass reasoning_effort in additional_kwargs. Most chat models accept none; a few don't (their lowest is low) and answer 400 unsupported_value. Check the model's reasoning_efforts in GET /v1/models/{id} or the catalog.
import os
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="ewest/gemini-flash",
api_base="https://api.ewest.ai/v1",
api_key=os.environ["EWEST_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=1048576,
max_tokens=256,
additional_kwargs={"reasoning_effort": "none"}, # answer without thinking first
)
print(llm.complete("Say hello in one short sentence."))Still stuck? Follow Troubleshoot a request.