Simple and easy-to-use random image API service

Random Image API Documentation

Simple and easy-to-use random image API service

Redirect Mode (/api/random)Direct Response Mode (/api/response)

Base API Address

API Access Links

Base API AddressSuccess Response
/api/random
GET/api/randomRedirect Mode (/api/random)
GET/api/responseDirect Response Mode (/api/response)

With API Key

API 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-key

You can enable and configure API Key in Admin Panel → API Configuration.

Usage Examples

Usage Examples

GET

Redirect Mode (/api/random)

/api/random
GET

Direct Response Mode (/api/response)

/api/response

With Parameters (r18=r18)

/api/random?r18=true

With Parameters (sfw=sfw)

/api/random?sfw=true

Output Format & Quality

Orientation & 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).

Random landscape

/api/random?orientation=landscape

Direct landscape

/api/response?orientation=landscape

Resize & 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)

Resize 800x600 cover

/api/response?width=800&height=600&fit=cover

Resize 800x600 contain

/api/response?width=800&height=600&fit=contain

Output 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.

Return WebP format

/api/random?format=webp

Return at 80% quality

/api/random?quality=0.8

Random endpoint fallback to origin

/api/random?origin=true

Response endpoint fallback to origin

/api/response?origin=true

Time 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=3

Direct response last 24 hours at 5x weight

/api/response?timeWindow=24h&timeWeight=5

Fixed campaign window at 4x weight

/api/random?timeStart=2026-05-01T00%3A00%3A00&timeEnd=2026-05-31T23%3A59%3A59&timeZone=Asia%2FShanghai&timeWeight=4

Parameter Description

Transparency Adjustment Feature

endpoint supports image transparency adjustment. You can adjust image opacity and composite it onto a specified background color.

opacity

Image opacity (0-1.0)

• 0 = fully transparent, 1 = fully opaque • Optional parameter, no transparency processing if not specified

bgColor

Background color

white | black | #hex

Examples

50% opacity, white background

/api/response?opacity=0.5&bgColor=white

80% opacity, black background

/api/response?opacity=0.8&bgColor=black

30% opacity, custom color background

/api/response?opacity=0.3&bgColor=ff6b6b

Response Headers:

Response Format

200 OK

Success Response

API returns the image file directly, not a JSON format response.

Response Headers:

Content-Type: image/jpeg, image/png, image/webp

// Headers

X-Image-Id: ...

X-Image-Filename: ...

X-Response-Time: ...ms

4xx / 5xx

Error Response

400400 Bad RequestInvalid request parameters
403403 ForbiddenAPI service is disabled
404404 Not FoundNo images found matching the criteria
429429 Too Many RequestsRequest frequency too high
500500 Internal Server ErrorInternal server error

Notice

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.