LangChain's ChatOpenAI class works with any OpenAI-compatible API. Chinese LLMs like DeepSeek V4 and Qwen3 offer:
pip install langchain-openai langchain-core
from langchain_openai import ChatOpenAI
# That's it โ just change base_url and api_key
llm = ChatOpenAI(
model="deepseek-v4",
base_url="https://eaf9553505eeb8f5-115-190-107-107.serveousercontent.com/v1",
api_key="your-api-key-here",
temperature=0.7,
)
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Explain quantum computing in simple terms."),
]
response = llm.invoke(messages)
print(response.content)
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
prompt = ChatPromptTemplate.from_messages([
("system", "You are a {role} expert."),
("human", "{question}")
])
chain = prompt | llm | StrOutputParser()
result = chain.invoke({
"role": "Python",
"question": "How do I implement a binary search tree?"
})
print(result)
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.tools import tool
@tool
def search_database(query: str) -> str:
"""Search the knowledge base for relevant information."""
# Your database logic here
return f"Results for: {query}"
tools = [search_database]
llm = ChatOpenAI(
model="deepseek-v4",
base_url="https://eaf9553505eeb8f5-115-190-107-107.serveousercontent.com/v1",
api_key="your-api-key-here",
)
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({"input": "Find docs about authentication", "role": "technical"})
for chunk in llm.stream("Write a haiku about programming"):
print(chunk.content, end="", flush=True)
| Model | Context | Best For | Price |
|---|---|---|---|
| DeepSeek V4 | 128K | General purpose, coding, reasoning | $0.28/M tokens |
| DeepSeek V3 | 128K | Balanced performance | $0.14/M tokens |
| DeepSeek R1 | 128K | Complex reasoning, math | $0.55/M tokens |
| Qwen3 Flash | 32K | Fast responses, high throughput | $0.07/M tokens |
| DeepSeek V4 Flash | 64K | Quick tasks, chatbots | $0.07/M tokens |
deepseek-v4-flash or qwen3.6-flash for development and testing โ they're 4-10x cheaper and perfect for prototyping. Switch to deepseek-v4 for production when you need maximum quality.
If you're already using OpenAI in your LangChain project, migration is a 2-line change:
# Before (OpenAI)
llm = ChatOpenAI(model="gpt-4o", api_key="sk-...")
# After (AI Token Hub)
llm = ChatOpenAI(
model="deepseek-v4",
base_url="https://eaf9553505eeb8f5-115-190-107-107.serveousercontent.com/v1",
api_key="your-aitoken-key",
)
All other code โ prompts, chains, agents, output parsers โ remains unchanged.
| Issue | Solution |
|---|---|
| 401 Unauthorized | Check your API key. Get one from our dashboard |
| Model not found | Use exact model names: deepseek-v4, deepseek-v3, deepseek-r1 |
| Timeout errors | For long responses, increase timeout: ChatOpenAI(..., request_timeout=120) |
| Rate limiting | Check your plan limits. Free tier: 100 requests/day |