LangChain / LlamaIndex
Use 221 models in LangChain and LlamaIndex by pointing the OpenAI-compatible API endpoint to Chuizi.AI.
Prerequisites
- Python 3.9+
- A Chuizi.AI account with an API key (starts with
ck-)
LangChain Configuration
Installation
terminal
bash
pip install langchain-openai
Basic Usage
example.py
python
from langchain_openai import ChatOpenAI llm = ChatOpenAI( openai_api_base="https://api.chuizi.ai/v1", openai_api_key="ck-your-key-here", model="anthropic/claude-sonnet-4-6", ) response = llm.invoke("What is RAG?") print(response.content)
Using in a Chain
example.py
python
from langchain_core.prompts import ChatPromptTemplate prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful AI assistant."), ("user", "{input}"), ]) chain = prompt | llm response = chain.invoke({"input": "Explain LangChain"}) print(response.content)
Embeddings
example.py
python
from langchain_openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings( openai_api_base="https://api.chuizi.ai/v1", openai_api_key="ck-your-key-here", model="openai/text-embedding-3-small", ) result = embeddings.embed_query("Hello world")
LlamaIndex Configuration
Installation
terminal
bash
pip install llama-index-llms-openai llama-index-embeddings-openai
Basic Usage
example.py
python
from llama_index.llms.openai import OpenAI llm = OpenAI( api_base="https://api.chuizi.ai/v1", api_key="ck-your-key-here", model="anthropic/claude-sonnet-4-6", ) response = llm.complete("What is a vector database?") print(response)
Set as Global Default
example.py
python
from llama_index.core import Settings Settings.llm = OpenAI( api_base="https://api.chuizi.ai/v1", api_key="ck-your-key-here", model="anthropic/claude-sonnet-4-6", )
Verify the Configuration
Run any of the code examples above. If you receive a successful response, the configuration is correct.
Common Issues
Model Name Format
In both LangChain and LlamaIndex, use the provider/model format, such as anthropic/claude-sonnet-4-6.
Parameter Name Differences
LangChain uses openai_api_base, while LlamaIndex uses api_base. Be careful not to mix them up.
Framework Version Compatibility
Use LangChain 0.2+ and LlamaIndex 0.10+ for best results. Older versions may have slightly different parameter names.
Next Steps
- Embeddings API — vector embedding reference for RAG pipelines
- Choose a Model — compare models for RAG and agent tasks
- Structured Output — get JSON responses for data extraction