TL;DR
DeepSeek V4 is accessible through a web chat interface and an OpenAI-compatible API. For API use, create an API key, use Bearer token auth, and send requests to the chat completions endpoint. Set temperature to 0.2 for code and specifications; 0.5 for creative tasks. Break complex coding tasks into sequential steps rather than one large prompt. Test your integration with Apidog before building.
Introduction
DeepSeek V4 is useful for coding, reasoning, and technical writing workflows. It follows explicit instructions well at low temperature, can produce minimal code output, and works best when prompts include clear constraints.
This guide shows how to:
- Test DeepSeek V4 in the web interface
- Call the API with
curland Python - Validate requests in Apidog
- Structure coding prompts for better implementation output
- Add basic production safeguards around API usage
Starting with the web interface
Use the web interface first to validate whether V4 handles your task well before wiring it into an application.
Get access
- Go to
chat.deepseek.com - Sign in with your account
- Select V4 from the model list in the sidebar
Write direct prompts
V4 responds best to short, explicit instructions. Avoid long setup unless it affects the output.
Use prompts like:
Write a Python function that sorts a list of dictionaries by a specified key.
Add constraints when you care about format, length, or assumptions:
Write a Python function that sorts a list of dictionaries by a specified key.
Constraints:
- Keep the implementation under 50 lines
- Use only the standard library
- Output only code
- List assumptions as comments at the top
Useful prompt constraints:
Output only the code, no explanationKeep the implementation under 100 linesUse no external dependenciesList assumptions before writing codeReturn valid JSON onlyInclude edge cases before the implementation
Temperature guidance
The web interface does not expose temperature directly, but the API does.
Use:
-
0.2β code generation, specs, structured output -
0.5β alternatives, variations, tradeoff exploration -
0.7+β creative writing and brainstorming
For implementation work, start with 0.2.
Reset long conversations
Context accumulates in long threads. If output becomes vague, inconsistent, or too influenced by earlier messages, start a new conversation with a focused prompt.
API setup
DeepSeek V4 uses an OpenAI-compatible API shape, so existing OpenAI-style clients can work by changing the base URL, model, and API key.
Step 1: Create an API key
- Go to
platform.deepseek.com - Navigate to API Keys
- Create a new key
- Copy it immediately
- Store it as an environment variable
export DEEPSEEK_API_KEY="your-api-key-here"
Avoid hardcoding the key in source code.
Step 2: Test with curl
Send a request to the chat completions endpoint:
curl https://api.deepseek.com/v1/chat/completions \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4",
"messages": [
{
"role": "user",
"content": "Write a Python function that sorts a list of dictionaries by a specified key."
}
],
"temperature": 0.2
}'
Expected result: a JSON response with a choices array and generated content at:
choices[0].message.content
Step 3: Use the OpenAI Python client
Install the OpenAI client if needed:
pip install openai
Then configure the DeepSeek base URL:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com/v1",
)
response = client.chat.completions.create(
model="deepseek-v4",
messages=[
{
"role": "system",
"content": "You write clean, minimal Python. No explanatory prose unless asked.",
},
{
"role": "user",
"content": "Write a function that renames screenshot files based on their creation timestamp.",
},
],
temperature=0.2,
)
print(response.choices[0].message.content)
The OpenAI Python client works here because DeepSeek exposes an OpenAI-compatible endpoint structure.
Testing with Apidog
Before building an application around the API, test the request and response format in Apidog. This helps catch authentication, schema, and streaming issues early.
Step 1: Create an environment
In Apidog:
- Create a new project
- Go to Environments
- Create an environment named
DeepSeek Production - Add a variable:
Name: DEEPSEEK_API_KEY
Type: Secret
Value: your-api-key
Step 2: Create a chat completion request
Create a new request:
POST https://api.deepseek.com/v1/chat/completions
Authorization: Bearer {{DEEPSEEK_API_KEY}}
Content-Type: application/json
Request body:
{
"model": "deepseek-v4",
"messages": [
{
"role": "system",
"content": "You are a coding assistant. Respond only with code unless asked for explanation."
},
{
"role": "user",
"content": "{{user_prompt}}"
}
],
"temperature": 0.2,
"max_tokens": 2000
}
Step 3: Add assertions
Add checks for the minimum response contract your app depends on:
Status code is 200
Response body has field choices
Response body field choices[0].message.content is not empty
If your application expects code only, add a prompt-level constraint and verify the response manually before automating around it.
Step 4: Test streaming
For real-time streaming responses, send:
{
"model": "deepseek-v4",
"messages": [
{
"role": "user",
"content": "Write a short Python function that validates an email address."
}
],
"stream": true,
"temperature": 0.2
}
Apidog can inspect streaming responses. Verify that your client correctly assembles the final content from streamed chunks.
First coding task: file automation workflow
A good first evaluation task is a file automation script. It tests whether the model can reason about:
- File system edge cases
- Naming collisions
- Dry-run behavior
- Platform differences
- Destructive operations
Do not start with a single large prompt like:
Build a complete file renaming tool.
Instead, split the task into phases.
Phase 1: Risk assessment
I want to write a Python script that renames files in a folder based on their creation date.
Before you write any code, list the risks and edge cases I should handle.
Look for issues such as:
- Duplicate timestamps
- Existing destination filenames
- Files without expected metadata
- Timezone differences
- Permission errors
- Directories mixed with files
- Dry-run support
- Reversibility
Phase 2: Implementation plan
Now write a step-by-step implementation plan. Don't write code yet.
Use this step to verify that the modelβs approach is safe before it writes code.
Phase 3: Code
Write the Python script.
Requirements:
- Under 120 lines
- Handle the edge cases you listed
- Add a --dry-run flag that shows what would be renamed without making changes
- Use no external dependencies beyond the standard library
- Output only the code
Phase 4: Tests
Write pytest tests for the main renaming logic.
Requirements:
- Mock the file system
- Test duplicate timestamp handling
- Test dry-run behavior
- Test existing destination filename conflicts
This staged approach produces cleaner and more reviewable output than asking for the complete tool in one message.
Example: safer implementation prompt
Use a prompt like this when you are ready for code:
Write a Python CLI script that renames files in a directory based on creation timestamp.
Functional requirements:
- Accept a directory path as an argument
- Add a --dry-run flag
- Skip directories
- Avoid overwriting existing files
- Resolve filename collisions deterministically
- Print each planned or completed rename
- Use only the Python standard library
Output requirements:
- Output only code
- Keep the file under 120 lines
- Include clear error handling
For implementation work, explicit constraints are more reliable than broad instructions.
Model strengths and limitations
What V4 does well
DeepSeek V4 is effective when you need:
- Low-temperature structured output
- Minimal code without extra prose
- Direct instruction following
- Edge case discovery when explicitly requested
- Practical code generation for contained tasks
Where to be careful
Do not treat generated code as production-ready without review.
Watch for:
- Incorrect assumptions about your runtime
- Missing validation around generated output
- Overconfident answers at higher temperatures
- Bugs in file system, concurrency, or security-sensitive code
- Drift in long conversations
For complex scripts, multi-step prompting usually works better than one large request.
For multi-file refactoring at scale, Claude Opus 4.6 or GPT-5 may produce fewer surprises. For most coding use cases, the practical difference depends on cost, context needs, and your specific edge cases.
Rate limits and pricing
Check current rate limits and pricing at platform.deepseek.com.
For production usage, add basic reliability controls:
- Retry logic with exponential backoff for HTTP
429 - Request logging for debugging and token tracking
- Output validation before executing or storing generated content
- Timeouts for API calls
- Safe handling for partial or malformed responses
Example retry structure:
import time
from openai import OpenAI
def call_with_retries(client: OpenAI, *, max_attempts: int = 3):
for attempt in range(max_attempts):
try:
return client.chat.completions.create(
model="deepseek-v4",
messages=[
{"role": "user", "content": "Write a Python function to slugify a string."}
],
temperature=0.2,
)
except Exception:
if attempt == max_attempts - 1:
raise
sleep_seconds = 2 ** attempt
time.sleep(sleep_seconds)
Adapt exception handling to your client and production error policy.
FAQ
Is DeepSeek V4 OpenAI-compatible?
Yes. The chat completions endpoint follows the OpenAI API format. Existing code that calls OpenAI can switch to DeepSeek by changing the base URL and API key.
What is the context window?
DeepSeek V4 supports a large context window suitable for repository-scale code review. Check the current documentation for the exact limit because it can change.
Can I use DeepSeek V4 for non-coding tasks?
Yes. Writing, analysis, and research tasks can work well. The same strengths around structured output and instruction following apply outside code.
How does V4 compare to Claude Opus 4.6 for coding?
On SWE-bench benchmarks, Claude Opus 4.6 leads at 80.9%. DeepSeek V4 is strong on multi-file, repository-scale tasks with large context. For most coding use cases, both are capable; the practical difference is usually cost and behavior on your specific edge cases.
Does the API support function calling?
Yes. DeepSeek V4 supports function calling in the OpenAI format, making it compatible with tool-use workflows built on the OpenAI SDK.
Top comments (0)