Generate an image
Create images with the ShareAI Images API using a supported model, a text prompt and validated image-generation options.
On this page
https://api.shareai.now/api/v1/images/generationsGenerate an image from a text prompt.
- Base URL
https://api.shareai.now- Authentication
- Bearer API key or approved OAuth access token
Use an image model currently enabled on ShareAI and allowed by your credential. The model determines which sizes, quality levels and output options it supports.
Send a request#
cURL
curl --fail-with-body --request POST \
"https://api.shareai.now/api/v1/images/generations" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_IMAGE_MODEL",
"prompt": "A quiet forest painted in watercolor.",
"n": 1,
"size": "1024x1024"
}'
Python
import json
import os
import urllib.request
headers = {"Authorization": "Bearer " + os.environ["SHAREAI_API_KEY"]}
headers["Content-Type"] = "application/json"
payload = {'model': 'YOUR_IMAGE_MODEL', 'prompt': 'A quiet forest painted in watercolor.', 'n': 1, 'size': '1024x1024'}
data = json.dumps(payload).encode()
request = urllib.request.Request('https://api.shareai.now/api/v1/images/generations', data=data, headers=headers, method='POST')
with urllib.request.urlopen(request, timeout=180) as response:
print(json.load(response))
TypeScript
const url = "https://api.shareai.now/api/v1/images/generations";
const headers: Record = {
Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`,
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "YOUR_IMAGE_MODEL",
"prompt": "A quiet forest painted in watercolor.",
"n": 1,
"size": "1024x1024"
};
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
console.log(await response.json());
Request fields#
| Field | Value |
|---|---|
model | An enabled image-generation model ID. |
prompt | A nonempty text description. |
n | Number of images, from 1 to 10, subject to model support. |
size / quality | Optional model-supported size and quality values. |
response_format / output_format | Optional model-supported response and file-format settings. |
background | Optional background setting supported by the model. |
Read the image#
Inspect the returned data entries. Depending on the model and requested format, an entry contains an HTTPS image URL or base64 image data. Use the actual returned format; do not assume every provider returns a URL. The API does not download returned image URLs for you.
Size and timing limits#
Requests are synchronous. Combined text is limited to 256 KiB, the provider call to 120 seconds and the response to 2 MiB. Large base64 images can exceed that response limit. Select a suitable output size or a model that supports URL output.
Retry carefully#
Generating an image can incur usage. After a timeout or an ambiguous network failure, check activity before retrying; repeating the request can generate and charge for another image. The API does not automatically retry an image request after submission to a provider.
Supported operations#
This route generates images from text. Image edits, variations, multipart uploads and streaming image generation are not supported. Current billing requires a compatible model/provider token-usage contract; per-image-only providers may be unavailable.
Use customer authorization#
For an approved OAuth flow, send the access token as Bearer. Account-funded image generation requires surcharge and an accepted usage plan. All model, provider and account restrictions remain in force.
Last updated September 15, 2026