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.

/v1/randomimage GET

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

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


Parameters

  • category  optional

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

  • width  optional

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

  • height  optional

    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.

Sample Request Live Demo!

category
https://api.api-ninjas.com/v1/randomimage?category=nature

Sample Response

IMAGE

Code Examples

1 2 3 4 5 6 7 8 9 10 11 import requests import shutil category = 'nature' api_url = 'https://api.api-ninjas.com/v1/randomimage?category={}'.format(category) response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY', 'Accept': 'image/jpg'}, stream=True) if response.status_code == requests.codes.ok: with open('img.jpg', 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) else: print("Error:", response.status_code, response.text)

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.