Getting Started with DeepSeek API: A Quick Guide

DeepSeek API Overview

DeepSeek API uses an OpenAI-compatible API format, which means you can access the DeepSeek API using the OpenAI SDK or any OpenAI API-compatible software with simple configuration changes. This guide will help you get started with DeepSeek API quickly.

Basic Configuration Parameters

Key configuration parameters include:

  • base_url: https://api.deepseek.com
    • For OpenAI compatibility, you can also use https://api.deepseek.com/v1
    • Note: The v1 here is unrelated to model versions
  • api_key: Required (needs to be applied for)
  • model: Use deepseek-chat to access the latest DeepSeek-V3 model

API Usage Examples

Using curl

curl https://api.deepseek.com/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <DeepSeek API Key>" \ -d '{ "model": "deepseek-chat", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ], "stream": false }'

Using Python SDK

from openai import OpenAI client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com") response = client.chat.completions.create( model="deepseek-chat", messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": "Hello"}, ], stream=False ) print(response.choices[0].message.content)

Using Node.js SDK

import OpenAI from "openai"; const openai = new OpenAI({ baseURL: "https://api.deepseek.com", apiKey: "<DeepSeek API Key>", }); async function main() { const completion = await openai.chat.completions.create({ messages: [{ role: "system", content: "You are a helpful assistant." }], model: "deepseek-chat", }); console.log(completion.choices[0].message.content); } main();

Important Notes

  1. Before getting started, ensure you have:

    • Applied for a DeepSeek API key
    • Installed the appropriate SDK (e.g., pip install openai for Python, npm install openai for Node.js)
  2. Streaming Output:

    • Non-streaming by default
    • Enable streaming by setting stream=true
    • Streaming is ideal for real-time response scenarios
  3. Model Information:

    • The deepseek-chat model has been fully upgraded to DeepSeek-V3
    • The interface remains unchanged, no code modifications needed
    • Access the latest version by specifying model='deepseek-chat'

Next Steps

After completing the basic setup, you can:

  • Explore advanced API parameters
  • Implement streaming functionality
  • Integrate into your applications
  • Optimize API call efficiency

You're now ready to start building your AI applications with DeepSeek API!