Developers do not need specialized libraries to run DeepSeek models in their existing engineering stacks. DeepSeek provides a REST API that conforms directly to OpenAI's request and response specifications. By changing only two configuration values—the base URL and the API key—you can direct existing OpenAI client libraries, IDE plugins, and terminal coding assistants to DeepSeek’s inference infrastructure.
This guide details how to configure OpenAI client libraries in Python and TypeScript, hook DeepSeek into development tools like Cline, Cursor, Continue, and Aider, and take advantage of advanced protocol behaviors such as automatic prompt caching and reasoning token handling.
The Core Configuration: Base URL and Authentication
OpenAI client libraries route traffic to https://api.openai.com/v1 by default. To redirect requests to DeepSeek, adjust your client configuration to use DeepSeek's endpoint and credentials:
| Parameter | Value | Notes |
|---|---|---|
| Base URL | https://api.deepseek.com | Standard endpoint for chat completions and models list |
| Alternative Base URL | https://api.deepseek.com/v1 | Used when client tooling strictly appends /chat/completions to /v1 |
| Beta Base URL | https://api.deepseek.com/beta | Endpoint for specialized completion features such as FIM |
| Anthropic Base URL | https://api.deepseek.com/anthropic | Endpoint for Anthropic SDK-compatible tooling |
| API Key | sk-... | Generated in the DeepSeek Platform dashboard |
| Active Models | deepseek-chat, deepseek-reasoner | deepseek-chat for fast coding and chat; deepseek-reasoner for CoT thinking |
Avoiding Base URL Path Conflicts
The most frequent configuration error occurs when libraries or UI extensions concatenate paths improperly. DeepSeek’s router accepts requests at both https://api.deepseek.com/chat/completions and https://api.deepseek.com/v1/chat/completions. However:
- If a client library automatically appends
/v1/chat/completions, configurebase_url="https://api.deepseek.com". - If a tool appends
/chat/completionsdirectly without/v1, configurebase_url="https://api.deepseek.com/v1". - Never include a trailing slash (e.g.,
https://api.deepseek.com/) unless explicitly requested by the client, and avoid duplicate/v1paths (such ashttps://api.deepseek.com/v1/v1).
SDK Integration Examples
Because DeepSeek adheres to OpenAI's schema, official OpenAI SDKs work out of the box without patching.
1. Python (openai SDK v1.0+)
import os
from openai import OpenAI
# Initialize client with DeepSeek credentials
client = OpenAI(
api_key=os.environ.get("DEEPSEEK_API_KEY"),
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are an expert software engineer."},
{"role": "user", "content": "Write a Python generator function to stream large JSON lines files."}
],
temperature=0.7,
stream=False
)
print(response.choices[0].message.content)
To stream completions token by token, set stream=True and iterate over chunks:
stream = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Explain raft consensus in two paragraphs."}],
stream=True
)
for chunk in stream:
token = chunk.choices[0].delta.content or ""
print(token, end="", flush=True)
2. Node.js & TypeScript (openai npm package)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: "https://api.deepseek.com",
});
async function runCodeReview() {
const completion = await client.chat.completions.create({
model: "deepseek-chat",
messages: [
{ role: "system", content: "Perform a security analysis on the provided code." },
{ role: "user", content: "const query = `SELECT * FROM users WHERE id = ${req.params.id}`;" },
],
});
console.log(completion.choices[0].message.content);
}
runCodeReview();
3. Rapid Smoke Test via cURL
To verify endpoint reachability and credentials before configuring IDE plugins:
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "user", "content": "Ping DeepSeek API"}
]
}'
Integrating DeepSeek into Developer Tools
Most modern coding assistants support OpenAI-compatible custom backends. Below are configuration instructions for prominent tools.
Cline & Roo Code (VS Code Extension)
Cline acts as an autonomous coding agent directly inside your editor.
- Open the Cline panel in VS Code and click the Settings (gear) icon.
- Under API Provider, select OpenAI Compatible. Avoid selecting "OpenAI", as that hardcodes traffic to OpenAI’s proprietary endpoint.
- In Base URL, enter:
https://api.deepseek.com. - In API Key, enter your DeepSeek API key.
- In Model ID, enter
deepseek-chatfor daily development tasks, ordeepseek-reasonerif you require step-by-step problem breakdown. - Click Save.
Cursor
Cursor allows developers to override its default OpenAI routing.
- Navigate to Cursor Settings (
Cmd+,on macOS orCtrl+,on Windows/Linux) and select Models. - Scroll to the OpenAI API Key section and enable Override OpenAI Base URL.
- Set the base URL to
https://api.deepseek.com/v1(Cursor expects the/v1prefix to build completion paths). - Enter your DeepSeek API key in the OpenAI API Key input box.
- Under Model Names, click Add Model and add
deepseek-chat. Disable models you do not use to ensure queries route to DeepSeek.
Continue.dev
Continue stores provider definitions in ~/.continue/config.json. Configure DeepSeek as both a chat model and an autocomplete model:
{
"models": [
{
"title": "DeepSeek Chat",
"provider": "openai",
"model": "deepseek-chat",
"apiKey": "YOUR_DEEPSEEK_API_KEY",
"apiBase": "https://api.deepseek.com/v1"
}
],
"tabAutocompleteModel": {
"title": "DeepSeek Autocomplete",
"provider": "openai",
"model": "deepseek-chat",
"apiKey": "YOUR_DEEPSEEK_API_KEY",
"apiBase": "https://api.deepseek.com/v1"
}
}
Aider (Terminal Pair Programming)
Aider integrates with DeepSeek either natively through LiteLLM or via environment variables:
# Option A: Direct model flag with LiteLLM resolution
export DEEPSEEK_API_KEY="sk-..."
aider --model deepseek/deepseek-chat
# Option B: OpenAI endpoint redirection
export OPENAI_API_BASE="https://api.deepseek.com/v1"
export OPENAI_API_KEY="sk-..."
aider --model openai/deepseek-chat
Architecture Considerations for Workflows
Integrating DeepSeek into CI/CD pipelines, code review bots, and agentic workflows introduces specific behavioral and cost advantages.
1. Automatic Context Caching (KV Cache)
DeepSeek incorporates zero-configuration prompt caching on disk. When multiple requests share an identical prefix starting from index 0:
- The backend identifies cached token sequences automatically.
- Cached tokens bypass re-computation, resulting in significantly lower time-to-first-token (TTFT) and up to 90% reductions in input token costs.
- You can inspect cache utilization directly in the API response's
usageobject:
"usage": {
"prompt_tokens": 4096,
"completion_tokens": 512,
"total_tokens": 4608,
"prompt_cache_hit_tokens": 3584,
"prompt_cache_miss_tokens": 512
}
Workflow Tip: Order your prompt structures intentionally. Place static system prompts, large architectural specifications, and reference source files at the beginning of the prompt, and place volatile task instructions or user queries at the end. This preserves a consistent prefix across calls.
2. Handling Reasoning Tokens (reasoning_content)
When calling DeepSeek reasoning models (such as deepseek-reasoner), the model outputs chain-of-thought tokens prior to generating its final answer.
In the OpenAI response format:
- Standard response content resides in
choices[0].message.content. - Reasoning steps reside in
choices[0].message.reasoning_content. - In streaming chunks, reasoning tokens arrive via
choices[0].delta.reasoning_content.
# Extracting reasoning output in Python
response = client.chat.completions.create(
model="deepseek-reasoner",
messages=[{"role": "user", "content": "Design a distributed rate limiter."}]
)
message = response.choices[0].message
if hasattr(message, "reasoning_content") and message.reasoning_content:
print("=== Reasoning Process ===")
print(message.reasoning_content)
print("=== Final Solution ===")
print(message.content)
If you are using third-party UI tools that validate strictly against older OpenAI JSON schemas without awareness of reasoning_content, verify that the tool either ignores unknown fields or has been upgraded to support DeepSeek's thinking protocol.
3. Function Calling and Structured Output
DeepSeek supports OpenAI-style tool calling and JSON mode. Developers can provide function declarations using JSON Schema:
tools = [
{
"type": "function",
"function": {
"name": "fetch_git_diff",
"description": "Fetch the diff between two git commits or branches",
"parameters": {
"type": "object",
"properties": {
"base": {"type": "string", "description": "Base branch or commit hash"},
"target": {"type": "string", "description": "Target branch or commit hash"}
},
"required": ["base", "target"]
}
}
}
]
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Compare main and feature-auth"}],
tools=tools,
tool_choice="auto"
)
tool_calls = response.choices[0].message.tool_calls
if tool_calls:
for call in tool_calls:
print(f"Tool invocation: {call.function.name}({call.function.arguments})")
Production Reliability and Security Best Practices
- Secret Management: Store API keys in environment variables (
DEEPSEEK_API_KEY) or dedicated secret managers (e.g., AWS Secrets Manager, HashiCorp Vault, 1Password CLI). Never commit API keys insideconfig.jsonfiles that are checked into version control. - Retry with Exponential Backoff: When running automated batch scripts or CI code reviews, wrap API invocations in retry mechanisms that handle HTTP 429 (Rate Limit) and transient 5xx responses gracefully.
- Multi-Model Orchestration: In large agent pipelines, leverage
deepseek-chatfor fast sub-tasks (syntax verification, small edits, unit test scaffolding) and reserve reasoning models for architecture evaluation and complex algorithmic planning.