Home / Guides / Frameworks and SDKs
DeepSeek with LangChain, LlamaIndex and the Vercel AI SDK
Updated 2026-10-18 · OpenAI-compatible code for three popular frameworks, plus the parameter that turns thinking off.
Connection details
- Base URL (OpenAI compatible)
- https://api.aifans.fan/v1
- API key
- Create one in the console; it starts with sk- (no account yet? sign up)
- Recommended models
- deepseek-v4.1-flash, deepseek-v4-pro (all models and prices)
LangChain, LlamaIndex and the Vercel AI SDK all ship an OpenAI-compatible model class: change the base URL, the API key and the model name, and the rest of your code stays the same.
LangChain (Python)
# pip install langchain-openai
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="deepseek-v4.1-flash", base_url="https://api.aifans.fan/v1", api_key="YOUR_API_KEY", max_tokens=2000)
print(llm.invoke("Introduce yourself in one sentence").content)
LlamaIndex
# pip install llama-index-llms-openai-like
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(model="deepseek-v4.1-flash", api_base="https://api.aifans.fan/v1", api_key="YOUR_API_KEY",
is_chat_model=True, is_function_calling_model=True, context_window=128000)
print(llm.complete("Introduce yourself in one sentence"))
Vercel AI SDK (Node.js / TypeScript)
// npm install ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const aifans = createOpenAICompatible({ name: "aifans", baseURL: "https://api.aifans.fan/v1", apiKey: process.env.AIFANS_API_KEY });
const { text } = await generateText({ model: aifans("deepseek-v4.1-flash"), prompt: "Introduce yourself in one sentence" });
console.log(text);
Turn thinking off for speed
The DeepSeek V4 family thinks before it answers. For simple tasks such as classification or extraction, switch it off:
llm = ChatOpenAI(model="deepseek-v4.1-flash", base_url="https://api.aifans.fan/v1", api_key="YOUR_API_KEY",
extra_body={"thinking": {"type": "disabled"}})
All parameters are in the API reference; plain OpenAI SDK code is in the OpenAI SDK guide.