LlamaIndex
LlamaIndex is a data framework for LLM applications. Connect it to TensorX using the OpenAI-compatible configuration.
Prerequisites
Python 3.8+
LlamaIndex installed
TensorX API key from app.tensorx.ai
Installation
pip install llama-index llama-index-llms-openai-like llama-index-embeddings-openai-likeConfiguration
LlamaIndex's OpenAI and OpenAIEmbedding classes check the model name against OpenAI's own model list and reject TensorX model IDs. For an OpenAI-compatible endpoint, use the OpenAILike and OpenAILikeEmbedding classes instead. They accept any model name and send the same requests. Pass is_chat_model=True so LlamaIndex uses the chat completions endpoint.
Basic Usage
from llama_index.llms.openai_like import OpenAILike
# Create LLM instance. Use any chat model from /v1/models.
llm = OpenAILike(
model="z-ai/glm-5.3",
api_key="your-tensorx-api-key",
api_base="https://api.tensorx.ai/v1",
is_chat_model=True
)
# Simple completion
response = llm.complete("Explain quantum computing in simple terms")
print(response)Chat Interface
Streaming Responses
RAG Applications
Build retrieval-augmented generation (RAG) systems with TensorX:
Agent Applications
Create agents with TensorX:
Configuration with Settings
For global configuration across your application:
Model selection
Call GET /v1/models with your TensorX API key and use one of the returned IDs. If the integration depends on a capability or token limit, query GET /v1/model/info before selecting the model. See Models for examples.
Troubleshooting
Connection errors
Ensure api_base ends with /v1:
Token limits
Adjust max_tokens based on your needs:
Resources
Last updated
Was this helpful?

