Streaming Response
Streaming API for image analysis using multimodal models
Streaming Response API
Request
- Method: POST
- URL: /api/qwen-stream
- Headers:
Content-Type: application/json
- Body:
{ "imageBase64": "data:image/jpeg;base64,...", "prompt": "optional instruction, defaults to traffic accident detection" }
Streaming Response
- Content-Type:
text/event-stream - Data Format: Real-time text chunks returned from model generation
- End Marker: Usage information included at the end
--- Usage --- {"prompt_tokens":10,"completion_tokens":20,"total_tokens":30}
Error Response
- Content-Type:
application/json - Format:
{ "error": "error message", "code": 400 }
Error Codes
400: Request parameter error500: Server internal error
Example
// Client handling streaming response
const response = await fetch('/api/qwen-stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
imageBase64: "data:image/jpeg;base64,...",
prompt: "Analyze vehicle status in the image"
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(decoder.decode(value));
}Notes
- Images must be base64 encoded, supports
data:image/jpeg;base64prefix - Streaming responses require
text/event-streamparsing - Default prompt is traffic accident detection
- Response ends with token usage information
Code Examples
curl -X POST "http://segvision.satxspace.org/api/qwen-stream" \
-H "Content-Type: application/json" \
-d '{
"imageBase64": "data:image/jpeg;base64,your-image-base64-data",
"prompt": "Detect traffic accidents in the image and return results in JSON format."
}'