Integration guides
Using LangChain
Connect LangChain to Tutujin API with ChatOpenAI and OpenAIEmbeddings from langchain-openai, setting base_url to https://open.tutujin.com/v1; for native Claude calls use ChatAnthropic from langchain-anthropic. Python and JavaScript examples.
LangChain connects to Tutujin API through the langchain-openai package: both ChatOpenAI and OpenAIEmbeddings accept a custom base_url. Set it to https://open.tutujin.com/v1, use your Tutujin key as api_key, and use a model name from the model hub. For the native Claude API, use ChatAnthropic from langchain-anthropic with base_url set to https://open.tutujin.com.
Install
pip install langchain-openai langchain-anthropicnpm install @langchain/openai @langchain/coreChat models
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-5.4-mini",
base_url="https://open.tutujin.com/v1",
api_key=os.environ["TUTUJIN_API_KEY"],
temperature=0.3,
max_retries=3,
timeout=60,
)
print(llm.invoke("Explain vector databases in one sentence.").content)
# streaming
for chunk in llm.stream("Write a 60-word product description"):
print(chunk.content, end="", flush=True)import { ChatOpenAI } from '@langchain/openai'
const llm = new ChatOpenAI({
model: 'gpt-5.4-mini',
apiKey: process.env.TUTUJIN_API_KEY,
configuration: { baseURL: 'https://open.tutujin.com/v1' },
temperature: 0.3,
})
const res = await llm.invoke('Explain vector databases in one sentence.')
console.log(res.content)
// streaming
for await (const chunk of await llm.stream('Write a 60-word product description')) {
process.stdout.write(String(chunk.content))
}To switch models, change model. Every model the catalog lists for Chat Completions — DeepSeek, Qwen, Claude, Gemini and more — works with ChatOpenAI.
Building a chain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You write e-commerce copy in under 30 words."),
("user", "Write one selling point for: {product}"),
])
chain = prompt | llm | StrOutputParser()
print(chain.invoke({"product": "500 ml stainless steel insulated bottle"}))Embeddings
import os
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(
model="text-embedding-3-small",
base_url="https://open.tutujin.com/v1",
api_key=os.environ["TUTUJIN_API_KEY"],
)
vectors = embeddings.embed_documents(["What is the return policy?", "How soon do orders ship?"])
query_vector = embeddings.embed_query("how do I return an item")For embedding models from other vendors (for example qwen3-embedding-8b), add check_embedding_ctx_length=False. By default OpenAIEmbeddings tokenizes text with OpenAI's tokenizer and sends token IDs, which other vendors' models do not accept; turning the check off sends the raw text:
embeddings = OpenAIEmbeddings(
model="qwen3-embedding-8b",
base_url="https://open.tutujin.com/v1",
api_key=os.environ["TUTUJIN_API_KEY"],
check_embedding_ctx_length=False,
)Plug the embeddings into any vector store LangChain supports (PGVector, Milvus, Qdrant, Chroma…) for retrieval-augmented generation; the full design is in Enterprise knowledge base and RAG.
Native Claude calls
import os
from langchain_anthropic import ChatAnthropic
claude = ChatAnthropic(
model="claude-sonnet-5-5",
base_url="https://open.tutujin.com",
api_key=os.environ["TUTUJIN_API_KEY"],
max_tokens=1024,
)
print(claude.invoke("Summarize these meeting notes in three points: ...").content)The base URL is the site root, without /v1.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| 404 | ChatOpenAI needs /v1 in base_url; ChatAnthropic does not |
| 400 from embeddings | A non-OpenAI embedding model without check_embedding_ctx_length=False |
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.