NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

Random Image API

The Random Image API generates random images for all your placeholder and design needs. It supports custom sizes as well as custom image categories.

(4.6)

From 2,721 users

1,600+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
190ms203ms249ms444ms1049ms

Didn't find what you were looking for? Suggest an improvement


/v1/randomimage GET

https://api.api-ninjas.com/v1/randomimage

Returns a random, base64-encoded image in JPEG format.

Parameters

  • category  optionalpremium only

    Image category. If set, must be one of the following: nature, city, technology, food, still_life, abstract, wildlife.

  • width  optionalpremium only

    Width of the image to generate. Must be between 1 and 5000. Default value is 640.

  • height  optionalpremium only

    Height of the image to generate. Must be between 1 and 5000. Default value is 480.

Headers

  • X-Api-Key  required

    API Key associated with your account.

  • Accept  required

    Header indicating the content type to accept in the result. Must be set to the following: image/jpg.

Response

Returns a random image in JPG format. The response body is binary image data. Returns an error if the request is unsuccessful.

Sample Request Live Demo!

category premium
width premium
height premium

Try our APIs in the API playground

Sign up for a free API key to get started — no credit card required.

https://api.api-ninjas.com/v1/randomimage

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

IMAGE

Code Examples

1 2 3 curl -X GET "https://api.api-ninjas.com/v1/randomimage?category=wildlife" \ -H "X-Api-Key: YOUR_API_KEY" \ --output random_image.jpg

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the Random Image API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • Use the optional width and height parameters (each between 1 and 5000, defaulting to 640 and 480) to set dimensions, and the category parameter to pick a subject: nature, city, technology, food, still_life, abstract, or wildlife. All three parameters are premium-only, so you'll need a paid plan from our pricing page to use them.
  • The endpoint returns a random, base64-encoded image in JPEG format, so you must include the required Accept header set to image/jpg on your request. The response body is binary image data, or an error if the request is unsuccessful.
  • It's ideal for generating placeholder images during web and app design, populating mockups with category-specific visuals like food or wildlife, and seeding test data with realistic graphics. Pair it with our Random User and Random Word APIs to build complete sample datasets, or browse all available APIs.