SSE debugging
SSE (Server-Sent Events) is a real-time communication technology built upon the HTTP protocol. It's commonly used when AI models need to stream responses. With SSE, a continuous, one-way connection is established between the client and the server. This allows the server to send real-time updates directly to the client, enabling users to instantly see the thought process of the reasoning models and the generated content.
Initiating an SSE Connection
Apidog Version Should Be 2.6.49 or higher.
Auto-Merge Message
Apidog comes with built-in support for popular AI models and can automatically recognize and merge streaming responses in the following formats:
- OpenAI API Compatible Format
- Gemini API Compatible Format
- Claude API Compatible Format
If the AI model's response matches any of these formats, Apidog will automatically merge message fragments into complete reply.
For certain models, such as DeepSeek R1, Apidog also supports displaying the model's thought process in the timeline, giving you a clearer, more intuitive view of how the AI is reasoning.
Customize Merging Rules
If the Auto-Merge
feature does not work properly, you can take the following measures based on the actual situation:
1. Configure JSONPath Extraction Rules
When the SSE returns content that is in JSON format but does not conform to the built-in recognition rules of OpenAI, Gemini, Claude, etc., you can manually configure JSONPath to extract the required content. For example, for the following raw SSE response:
data: {"choices":[{"index":0,"message":{"role":"assistant","content":"H"},"logprobs":null,"finish_reason":"stop"}]}
data: {"choices":[{"index":0,"message":{"role":"assistant","content":"i"},"logprobs":null,"finish_reason":"stop"}]}
To extract thecontent
field, use this JSONPath configuration: $.choices[0].message.content
.
Here’s what each part of this JSONPath means:
$
refers to the root of the JSONchoices[0]
selects the first element of the choices arraymessage.content
specifies the content attribute under the message object of that element.
This configuration will extract the content:
Hi
2. Use Post Processor Script
For non-JSON SSE messages, you can:
- Use post processor scripts to manually handle the data.
- Contact technical support to provide feedback on the model format you are using, and we will consider adding built-in support for that format.
FAQ
This issue usually happens when the server's response doesn't follow the SSE format guidelines. The standard SSE message format requires:
- The message content must come after
data:
- Each message must be separated by two newline characters (i.e., a blank line between messages).
For more details on the SSE message format, check out the MDN documentation - Using Server-Sent Events.