Random Image API Documentation
Simple and easy-to-use random image API service
API Access Links
Base API Address
/api/randomAPI Key Authentication (Optional)
If API Key authentication is enabled in the admin panel, all API requests must include the key parameter.
/api/random?key=your-api-keyYou can enable and configure API Key in Admin Panel → API Configuration.
Usage Examples
Redirect Mode (/api/random)
/api/randomDirect Response Mode (/api/response)
/api/responseWith Parameters (r18=r18)
.../random?r18=trueWith Parameters (sfw=sfw)
.../random?sfw=trueOrientation & Size Filters
Orientation Filter
Use the orientation parameter to prefer landscape/portrait/square images when selecting randomly.
- `orientation` = `landscape` | `portrait` | `square`
- Works for both /api/random (redirect) and /api/response (direct response).
/api/random?orientation=landscape/api/response?orientation=landscapeResize & Crop (Direct Response)
The /api/response endpoint supports resizing with optional cropping.
- `width` / `height` Single value keeps aspect ratio; both values combine with fit.
- `fit` = `cover` | `contain` (default cover)
/api/response?width=800&height=600&fit=cover/api/response?width=800&height=600&fit=containOutput Format & Quality
When enabled in the admin panel, callers can use format and quality to control output format and compression quality dynamically.
- `format` = `jpg` | `jpeg` | `webp`; when omitted, the original format is preserved.
- `quality` accepts either `0-1` decimals or `1-100` integers. For example, `0.8` and `80` both mean 80% quality.
- The admin panel can also configure default WebP delivery separately for `/api/random` and `/api/response`/`/image`, and the two switches are independent.
- When default WebP delivery is enabled for an endpoint, use `origin=true` to force the original transfer behavior.
/api/random?format=webp/api/random?quality=0.8/api/random?origin=true/api/response?origin=trueTime Window Weighted Random
After an admin enables this parameter, callers can make images uploaded inside a selected time window more likely to be returned. Each image inside the window participates with timeWeight weight, while images outside keep base weight 1.
Enable “Time Window Weighting” in Admin Panel → API Configuration first. It applies to /api/random, /api/random?response=true, and /api/response.
- `timeWindow` supports rolling windows as a positive integer plus m/h/d/w, such as 30m, 24h, 7d, or 4w. Maximum: 365d.
- `timeStart` and `timeEnd` support a fixed time range. Use ISO datetimes with Z/+08:00, or pass `timeZone=Asia/Shanghai` / `timeZone=%2B08:00` when the datetimes do not include a zone.
- `timeWeight` is an integer from 1 to 100. 1 is equivalent to normal random selection; larger values increase the probability of images inside the window.
- Overall in-window hit rate = in-window image count × timeWeight / (in-window image count × timeWeight + out-of-window image count).
- `timeWeight=100` does not mean a guaranteed 100% in-window hit. If the window has few images and the outside pool is large, the overall in-window hit rate can still be modest.
- After the in-window bucket is selected, one matching image inside that window is chosen uniformly at random. Ordering is only used for stable pagination, not for preferring newest images.
- Do not combine timeWindow with timeStart/timeEnd. timeZone only applies to fixed windows. Missing timeWeight, missing window values, invalid dates/time zones, or disabled parameters return 400.
Last 7 days at 3x weight
/api/random?timeWindow=7d&timeWeight=3Direct response last 24 hours at 5x weight
/api/response?timeWindow=24h&timeWeight=5Fixed campaign window at 4x weight
/api/random?timeStart=2026-05-01T00%3A00%3A00&timeEnd=2026-05-31T23%3A59%3A59&timeZone=Asia%2FShanghai&timeWeight=4Transparency Adjustment Feature
endpoint supports image transparency adjustment. You can adjust image opacity and composite it onto a specified background color.
Parameter Description
opacityImage opacity (0-1.0)
• 0 = fully transparent, 1 = fully opaque • Optional parameter, no transparency processing if not specified
bgColorBackground color
white | black | #hex
Examples
50% opacity, white background
/api/response?opacity=0.5&bgColor=white80% opacity, black background
/api/response?opacity=0.8&bgColor=black30% opacity, custom color background
/api/response?opacity=0.3&bgColor=ff6b6bResponse Format
Success Response (200 OK)
Content-Type: image/jpeg, image/png, image/webp
// Headers
X-Image-Id: ...
X-Image-Filename: ...
X-Response-Time: ...ms
Error Response
Notice
- Rate Limit:API has request rate limits, please avoid making requests too frequently.
- Cache:The server uses two in-memory caches: /api/response has a consumable random prefetch queue, while fixed imageId responses use a reusable LRU final-response cache. Browsers/CDNs should still follow response headers.
- HTTPS:HTTPS protocol is recommended for accessing the API to ensure security.