Documentation
chatular-chat-api
Text to text. Send a message from your own code and read the reply as it is written. It uses the tokens of your plan.
This API answers in words and does not make pictures. For pictures, use chatular-image-api.
Send a message
POST /api/chat answers with server-sent events. To continue the same chat, send the threadId from the done event with your next message.
| Field | Type | What it is |
|---|---|---|
prompt | string | Your message. Required, unless you send images. |
threadId | string | Continue this chat. Leave it out to start a new one. |
images | array | Up to 5 pictures, each { base64, mimeType, thumb }: PNG, JPEG, WebP or GIF, the whole request under 20 MB. mimeType is required; thumb is an optional small preview, in base64, saved with the chat. |
replyLanguage | string | Reply in this language, e.g. "Spanish". |
displayPrompt | string | What the chat saves and shows for this message. Put your own context in prompt and your user's words here. |
curl -N https://api.chatular.ai/api/chat \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a tagline for a sneaker shop"}'
In JavaScript:
const res = await fetch('https://api.chatular.ai/api/chat', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: 'Write a tagline for a sneaker shop' }),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = '', reply = '', threadId = null;
for (;;) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const events = buffer.split('\n\n');
buffer = events.pop();
for (const e of events) {
if (!e.startsWith('data: ')) continue;
const event = JSON.parse(e.slice(6));
if (event.type === 'delta') reply += event.text;
if (event.type === 'done') threadId = event.threadId; // send it next time to continue
}
}
In Python:
import json, requests
res = requests.post(
"https://api.chatular.ai/api/chat",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"prompt": "Write a tagline for a sneaker shop"},
stream=True,
)
for line in res.iter_lines():
if line.startswith(b"data: "):
event = json.loads(line[6:])
if event["type"] == "delta":
print(event["text"], end="", flush=True)
elif event["type"] == "done":
thread_id = event["threadId"] # send it next time to continue
Events
start | The reply has started. |
delta | The next piece of the reply. |
done | The whole reply, its threadId and the tokens it used. |
error | Something went wrong; text says what. |
data: {"type":"start","threadId":null}
data: {"type":"delta","text":"Step into"}
data: {"type":"delta","text":" your next."}
data: {"type":"done","text":"Step into your next.","threadId":"k3J9…","inputTokens":812,"outputTokens":9}
Your chats and usage
| Method | Path | What it is |
|---|---|---|
| GET | /api/chat/history | Your API chats, newest first (source=all adds the apps') |
| GET | /api/chat/history/:id | One chat with its messages |
| DELETE | /api/chat/history/:id | Delete a chat |
| GET | /api/chat/quota | Tokens used in this window, and when it resets |
| GET | /api/chat/whoami | The account a key belongs to |
curl https://api.chatular.ai/api/chat/history \
-H "Authorization: Bearer YOUR_API_KEY"