How to Use DeepSeek-V3.1 in Claude Code: A Complete Guide
How to Use DeepSeek-V3.1 in Claude Code: A Complete Guide

DeepSeek-V3.1 is the latest release from the DeepSeek team, introducing a hybrid reasoning architecture that allows switching between reasoning and non-reasoning modes. It delivers faster inference and improved Agent capabilities, making it ideal for both quick tasks and complex workflows.
If youโre working inside Claude Code (Anthropicโs AI coding environment), you can seamlessly integrate DeepSeek-V3.1 by using its OpenAI-compatible API. This guide will walk you through setup, usage, and some practical tips.
1. Prerequisites
Before getting started, make sure you have the following:
Python โฅ 3.9
Installed dependencies: openai SDK
DeepSeek API key: available from DeepSeek Platform
2. Install Dependencies
Run the following inside Claude Codeโs terminal:
bash
pip install openai
Then import the client:
from openai import OpenAI
3. Configure API Key
You can either set your API key via environment variables:
bash
export OPENAI_API_KEY="your-deepseek-api-key"
Or directly in the code (not recommended for production):
client = OpenAI(
api_key="your-deepseek-api-key",
base_url="https://api.deepseek.com"
)
4. Calling DeepSeek-V3.1
DeepSeek-V3.1 offers two models:
Non-Reasoning Mode (deepseek-chat): fast, concise outputs
Reasoning Mode (deepseek-reasoner): step-by-step reasoning with more detailed logic
Example usage:
from openai import OpenAI
# Initialize client
client = OpenAI(api_key="your-deepseek-api-key", base_url="https://api.deepseek.com")
# Non-Reasoning Mode
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the difference between VPS and VDS hosting in simple terms."}
]
)
print("Non-Reasoning Output:")
print(response.choices[0].message.content)
# Reasoning Mode
response = client.chat.completions.create(
model="deepseek-reasoner",
messages=[
{"role": "user", "content": "Give me a step-by-step reasoning to compare VPS vs VDS."}
]
)
print("Reasoning Output:")
print(response.choices[0].message.content)
5. Running Inside Claude Code
Create a file, e.g., deepseek_test.py
Copy the above code into it
Run in Claude Code terminal:
bash
python deepseek_test.py
Youโll see two different outputs โ a concise answer from non-reasoning mode and a detailed reasoning trace from reasoning mode.
6. Best Practices
Use reasoning mode for analytical or multi-step tasks (e.g., problem-solving, logical breakdowns).
Use non-reasoning mode for speed (e.g., translation, quick Q&A, code generation).
Claude Code makes it easy to debug โ print responses directly to iterate faster.
Combine with Agent workflows โ DeepSeek-V3.1 is optimized for tool usage.
7. FAQ
Do I have to use Python in Claude Code?
Not necessarily. Node.js works too, but Python + openai SDK provides the smoothest experience.
Is DeepSeek-V3.1 free?
You get some free credits on sign-up. After that, usage is billed โ check the official pricing page.
How do I switch between reasoning and non-reasoning?
Just change the model field:
deepseek-chat โ non-reasoning
deepseek-reasoner โ reasoning
Is it really OpenAI API-compatible?
Yes. You only need to set the base_url and API key for DeepSeek.
Can Claude Code restrict my access?
No. Claude Code is simply a coding environment โ as long as you have internet and a valid API key, you can use DeepSeek.