Skip to main content

Generate an Image

Learn how to generate image with UmamiAI API.

Generate an image from a text prompt.​

Generates an image based on a prompt using a model, typically leveraging generative AI models like DALL-E for image synthesis from text descriptions.

Example​

JavaScript

const axios = require('axios').default;
const fs = require('fs');

const main = async () => {
const result = await axios.post(
'https://api.umamiai.xyz/v1/images/generations',
{
prompt: 'Hyperrealistic art featuring a cat in costume.',
model: 'stable-diffusion-v35-large'
},
{
headers: {
Authorization: 'Bearer <YOUR_UMAMIAI_API_KEY>',
},
},
);

fs.writeFileSync('./image.png', result.data.output.choices[0].image_base64, 'base64');
};

main();

Python

import requests
import base64


def main():
headers = {
"Authorization": "Bearer <YOUR_UMAMIAI_API_KEY>",
}

payload = {
"prompt": "Hyperrealistic art featuring a cat in costume.",
"model": "stable-diffusion-v35-large",
}

response = requests.post(
"https://api.umamiai.xyz/v1/images/generations", headers=headers, json=payload
)

image_base64 = response.json()["output"]["choices"][0]["image_base64"]
image_data = base64.b64decode(image_base64)

with open("./image.png", "wb") as file:
file.write(image_data)


main()

path=/images/generations method=post

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/images/generations', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY"
},
body: JSON.stringify({
"prompt": "text"
}),
});
const data = await response.json();

Python

import requests

response = requests.post(
"https://api.umamiai.xyz/v1/images/generations",
headers={"Content-Type":"application/json","Authorization": "Bearer YOUR_UMAMIAI_API_KEY"},
json={"prompt":"text"}
)
data = response.json()

Curl

curl -L \
-X POST \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
-H 'Content-Type: application/json' \
'https://api.umamiai.xyz/v1/images/generations' \
-d '{"prompt":"text"}'

Response

{
"created": 0,
"data": [
{
"b64_json": "text",
"revised_prompt": "text",
"url": "text"
}
]
}