๐Ÿฆœ LangChain + DeepSeek/Qwen: Complete Integration Guide

Last updated: July 29, 2026 ยท 5 min read ยท OpenAI-compatible setup

๐Ÿš€ Ready to use DeepSeek V4 with LangChain?
Get started with our OpenAI-compatible API. No code changes needed โ€” just swap the base URL.
Get API Key โ†’

Why Use Chinese LLMs with LangChain?

LangChain's ChatOpenAI class works with any OpenAI-compatible API. Chinese LLMs like DeepSeek V4 and Qwen3 offer:

Quick Start (5 Minutes)

1 Install Dependencies

pip install langchain-openai langchain-core

2 Configure the Client

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,
)

3 Use It Like Normal OpenAI

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)

Advanced: Chains & Agents

Using with LCEL Chains

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)

Using with Agents (Tool Calling)

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"})

Streaming Response

for chunk in llm.stream("Write a haiku about programming"):
    print(chunk.content, end="", flush=True)

Available Models

ModelContextBest ForPrice
DeepSeek V4128KGeneral purpose, coding, reasoning$0.28/M tokens
DeepSeek V3128KBalanced performance$0.14/M tokens
DeepSeek R1128KComplex reasoning, math$0.55/M tokens
Qwen3 Flash32KFast responses, high throughput$0.07/M tokens
DeepSeek V4 Flash64KQuick tasks, chatbots$0.07/M tokens
๐Ÿ’ก Pro tip: Use 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.

Migration from OpenAI

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.

Troubleshooting

IssueSolution
401 UnauthorizedCheck your API key. Get one from our dashboard
Model not foundUse exact model names: deepseek-v4, deepseek-v3, deepseek-r1
Timeout errorsFor long responses, increase timeout: ChatOpenAI(..., request_timeout=120)
Rate limitingCheck your plan limits. Free tier: 100 requests/day
Start building with DeepSeek + LangChain today
Free tier available. No credit card required.
Get Your API Key โ†’