API reference
Generate an image
POST /api/pub/v1/images — generate an image from a prompt and get the bytes back as base64.
POST https://api.dhanu.ai/api/pub/v1/images
Generates an image and returns the bytes as base64. Dhanu stores nothing — no task, no document, no version history. Save the bytes yourself.
Request
| Field | Type | Required | Notes |
|---|---|---|---|
prompt | string | Yes | Up to 2000 characters |
aspectRatio | string | No | 1:1, 3:4, 9:16, 4:3, or 16:9 |
projectId | string | No | Required when the key is scoped to more than one project |
curl -X POST https://api.dhanu.ai/api/pub/v1/images \
-H "Authorization: Bearer $DHANU_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "a red bicycle on a white background",
"aspectRatio": "1:1"
}'
Response
201 Created
{
"image": { "b64": "…", "mimeType": "image/png" },
"model": "…",
"usage": { "inputTokens": 9, "outputTokens": 0 },
"cost": { "amount": 800, "currency": "NPR" }
}
cost.amount is in the currency’s minor unit, so 800 is NPR 8.00 — roughly what
a typical image costs.
Saving the bytes
import { writeFileSync } from "node:fs";
const response = await fetch("https://api.dhanu.ai/api/pub/v1/images", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DHANU_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: "a red bicycle", aspectRatio: "1:1" }),
});
const { image } = await response.json();
writeFileSync("out.png", Buffer.from(image.b64, "base64"));
Errors
| Code | Status | Meaning |
|---|---|---|
invalid_generation_prompt | 422 | Prompt is empty or over 2000 characters |
invalid_image_aspect_ratio | 422 | Aspect ratio is not one of the five supported |
project_id_required | 422 | Multi-project key called without projectId |
insufficient_credits | 402 | Workspace credit balance is zero or below |
The full list is on Errors.