Quick Start Guide
Get started with DeepSeek AI in minutes. This guide will walk you through setting up your account, making your first API call, and exploring key features.
Prerequisites
- A valid email address for account registration
- Basic programming knowledge (Python, JavaScript, or cURL)
- Internet connection for API access
Step 1: Create Your Account
Sign Up
- Visit DeepSeek Platform
- Click "Sign Up" and provide your email address
- Verify your email address
- Complete your profile setup
Get Your API Key
- Log in to your DeepSeek dashboard
- Navigate to "API Keys" section
- Click "Create New API Key"
- Copy and securely store your API key
⚠️ Important: Keep your API key secure and never share it publicly.
Step 2: Install SDK
Choose your preferred programming language:
Python
pip install deepseek-sdk
JavaScript/Node.js
npm install deepseek-sdk
Alternative: Direct HTTP Requests
You can also use cURL or any HTTP client to make direct API requests.
Step 3: Your First API Call
Python Example
from deepseek import DeepSeekClient
# Initialize the client
client = DeepSeekClient(api_key="your-api-key-here")
# Make your first chat completion request
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "Hello! Can you explain what DeepSeek is?"}
]
)
print(response.choices[0].message.content)
JavaScript Example
import { DeepSeekClient } from 'deepseek-sdk';
// Initialize the client
const client = new DeepSeekClient({
apiKey: 'your-api-key-here'
});
// Make your first chat completion request
async function firstCall() {
const response = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [
{ role: 'user', content: 'Hello! Can you explain what DeepSeek is?' }
]
});
console.log(response.choices[0].message.content);
}
firstCall();
cURL Example
curl -X POST "https://api.deepseek.com/v1/chat/completions" \
-H "Authorization: Bearer your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "user", "content": "Hello! Can you explain what DeepSeek is?"}
]
}'
Step 4: Explore Core Features
Chat Completions
Create conversational AI experiences:
# Multi-turn conversation
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "What's the weather like today?"},
{"role": "assistant", "content": "I don't have access to real-time weather data. You can check a weather app or website for current conditions in your area."},
{"role": "user", "content": "How can I check the weather programmatically?"}
]
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages,
temperature=0.7,
max_tokens=500
)
print(response.choices[0].message.content)
Streaming Responses
Get real-time streaming responses:
# Streaming chat completion
stream = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "Write a short story about AI"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
Code Generation
Generate and analyze code:
# Code generation
code_response = client.chat.completions.create(
model="deepseek-coder",
messages=[
{"role": "user", "content": "Create a Python function to calculate the Fibonacci sequence"}
]
)
print(code_response.choices[0].message.content)
Function Calling
Use function calling for structured interactions:
import json
# Define a function
functions = [
{
"name": "get_weather",
"description": "Get current weather information for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["location"]
}
}
]
# Function calling request
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "What's the weather like in New York?"}
],
functions=functions,
function_call="auto"
)
# Check if function was called
if response.choices[0].message.function_call:
function_call = response.choices[0].message.function_call
print(f"Function called: {function_call.name}")
print(f"Arguments: {function_call.arguments}")
Step 5: Advanced Configuration
Setting Parameters
Customize AI behavior with various parameters:
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "Explain quantum computing"}
],
temperature=0.3, # Lower temperature for more focused responses
max_tokens=1000, # Maximum response length
top_p=0.9, # Nucleus sampling parameter
frequency_penalty=0.1, # Reduce repetition
presence_penalty=0.1 # Encourage topic diversity
)
Error Handling
Implement proper error handling:
from deepseek import DeepSeekError, RateLimitError, AuthenticationError
try:
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except DeepSeekError as e:
print(f"DeepSeek API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Async Operations (Python)
Use async/await for better performance:
import asyncio
from deepseek import AsyncDeepSeekClient
async def async_example():
client = AsyncDeepSeekClient(api_key="your-api-key-here")
response = await client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello async world!"}]
)
print(response.choices[0].message.content)
await client.close()
# Run async function
asyncio.run(async_example())
Step 6: Best Practices
API Key Security
import os
from deepseek import DeepSeekClient
# Use environment variables for API keys
api_key = os.getenv("DEEPSEEK_API_KEY")
client = DeepSeekClient(api_key=api_key)
Rate Limiting
import time
from deepseek import RateLimitError
def make_request_with_retry(client, messages, max_retries=3):
for attempt in range(max_retries):
try:
return client.chat.completions.create(
model="deepseek-chat",
messages=messages
)
except RateLimitError:
if attempt < max_retries - 1:
wait_time = 2 ** attempt # Exponential backoff
time.sleep(wait_time)
else:
raise
Prompt Engineering
# Use clear, specific prompts
def create_effective_prompt(task, context="", examples=""):
prompt = f"""
Task: {task}
Context: {context}
Examples: {examples}
Please provide a detailed and accurate response.
"""
return prompt.strip()
# Example usage
prompt = create_effective_prompt(
task="Summarize the key points of quantum computing",
context="For a general audience with basic science knowledge",
examples="Focus on practical applications and benefits"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": prompt}]
)
Common Use Cases
1. Chatbot Integration
class DeepSeekChatbot:
def __init__(self, api_key):
self.client = DeepSeekClient(api_key=api_key)
self.conversation_history = []
def chat(self, user_message):
self.conversation_history.append({"role": "user", "content": user_message})
response = self.client.chat.completions.create(
model="deepseek-chat",
messages=self.conversation_history
)
assistant_message = response.choices[0].message.content
self.conversation_history.append({"role": "assistant", "content": assistant_message})
return assistant_message
# Usage
chatbot = DeepSeekChatbot("your-api-key")
response = chatbot.chat("Hello, how are you?")
print(response)
2. Content Generation
def generate_blog_post(topic, length="medium"):
length_instructions = {
"short": "Write a concise 300-word blog post",
"medium": "Write a comprehensive 800-word blog post",
"long": "Write a detailed 1500-word blog post"
}
prompt = f"{length_instructions[length]} about {topic}. Include an engaging introduction, main points with examples, and a compelling conclusion."
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": prompt}],
temperature=0.7
)
return response.choices[0].message.content
# Generate content
blog_post = generate_blog_post("The Future of Artificial Intelligence", "medium")
print(blog_post)
3. Code Analysis and Review
def analyze_code(code, language="python"):
prompt = f"""
Please analyze the following {language} code and provide:
1. Code quality assessment
2. Potential bugs or issues
3. Performance optimization suggestions
4. Best practice recommendations
Code:
```{language}
{code}
"""
response = client.chat.completions.create(
model="deepseek-coder",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
Analyze code
code_to_analyze = """ def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2) """
analysis = analyze_code(code_to_analyze) print(analysis)
## Next Steps
### Explore Advanced Features
- [Function Calling Guide](/en/function-calling-guide)
- [Streaming and Real-time Applications](/en/guides/streaming)
- [User Guides](/en/guides/)
- [Multimodal AI Capabilities](/en/guides/multimodal)
### Integration Guides
- [Getting Started](/en/getting-started)
- [User Guides](/en/guides/)
- [Enterprise Solutions](/en/enterprise/)
- [API Reference](/en/api-reference)
### Resources
- [API Reference](/en/api-reference)
- [SDK Documentation](/en/sdks)
### Support
- [Technical Support](/en/support)
- [FAQ](/en/faq)
- [Contact Us](/en/contact)
---
*You're now ready to build amazing AI-powered applications with DeepSeek! Start with simple examples and gradually explore more advanced features as you become comfortable with the platform.*