DEV Community

Cover image for How to Test DeepSeek R1 API , Showing the thought process!🤯💥
Fallon Jimmy
Fallon Jimmy

Posted on

How to Test DeepSeek R1 API , Showing the thought process!🤯💥

How to see real-time AI replies while developing AI interfaces, avoiding traditional polling methods without waiting for a long time? Common AI models (such as Deepseek) support streaming output. Is there an API interface software that can achieve this function?

Image description

Real-time API debugging can be challenging — especially when dealing with fragmented responses. In this post, we explore the SSE testing feature, enhanced with an innovative Auto-Merge function, can simplify your debugging process and boost your development workflow.

Table of contents:

  • [What’s SSE (Server-Sent Event)?]
  • [How Does SSE Work?]
  • [Advantages and Limitations of SSE]
  • [Get the Free SSE-Supported API Client]
  • [The Power of Auto-Merge]
  • [How It Improves Your Workflow]

What’s SSE (Server-Sent Event)?

Server-Sent Events (SSE) is a standard that allows a web server to push data to a web client in real-time, without the client having to repeatedly poll the server for updates. It establishes a persistent and long-lived connection between the client and the server, enabling the server to send new data to the client as it becomes available.

Image description

How Does SSE Work?

Here’s how Server-Sent Events (SSE) works:

1.Client Initiates Connection: The client (typically a web browser) establishes a connection with the server by creating a new EventSource object and specifying the URL of the server-side script that will handle the SSE connection.

const eventSource = new EventSource('/path/to/sse-endpoint');
Enter fullscreen mode Exit fullscreen mode

2.Server Holds Connection Open: When the server receives the initial request from the client, it does not immediately respond with data. Instead, it leaves the connection open and enters a long-lived state, waiting to send data to the client as it becomes available.

data: This is the first message
event: message
id: 1

data: This is the second message
event: message
id: 2
Enter fullscreen mode Exit fullscreen mode

3.Server Sends Data: When the server has new data to send, it writes the data to the open connection in a specific format, consisting of a data field followed by the actual data payload. The server can also include other fields like event (to specify an event type) and id (to uniquely identify the event).

eventSource.addEventListener('message', function(event) {
 console.log('New message:', event.data);
});
Enter fullscreen mode Exit fullscreen mode

4.Connection Stays Open: The connection between the client and server remains open, allowing the server to continue sending data as it becomes available, without the need for the client to repeatedly request updates.

Advantages and Limitations of SSE

SSE has several advantages over traditional polling or long-polling techniques:

Real-time Updates: Data is pushed to the client as soon as it becomes available on the server, providing real-time updates without the need for polling.

Efficient: Unlike long-polling, SSE doesn’t require the client to frequently open and close connections, reducing overhead and improving scalability.

Automatic Reconnection: If the connection is interrupted, the EventSource object automatically attempts to reconnect, ensuring continuous updates.

Image description

However, SSE also has some limitations:

Unidirectional Communication: SSE is unidirectional, meaning data can only be sent from the server to the client. For bidirectional communication, WebSockets are typically used.

Limited Browser Support: While SSE is supported by modern browsers, older browsers may require fallback mechanisms or polyfills.

SSE is commonly used in scenarios where real-time updates are required, such as chat applications, live feeds, dashboard updates, and notifications systems. It provides a more efficient and real-time alternative to traditional polling techniques.

Get the Free SSE-Supported API Client

When debugging SSE (Server-Sent Events), streaming responses for endpoints related to

AI with LLMs, Apidog can automatically combine the message content and display the response in natural language. It also supports showing the thought process of reasoning models, such as Deepseek R1.

Step 1: Create a DeepSeek API Endpoint

After downloading the latest version of Apidog, open it and create a new HTTP project. Create a new interface for the project.

You can fill in the interface address of any AI model and configure the corresponding API Key. For example, for DeepSeek's API, import cURL into Apifox and note that the value of the stream field needs to be true.

Image description

Step 2: Send the Streaming Request

  • Click Send to initiate the SSE connection.
  • Apidog detects Content-Type: text/event-stream and switches to streaming mode.

Step 3: Monitor Real-Time Responses

Apidog’s Timeline View displays events as they arrive:

  • Dynamic Updates: Watch text build incrementally.
  • Metadata Tracking: View timestamps and event types (e.g., data, error)

Image description

Image description

Step 4: Showing the thought process

Debugging DeepSeek R1, which often includes reasoning steps in responses. Apidog’s timeline highlights these steps, helping developers identify logic errors, optimize prompts and validate output accuracy.

Image description

The Power of Auto-Merge

Auto-Merge is a smart feature designed to simplify SSE debugging. When your SSE responses arrive in fragments, Auto-Merge automatically recognizes and combines these pieces into one complete message. It even supports popular formats like OpenAI, Gemini, and Claude, ensuring you get a full picture every time.

How It Improves Your Workflow

  1. Streamlined Data Presentation: Instead of manually piecing together messages, Auto-Merge displays the full output in one go.
  2. Less Manual Intervention: No need for custom scripts or extra steps — everything is merged automatically.
  3. Accurate Feedback: With all data visible in real time, you can quickly spot and fix issues.
  4. Enhanced Visualization: The merged data is presented in a clear, timeline view, so you know exactly when and how each piece of data arrived.

Enhanced SSE function enhances the ability to develop AI applications, debug AI interfaces more efficiently, and intuitively display the process of model inference. It's really powerful. Download Apidog now and give it a try!

Top comments (4)

Collapse
 
jimmylin profile image
John Byrne

Nice . Been waiting to have an article of this type for awhile!

Collapse
 
fallon_jimmy profile image
Fallon Jimmy

Thanks for reading, John! 🙌

Collapse
 
johnbyrne profile image
JohnByrne

Really good informative article really liked the approach simple & easy, yet keeping all details

Collapse
 
fallon_jimmy profile image
Fallon Jimmy

Thanks for checking this out, JohnByrne!