Documentation
chatular-image-api
Two calls for making pictures: text to image and image to image. The answer holds the finished picture. They need the same API key.
How it works
POST /api/image/text-to-image, or your words and a picture to POST /api/image/image-to-image.file address, with your key.Text to image
POST /api/image/text-to-image. Makes a new picture from your words.
| Field | Type | What it is |
|---|---|---|
prompt | string | What to create, in any language, up to 2,500 characters. Required. |
shape | string | square, portrait, tall or wide. Leave it out and the words decide, else square. |
count | number | How many pictures, 1 to 4. The default is 1. |
curl https://api.chatular.ai/api/image/text-to-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt":"A perfume poster, Velvet Night, new scent","shape":"tall"}'
In JavaScript:
import { writeFile } from 'node:fs/promises';
const res = await fetch('https://api.chatular.ai/api/image/text-to-image', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: 'A perfume poster, Velvet Night, new scent', shape: 'tall' }),
});
const { pictures } = await res.json();
// Download the first picture
const file = await fetch('https://api.chatular.ai' + pictures[0].file, {
headers: { Authorization: 'Bearer YOUR_API_KEY' },
});
await writeFile('poster.png', Buffer.from(await file.arrayBuffer()));
In Python:
import requests
API = "https://api.chatular.ai"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
res = requests.post(
API + "/api/image/text-to-image",
headers=headers,
json={"prompt": "A perfume poster, Velvet Night, new scent", "shape": "tall"},
)
pictures = res.json()["pictures"]
# Download the first picture
file = requests.get(API + pictures[0]["file"], headers=headers)
with open("poster.png", "wb") as f:
f.write(file.content)
Image to image
POST /api/image/image-to-image. Changes the picture you send, as your words say. A picture you send is kept in your account for later, as one added in the app is.
| Field | Type | What it is |
|---|---|---|
prompt | string | What to change, in any language, up to 2,500 characters. Required. |
image | object | The picture to change, { base64 }: PNG, JPEG or WebP under 10 MB. Required. |
shape | string | square, portrait, tall or wide. Leave it out and the picture keeps its own shape. Another shape can crop it. |
count | number | How many pictures, 1 to 4. The default is 1. |
curl https://api.chatular.ai/api/image/image-to-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt":"Make the sneakers white","image":{"base64":"iVBORw0KGgo…"}}'
In Python, from a file:
import base64, requests
API = "https://api.chatular.ai"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
with open("photo.png", "rb") as f:
photo = base64.b64encode(f.read()).decode()
res = requests.post(
API + "/api/image/image-to-image",
headers=headers,
json={"prompt": "Make the sneakers white", "image": {"base64": photo}},
)
pictures = res.json()["pictures"]
The answer
Both calls answer the same way:
{
"pictures": [
{
"id": "k3J9…",
"prompt": "A perfume poster, Velvet Night, new scent",
"shape": "tall",
"width": 576,
"height": 1024,
"createdAt": 1793491200000,
"file": "/api/image/k3J9…/file"
}
],
"failed": 0
}
| Field | What it is |
|---|---|
id | The picture's id. |
prompt | The words you sent. |
shape | The shape it was created in. |
width, height | Its size in pixels. |
createdAt | When it was made, in milliseconds since 1970. |
file | Where to download it. Add it to https://api.chatular.ai. |
failed | How many of the pictures you asked for could not be created. |
limited | Present when your daily limit allowed fewer than you asked for; dailyLimit says what it is. |
Download the picture
GET /api/image/:id/file sends the picture itself, as PNG, JPEG or WebP (see its Content-Type). It needs the key of the account that made it.
curl https://api.chatular.ai/api/image/k3J9…/file \
-H "Authorization: Bearer YOUR_API_KEY" \
--output poster.png
Limits
Each picture counts against your plan's pictures per day, which reset at midnight UTC. A picture that fails does not count. Pictures are kept in your account and also appear in My paints.
Errors
| Status | code | What it means |
|---|---|---|
400 | empty, too_long, bad_shape, bad_count, bad_input, needs_image, image_not_allowed | The words are missing or too long, the shape or the count is wrong, the picture can't be read or is missing, or text to image was sent a picture. |
401 | The key is missing, wrong or revoked. | |
422 | blocked | These words can't be used. Try different ones. |
429 | photo_limit | You have made all your pictures for today. |
502 | failed | The picture could not be created. Try again. |
503 | unavailable | Creating pictures is not available right now. |