How to Use DeepSeek API with LangChain

LangChain ?? DeepSeek API ??

LangChain is a framework for building LLM-powered applications. Use our DeepSeek API Gateway with LangChain via the OpenAI-compatible chat model interface.

Third-party API gateway. Not affiliated with or endorsed by DeepSeek. Not an official DeepSeek service.

Base URL

https://modelrelayapis.cc/v1

Available Models

Setup Steps

  1. Install the LangChain OpenAI package: pip install langchain-openai
  2. Configure ChatOpenAI with our gateway as shown in the Python example below.
  3. Set base_url to https://modelrelayapis.cc/v1.
  4. Set api_key to your sk-gateway API Key.
  5. Set model to deepseek-v4-flash.

Python Example (LangChain)

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://modelrelayapis.cc/v1",
    api_key="sk-gateway-YOUR-KEY",
    model="deepseek-v4-flash"
)

response = llm.invoke("Explain quantum computing in one sentence.")
print(response.content)

Quick curl Test

curl https://modelrelayapis.cc/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer sk-gateway-YOUR-KEY"   -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"Hello"}]}'

Common Errors

HTTPMeaning
401Invalid or missing API key
402API budget exhausted ? buy a new package
403Model not allowed for your plan
429Rate limit exceeded
500/502Gateway error ? try again or contact support

Get Your DeepSeek API Key ? From $1

Instant key delivery after PayPal payment. Check your usage anytime on the Dashboard.

View Plans & Buy