Text to Image API Guide

A text to image generation guide for developers interested in accessing Stable diffusion API for their applications - Powered by MonsterAPI.

Text to Image API Guide


Welcome to our guide for the Text-to-Image Generation on MonsterAPI, powered by Pix-Art-Sigma.

MonsterAPI brings access to powerful Generative AI models to developers, allowing them to build applications that leverage the latest advances in machine learning. State-of-the-art language models, including Stable Diffusion, Pix2Pix, Whisper, and Falcon-7B instruct can be accessed using our scalable REST APIs.

Monster API hosts these Generative AI models and offers them to developers via easy-to-consume APIs at up to 80% lower cost than other alternatives.

In this guide, we'll focus on the Text to Image API, which generates realistic and high-quality images from text prompts.

📝 Getting Started:

1. Get Auth Keys

  • Signup/Login to MonsterAPI dashboard.
  • Once you sign up, your Auth key will automatically be created.
MonsterAPI Auth Key

Your auth key gives you access to our APIs. You must use this key in all your API Requests. For more information on how to use your Auth Key, read this auth key documentation.

2. Generate an Image:

To generate an image using the Text to Image Monster API, you need to follow this workflow:

  1. Send request API: Use this API to send a request for image generation
  2. Fetch status API: Use this API to fetch status of your image generation request

First we send an image generation request as follows:

📔
Send request API example:
import requests
import json

url = "https://api.monsterapi.ai/apis/add-task"

payload = json.dumps({
  "model": "txt2img",
  "data": {
    "prompt": "Elon Musk as Napoleon Bonaparte, intricate, elegant, highly detailed, digital painting, artstation, concept art, matte, sharp focus, illustration, art by greg rutkowski and alphonse mucha, closeup shot",

    "negprompt": "lowres, signs, memes, labels, text, food, text, error, mutant, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, made by children, caricature, ugly, boring, sketch, lacklustre, repetitive, cropped, (long neck), facebook, youtube, body horror, out of frame, mutilated, tiled, frame, border, porcelain skin, doll like, doll, bad quality, cartoon, lowres, meme, low quality, worst quality, ugly, disfigured, inhuman",

    "samples": 1,
    "steps": 50,
    "aspect_ratio": "square",
    "guidance_scale": 12.5,
    "seed": 2321
  }
})
headers = {
  'x-api-key': 'YOUR_X_API_KEY',
  'Authorization': 'Bearer YOUR_AUTH_TOKEN',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

On running the above send request API you should get a process ID as follows:

{
  "message": "Request accepted successfully",
  "process_id": "058c604c-aacb-11ed-a970-d78ebbbbe581"
}

Once we have a process ID, we query the status of this process using Fetch status API:

📔
Fetch status API example:
import requests
import json

url = "https://api.monsterapi.ai/apis/task-status"

payload = json.dumps({
  "process_id": "058c604c-aacb-11ed-a970-d78ebbbbe581"
})
headers = {
  'x-api-key': 'YOUR_X_API_KEY',
  'Authorization': 'Bearer YOUR_AUTH_TOKEN',

  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

Fetch status API will return the status of your process ID and it can be one of the following:

  • IN_QUEUE
  • IN_PROGRESS
  • COMPLETED
  • FAILED

Once the request status is "COMPLETED", you will receive the generated image URLs in the fetch status API's output.

Text to Image Playground:

If you don't want to try the API and need an easy method to experiment with our APIs, then you can try out our Text to Image Playground which lets you generate images in real time without any code setup.

Text to Image playground looks like this:

Below is a gallery of images generated using our Text to Image Generation API. Feel free to replicate them while generating new images!

Elon Musk as Napoleon Bonaparte, intricate, elegant, highly detailed, digital painting, artstation, concept art, matte, sharp focus, illustration, art by greg rutkowski and alphonse mucha, closeup shot
steve jobs as realistic portrait, symmetrical, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, cinematic lighting, some reflexions, natural autumn sunlights
Ultra detailed facial portrait of beautiful woman, wearing cowboy hat, extremely detailed digital painting, in the style of préraphaélite, mystical colors, rim light,electric lighting, 8 k, stunning scene, west american
hyper close up photography of a majestic long ear kitsune spirit, ethereal ghost veil, japanese forest scenery, adorable, summer background, dynamic focus, round eyes, Hyperrealist, photography, 8k, ultra high quality,
"((PHOTOREALISTIC)), RAW, beautiful landscape, ((large valley)), 8k, ((pine trees, grass details)), mountain in background, small lake, mountain reflection on water, photo from highgroung, realistic photo, breath taking, sharp lense, professional photographic, 70mm lense, detail love, good quality, wallpaper, colorful, highly detailed, 8k, soft light, photo realistic, spring, sharp detail, ((sunrise light)), masterpiece, <lora:Reflections:0.8>"
60s cartoon style photo of a huge savage skelton robot in far off galaxy, style of Hannah Barbara, studio ghibli, akira toriyama, james gilleard, warner brothers, trending pixiv fanbox, acrylic palette knife, 8k, vibrant

Summing Up:

Monster API is the perfect solution for businesses and developers looking for efficient and effective image generation. With auto-scaling APIs and no need for management, you can focus on creating stunning visuals without worrying about the technical details. Try it out today and take your image generation to the next level!