Skip to content
TutujinAPI

Integration guides

Using LlamaIndex

Connect LlamaIndex to Tutujin API with OpenAILike for chat models and OpenAIEmbedding for embeddings, with api_base set to https://www.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://www.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

cURL
pip install llama-index llama-index-llms-openai-like llama-index-embeddings-openai

Chat model

LlamaIndex's built-in OpenAI class validates model names and only accepts OpenAI models. For DeepSeek, Claude, Qwen and other models, use OpenAILike:

Python
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="deepseek-v4.1-flash",
    api_base="https://www.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

Python
from llama_index.embeddings.openai import OpenAIEmbedding

embed_model = OpenAIEmbedding(
    model_name="text-embedding-3-small",
    api_base="https://www.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

Python
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

Python
query_engine = index.as_query_engine(streaming=True)
response = query_engine.query("Summarize the travel policy")
response.print_response_stream()

Troubleshooting

SymptomCause and fix
Error about an unknown model nameYou used LlamaIndex's OpenAI class; switch to OpenAILike
404api_base needs /v1; it should be https://www.tutujin.com/v1
Truncated answers or long-document errorsRaise context_window and max_tokens, or lower similarity_top_k
503 with model_not_foundThe 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.