Connect LlamaIndex to byesu API
Connect LlamaIndex RAG query engines, chat engines, and FunctionAgent workflows to byesu using llama-index-llms-openai-like so you can call Claude 5.5, GPT-6.2, DeepSeek V4, Gemini 4, and Grok with a single pay-as-you-go API key.
Quick configuration
- Package:
llama-index-llms-openai-like(OpenAILike) api_base:https://byesu.com/v1- Required flags:
is_chat_model=True,is_function_calling_model=True,context_window=1000000,timeout=120.0 - Environment variable:
BYESU_API_KEY=sk-...(created in the defaultautogroup)
Why OpenAILike Beats llama_index.llms.openai.OpenAI
When routing through an OpenAI-compatible gateway to non-gpt-* model IDs (claude-opus-5-5, claude-sonnet-5-5, deepseek-v4-pro, gemini-4-argon, grok-4.7) — or newly released GPT models before upgrading LlamaIndex — llama_index.llms.openai.OpenAI validates model against a hardcoded dictionary of OpenAI model names to look up context window metadata and raises ValueError: Unknown model ....
OpenAILike (from llama-index-llms-openai-like) skips hardcoded model-name validation and accepts any gateway model ID cleanly while preserving chat completions, streaming, structured outputs, and native tool calling.
Prerequisites
- Create an
sk-...token in the byesu Console under the defaultautogroup (see Choosing a Group). - Install
llama-index-coreandllama-index-llms-openai-like:
pip install llama-index-core llama-index-llms-openai-like
export BYESU_API_KEY="sk-your-byesu-token"Configure OpenAILike for Chat, RAG & Tool Agents
Initialize OpenAILike with api_base="https://byesu.com/v1" and register it on Settings.llm:
import os
from llama_index.core import Document, Settings, SummaryIndex
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="claude-sonnet-5-5", # swap to "claude-opus-5-5", "gpt-6.2-sol", "deepseek-v4-pro", "gemini-4-argon"
api_base="https://byesu.com/v1",
api_key=os.environ["BYESU_API_KEY"],
context_window=1000000,
is_chat_model=True,
is_function_calling_model=True,
timeout=120.0,
)
# 1. Direct streaming chat
for chunk in llm.stream_chat([ChatMessage(role="user", content="Give 3 indexing tips for hybrid BM25 + vector RAG.")]):
print(chunk.delta, end="", flush=True)
print()
# 2. Register globally for LlamaIndex query engines & synthesizers
Settings.llm = llm
docs = [
Document(text="Runbook: Checkout service scales automatically up to 40 pods; Redis failover takes ~8 seconds."),
Document(text="SLO policy: Checkout p99 latency target is 350ms; paging triggers above 1.5% 5xx over 5 minutes."),
]
index = SummaryIndex.from_documents(docs)
query_engine = index.as_query_engine(response_mode="compact")
print(query_engine.query("When does on-call get paged for checkout, and how long is Redis failover?"))(When using VectorStoreIndex, pair Settings.llm = llm with your local HuggingFaceEmbedding or vector database's embedding model.)
Tool-Calling FunctionAgent Example
Because is_function_calling_model=True enables OpenAI-compatible tools payloads on OpenAILike, you can run LlamaIndex's async FunctionAgent across Claude, GPT, DeepSeek, or Gemini:
import asyncio
import os
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai_like import OpenAILike
def lookup_shard_status(shard_id: str) -> str:
"""Look up replication lag in milliseconds for a database shard."""
return f"Shard {shard_id}: primary healthy, replica lag 14ms."
llm = OpenAILike(
model="deepseek-v4-pro",
api_base="https://byesu.com/v1",
api_key=os.environ["BYESU_API_KEY"],
context_window=128000,
is_chat_model=True,
is_function_calling_model=True,
timeout=120.0,
)
agent = FunctionAgent(
tools=[lookup_shard_status],
llm=llm,
system_prompt="You are a database reliability assistant. Always check shard status before answering.",
)
async def main() -> None:
response = await agent.run("Is shard eu-west-02 safe for read-after-write traffic?")
print(response)
if __name__ == "__main__":
asyncio.run(main())Production Engineering Notes
- Sampling parameters on Claude 5.5 & GPT-6.2: LlamaIndex's OpenAI base classes default
temperatureto a float (0.1). If a strict reasoning route (gpt-6.2-sol) or native Anthropic2026-10-21schema rejects sampling fields with HTTP400, passtemperature=None(and avoid settingtop_p) so sampling keys are omitted (Claude 400 sampling fix). - Match
context_windowto your target model: Setcontext_window=1000000for 1M-window models (claude-opus-5-5,claude-sonnet-5-5,gemini-4-argon) or128000–400000for smaller windows so LlamaIndex's chunk splitter budgets prompts accurately (context length exceeded). - Token groups & billing: The default
autogroup covers Claude, GPT, Gemini, DeepSeek, and Grok. Create separate tokens inGlm(glm-5.3),Kimi(kimi-k3), ormedia(gpt-image-2,gemini-3.1-flash-image-ultra) when needed. Billing is pay-as-you-go per token with live rates displayed in the byesu Console after sign-in.
Troubleshooting & Benchmarks
ValueError: Unknown model: switch fromllama_index.llms.openai.OpenAItollama_index.llms.openai_like.OpenAILikeas shown above.401 invalid_api_key: verifyapi_base="https://byesu.com/v1"andBYESU_API_KEY(OpenAI 401 fix).404/no available channel: check exact model spelling and token group (no available channel).- Timeouts on long RAG synthesis: keep
timeout=120.0or higher and use streaming response synthesis (Anthropic timeout, weekly production benchmarks).