Integration guides
Using LlamaIndex
Connect LlamaIndex to Tutujin API with OpenAILike for chat models and OpenAIEmbedding for embeddings, with api_base set to https://open.tutujin.com/v1, then build document Q&A on VectorStoreIndex. Complete Python example.
LlamaIndex needs two classes to work with Tutujin API: OpenAILike for chat models (it accepts any model name) and OpenAIEmbedding for embeddings. Set api_base to https://open.tutujin.com/v1 on both, use your Tutujin key as api_key, make them the global defaults, and you can build document Q&A right away.
Install
pip install llama-index llama-index-llms-openai-like llama-index-embeddings-openaiChat model
LlamaIndex's built-in OpenAI class validates model names and only accepts OpenAI models. For DeepSeek, Claude, Qwen and other models, use OpenAILike:
import os
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="deepseek-v4.1-flash",
api_base="https://open.tutujin.com/v1",
api_key=os.environ["TUTUJIN_API_KEY"],
is_chat_model=True,
timeout=60,
)
print(llm.complete("Explain retrieval-augmented generation in one sentence."))is_chat_model=True routes calls through Chat Completions. The default context_window on OpenAILike is conservative; for long documents, set it to the limit the model's vendor publishes.
Embedding model
from llama_index.embeddings.openai import OpenAIEmbedding
embed_model = OpenAIEmbedding(
model_name="text-embedding-3-small",
api_base="https://open.tutujin.com/v1",
api_key=os.environ["TUTUJIN_API_KEY"],
)
vector = embed_model.get_text_embedding("What is the return policy?")
print(len(vector))Document Q&A
from llama_index.core import Settings, SimpleDirectoryReader, VectorStoreIndex
Settings.llm = llm
Settings.embed_model = embed_model
documents = SimpleDirectoryReader("./docs").load_data() # your PDFs, Word files, Markdown...
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(similarity_top_k=5)
print(query_engine.query("What documents do employees need for an expense claim?"))Indexing calls the embeddings endpoint for every chunk, billed at the embedding model's price; each question then makes one embeddings call and one chat call. To estimate costs, see the table in Enterprise knowledge base and RAG.
Streaming
query_engine = index.as_query_engine(streaming=True)
response = query_engine.query("Summarize the travel policy")
response.print_response_stream()Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Error about an unknown model name | You used LlamaIndex's OpenAI class; switch to OpenAILike |
| 404 | api_base needs /v1; it should be https://open.tutujin.com/v1 |
| Truncated answers or long-document errors | Raise context_window and max_tokens, or lower similarity_top_k |
503 with model_not_found | The key's group lacks this model — see Choosing a group |
Still stuck? Add our WeChat support JsnonoChat and send the request id from the error message, and we will look into it.