Image Processing Models
We provide several most popular stable diffusion models for scenarios like Texts2Images and Images2Images.
Before started
You should get some parameters before get started : SERVICE_ID
, API_KEY
and MODEL
, you can find them on our dashbord (opens in a new tab).
API reference
Stable-Diffusion-XL & Stable-Diffusion-3.5
/v1/images/generate
Request Parameters
Parameter name | Type | Description | Required |
---|---|---|---|
model | String | Model type, default:stable-diffusion-xl-base-1.0 | yes |
prompt | String | Prompt to render | Yes |
steps | Int | Number of diffusion steps to run. [10, 50], default:30 | No |
height | Int | Image resolution.multiple of 64 >= 128, default:512 | No |
width | Int | Image resolution.multiple of 64 >= 128, default:512 | No |
cfg_scale | Float | How strictly the diffusion process adheres to the prompt text .(higher values keep your image closer to your prompt) [0, 35], default: 7 | No |
seed | Int | Random noise seed. [0, 4294967295], default:0 (0 means random seed) | No |
Response Elements
Parameter name | Type | Description |
---|---|---|
images | bytes | image/png - raw bytes |
/v1/images/control
Request Parameters
Parameter name | Type | Description | Required |
---|---|---|---|
model | String | Model type, default:stable-diffusion-xl-base-1.0 | yes |
prompt | String | Prompt to render | Yes |
image | File | Image file to initilize the diffusion process. | Yes |
negative_prompt | String | Prompt to exclude | No |
steps | Int | Number of diffusion steps to run. [10, 50], default:30 | No |
control_strength | Float | How much influence the init_image has on the diffusion process. [0, 1], default:0.35. | No |
cfg_scale | Float | How strictly the diffusion process adheres to the prompt text.(higher values keep your image closer to your prompt) [0, 35], default: 7 | No |
seed | Int | Random noise seed. [0, 4294967295], default:0 (0 means random seed) | No |
Response Elements
Parameter name | Type | Description |
---|---|---|
image | bytes | image/png - raw bytes |
Usage
python
/v1/images/generate
import requests
import base64
# Define the URL and the payload to send.
url = "https://modelapi.holmesai.xyz/$SERVICE_ID/v1/images/generate"
# Set Authorization header
Headers = { "Authorization" : "Bearer {}".format("$API_KEY") }
payload = {
"model": "$MODEL",
"prompt": "puppy dog",
"steps": 30,
"height": 512,
"width": 512,
"cfg_scale": 10,
}
# Send said payload to said URL through the API.
response = requests.post(url=f'{url}', json=payload, headers=Headers, stream=True)
# Decode and save the image.
with open("output.png", 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
/v1/images/control
import requests
import base64
import json
# Define the URL and the payload to send.
url = "https://modelapi.holmesai.xyz/$SERVICE_ID/v1/images/control"
# Set Authorization header
Headers = { "Authorization" : "Bearer {}".format("$API_KEY") }
file_path = "input.png"
with open(file_path, 'rb') as image_file:
payload = {
"model": "$MODEL",
"prompt": "Put glassed on the dog",
"negative_prompt": "",
"steps": 30,
"cfg_scale": 10,
}
files = {
'image': (file_path, image_file.read(), 'application/octet-stream'), # Binary file
"model": "$MODEL",
}
# Send said payload to said URL through the API.
response = requests.post(url=f'{url}', files=files, data=payload, headers=Headers)
# Decode and save the image.
with open("output.png", 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
curl
/v1/images/generate
curl https://modelapi.holmesai.xyz/$SERVICE_ID/v1/images/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "$MODEL",
"prompt": "a cat ",
"steps": 20,
"height": 512,
"width": 512,
"cfg_scale": 10
}' \
-o out.png
/v1/images/control
curl -X POST https://modelapi.holmesai.xyz/$SERVICE_ID/v1/images/control \
-F "model=$MODEL" \
-F "prompt=add an apple" \
-F "image=@test.png" \
-F "negative_prompt=" \
-F "steps=30" \
-F "cfg_scale=10" \
-H "Authorization: Bearer $API_KEY" \
-o out.png