2.3 KiB
2.3 KiB
POST /serper/images
Protected. Requires a valid session cookie (credentials: 'include').
Search images via Serper.dev and stream WebP thumbnails (SSE)
Queries Google Image search via https://google.serper.dev/images using the
company setting keys.serper, and streams the
results via Server-Sent Events (text/event-stream).
- First emits an
imagesevent with the full search result list (includingimageUrl). - Then streams
thumbevents with WebP base64 thumbnails (max 200×200) as they are generated. - Emits
donewhen all thumbnails have completed (orerroron failure).
Body (JSON)
| Field | Required | Type | Description |
|---|---|---|---|
q |
yes | string | Image search query (e.g. "Purize logo") |
gl |
no | string | Country code |
hl |
no | string | Language code |
num |
no | integer | Number of search results to fetch |
preferSource |
no | boolean | Whether to prefer downloading from the full imageUrl before falling back to Google thumbnailUrl |
{
"q": "Purize logo",
"gl": "de",
"hl": "de",
"num": 100
}
SSE Events
The response is a text/event-stream. Events are emitted in order until the stream closes.
| Event | Description | Payload |
|---|---|---|
images |
First event; list of search result images with id, url, width, and height | { "images": [ { "id": 0, "url": "…", "width": 1000, "height": 800 } ] } |
thumb |
Emitted for each image as its 200×200 max WebP thumbnail is generated | { "id": 0, "dataUrl": "data:image/webp;base64,…" } |
done |
Emitted after all thumbnails have finished streaming; closes the SSE stream | { "total": 100 } |
error |
Emitted when an error occurs during Serper request or processing | { "error": "…" } |
Response 200
text/event-stream — emits images, thumb, done (and error on failure).
Errors
| Status | Description |
|---|---|
| 400 | Query missing, invalid input, or Serper API key not configured — {"error":"…"} |
| 401 | Unauthorized — {"error":"…"} |
| 403 | Not authorized — {"error":"…"} |
| 404 | Company not found — {"error":"…"} |
Generated from @openapi JSDoc. Do not edit by hand — run npm run docs:api.