DEV Community

Cover image for How to Use Deepseek API and Enable Streaming Output for Debugging
Auden
Auden

Posted on

137 7 7 7 9

How to Use Deepseek API and Enable Streaming Output for Debugging

Login to Deepseek Open Platform

First, log in to the Deepseek Open Platform to obtain the API key.

How to Use Deepseek API

Create and Copy the API Key

On the left sidebar of the Deepseek Open Platform, find the "API Keys" section. Click on it to create an API key. Once created, copy this key and store it in a secure location that only you have access to.

How to Use Deepseek API

Please keep this API key in a safe and easily accessible place. For security reasons, you will not be able to view it again through the Deepseek Open Platform interface. If you lose this key, you will need to create a new one.

Calling Deepseek API

Once you have the API key, you can begin making API calls. The official Deepseek API documentation is available here: https://api-docs.deepseek.com/.

Below, we will use Apidog to test the API and stream the messages returned by the AI model.

How to Use Deepseek API

Or output the entire response.

How to Use Deepseek API

If you haven't used Apidog yet, we highly recommend it. It is an integrated collaboration platform that combines API documentation, debugging, design, testing, mock, and automated testing all in one.

Set Up API Key

Log in to Apidog and create a new HTTP project. After that, go to the "Environment Management" section in the upper-right corner of the project. Click on "Prod Env" and in the Service Base URL field, enter https://api.deepseek.com. Then, add an environment variable named API_KEY with the value of the Deepseek API key you created earlier. After adding, save the changes.

How to Use Deepseek API

Create a New Endpoint

Once the API key is set up, create a new endpoint in your project. Then, copy the cURL command for the conversation API from the Deepseek API documentation.

How to Use Deepseek API

Go back to Apidog, and simply paste the cURL directly into the endpoint path by pressing "Ctrl + V." Apidog will automatically parse the cURL.

How to Use Deepseek API

In the parsed endpoint, click on "Headers" and modify the Authorization parameter. Change its value to Bearer {{API_KEY}}, so that the API request will include the API key stored in the environment variable.

How to Use Deepseek API

Debugging the Endpoint

Switch the environment to "Prod Env" in the upper-right corner under "Environment Management." Then, click the "Send" button to send the request. You will receive the response from the endpoint. By modifying the content of the messages in the Body, you can simulate different conversations.

How to Use Deepseek API

To enable streaming output, set the stream value to true.

How to Use Deepseek API

Summary

After logging into the Deepseek Open Platform, create an API key and save it in a secure location. By integrating Deepseek API with Apidog, you can quickly complete API debugging. After configuring the environment variables, import the cURL provided by Deepseek into Apidog and set the Authorization to Bearer {{API_KEY}}. Then, switch to the production environment to send requests and modify the parameters as needed to enable conversations. Streaming or full output is supported, improving development efficiency.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (6)

Collapse
 
neurolov_ai_ profile image
Neurolov

Excellent post! The section on enabling streaming output for debugging is particularly valuable. Getting real-time feedback is crucial for identifying and fixing issues quickly. I'm curious – what other debugging strategies have you found helpful when working with the DeepSeek API, especially when dealing with complex prompts or lengthy responses?

Collapse
 
defmans7 profile image
DanielVee • Edited

It was a bit hard to follow the article when I didn't know what the purpose of the tutorial was. Came down to the summary which didn't give much of a clue either. I might suggest a brief introduction would make it a bit more clear. Or maybe I just don't understand the headline.

Are you just testing different chat completions?

I feel stupid asking this question, but what are you debugging?

Collapse
 
vanthoang profile image
Van Thoang

I can't access the deepseek platform, error 503. It seems like the service is being interrupted, are you experiencing the same problem?

Collapse
 
muna_lugonvu_b9503af38b79 profile image
Muna Lugonvu

Right, I am experiencing the same issue

Collapse
 
bk_millanzi_089eec8b9fe86 profile image
Bk Millanzi

Being first kinda thing... Hahahahahahahah

Okay great article...
But... Is deepseek really open-sourced though

Collapse
 
mehmetakar profile image
mehmet akar

At least you can use it in your device with Exo. See on my article: There will be more to come in the future. MONOPLY will DIE!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay