DeepSeek Chat Completions API

DeepSeek R1

DeepSeek Chat Completions API

DeepSeek launched onto the Generative AI scene with little fanfare, but plenty of impact…

DeepSeek-V3 is an innovative language model developed by DeepSeek AI, designed to understand and generate human-like text. With its advanced capabilities, DeepSeek-V3 can assist in a wide range of tasks, from answering questions and writing essays to generating creative content. It’s a powerful tool that leverages cutting-edge technology to provide accurate and meaningful responses, making it a valuable resource for anyone looking to enhance their productivity and creativity.

What sets it apart is its unique structure that allows it to be both powerful and efficient. It uses advanced techniques to perform tasks accurately while being cost-effective. Additionally, it’s open-source, meaning anyone can use it for research or development. This makes DeepSeek-V3 a versatile tool for various applications, from answering questions to creating content.

How to Sign Up to the DeepSeek API

While DeepSeek offers its own chat application, the first step to understanding how to use the underlying API is always to create a basic chat question and answer. Before you can use the API, you need to sign up for an account on the DeepSeek Platform.

How Much Does It Cost?

Much has been written about how cheap the DeepSeek API is compared to OpenAI. Some say it’s about 25 to 1. Indeed, when I started testing, I didn’t think my US$2 credit would get me very far, but having consumed 273,522 tokens, my current spend is just 2 cents.

There is a note on the Platform home page that pricing will increase, but even the new prices are substantially less than the competitors.

Using the Chat Completions API

Once you’ve signed up, paid up and generated an API key, you can start hitting the API.

Making a request to the Chat Completion Endpoint

Authentication

Authentication is simple using your API key as the Bearer token in an HTTP request using PostMan, or 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
      }'

The Chat Completion Endpoint

POST: https://api.deepseek.com/chat/completions

The HTTP Request Body

Send the JSON formatted request in the body via a POST to the completion URL.

{
    "model": "deepseek-chat",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the average age of a university student in Australia?"}
    ],
    "stream": false
}

Receiving the response from the Chat Completions Endpoint

The response to the query is very similar in structure to a call using OpenAI.

{
    "id": "744c1993-3ef7-4bee-b822-0747bcfba6bd",
    "object": "chat.completion",
    "created": 1737710368,
    "model": "deepseek-chat",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "The average age of a university student in Australia can vary depending on the type of program and the institution. However, as of recent data:\n\n- **Undergraduate students**: The average age is typically around 20-21 years old. Many students enter university directly after completing high school, which is usually around age 17-18.\n  \n- **Postgraduate students**: The average age tends to be higher, often in the mid-to-late 20s or early 30s, as many postgraduate students have already completed an undergraduate degree and may have spent some time working before returning to study.\n\n- **Mature-age students**: A significant portion of university students in Australia are mature-age students (defined as those aged 21 or older when starting an undergraduate degree, or 25 or older for postgraduate studies). These students may be returning to education after a break or starting later in life.\n\nOverall, the average age across all university students in Australia is influenced by the presence of both traditional school-leavers and mature-age students, but it generally falls in the early-to-mid 20s."
            },
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 21,
        "completion_tokens": 221,
        "total_tokens": 242,
        "prompt_tokens_details": {
            "cached_tokens": 0
        },
        "prompt_cache_hit_tokens": 0,
        "prompt_cache_miss_tokens": 21
    },
    "system_fingerprint": "fp_3a5770e1b4"
}

The most important part of the response is the choices -> message -> content value. Like OpenAI, the response by default is formatted in Markdown, so where applicable, there will be formatting codes for things like new lines and headings scattered throughout the response.

Initial Thoughts

DeepSeek-V3 excels in understanding and generating human-like text, making it a powerful tool for various applications such as content creation, question answering, and more. Its unique architecture and cost-efficiency set it apart from other models, while its open-source nature fosters innovation and accessibility.

Speed does seem to be an issue, at least in the testing we’ve done so far, although that is not an issue limited to just DeepSeek. We’ll be diving into some more challenging scenarios in further testing, so it will be interesting to compare how it handles things like structured data.

Future improvements could focus on enhancing its contextual understanding, reducing biases, and increasing its adaptability to diverse languages and dialects. These advancements will help DeepSeek-V3 become even more versatile and reliable.