Complete guide to integrating with the DeepSeek V4 OpenAI-compatible API
Navigate to the developer dashboard and create a new API key. Save it securely - you won't be able to see it again.
pip install openaifrom openai import OpenAI
client = OpenAI(
base_url="https://deepseek-v4.io/api/v1",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="deepseek/deepseek-v4-flash",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)All API requests require your API key to be included in the Authorization header:
Authorization: Bearer sk-your-api-key-here/v1/chat/completionsMain endpoint for creating conversational AI responses. Compatible with OpenAI's Chat Completions API.
{
"model": "deepseek/deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"temperature": 0.7,
"max_tokens": 1000
}/v1/modelsReturns a list of available models that can be used with the API.
Optimized for speed and efficiency. Best for simple queries and real-time applications.
Full-featured model for complex reasoning and detailed responses.
API errors return standard HTTP status codes and JSON error objects:
{
"error": {
"message": "Invalid API key",
"type": "invalid_request_error",
"code": "invalid_api_key",
"param": null,
"details": []
}
}400 - Bad Request (invalid parameters)401 - Unauthorized (invalid API key)403 - Forbidden (insufficient permissions)429 - Rate Limit Exceeded500 - Internal Server ErrorAPI keys have rate limits to prevent abuse and ensure fair usage. Default limits vary by plan:
Rate limit status is returned in response headers: X-RateLimit-Remaining
Explore detailed guides and examples
Join our developer community
Get help from our support team