Guides
Images, SVG rendering, and image moderation in camelRun v2
Generate images with POST /v2/images, render SVG cards to PNG with POST /v2/images/render, moderate images, and enable render_image and view_image.
camelRun v2 provides endpoints for generating images (POST /v2/images), fetching stored images (GET /v2/images/:id), rendering SVG cards to PNG (POST /v2/images/render), and moderating images (POST /v2/moderations/images), plus built-in agent tools for rendering and inspecting images in CamelFS repositories.
Generate and retrieve images
POST /v2/images generates an image (using gpt-image-1 by default, with your tenant OpenAI key or the platform key), stores it in R2, settles usage, and returns its ID and URL:
const generated = await client.media.generateImage({
prompt: "A watercolor camel crossing desert dunes at dawn",
model: "gpt-image-1",
size: "1024x1024",
});
// { id: "img_...", url: "/v2/images/img_...", contentType: "image/png", sizeBytes: ..., costUsd: 0.04 }
const fetched = await client.media.getImage(generated.id);
// fetched.data is a Uint8Array of the image bytesOver REST
curl -s -X POST "https://run.camelai.com/v2/images" \
-H "Authorization: Bearer $CAMELRUN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A watercolor camel crossing desert dunes at dawn",
"size": "1024x1024"
}'
# Download the image bytes
curl -s "https://run.camelai.com/v2/images/$IMAGE_ID" \
-H "Authorization: Bearer $CAMELRUN_API_KEY" \
-o camel.pngGET /v2/images/:id returns the raw image bytes with Cache-Control: public, max-age=31536000, immutable. If an Authorization header is sent, camelRun verifies the image belongs to that tenant (403 forbidden otherwise).
Render SVG cards to PNG (POST /v2/images/render)
POST /v2/images/render renders an SVG document to PNG and returns { contentType: "image/png", width, height, data } where data is base64-encoded PNG bytes.
import { writeFile } from "node:fs/promises";
const card = await client.images.render(
'<svg width="440" height="80"><textbox x="16" y="10" width="408" height="60" ' +
'font-family="Sans" font-size="32" font-weight="bold">Maria da Conceição</textbox></svg>',
);
await writeFile("card.png", Buffer.from(card.data, "base64"));To embed raster images inside your SVG, reference them by name in <image href="photo.png"> and pass a files map where each value is either a tenant media ID ("img_..." from POST /v2/images) or { data: "<base64>" }:
const badge = await client.images.render(
'<svg width="400" height="120"><image href="avatar.png" x="16" y="16" width="88" height="88" /></svg>',
{
files: {
"avatar.png": { data: avatarBase64 },
},
},
);<textbox> layout element
<textbox> accepts plain text, x, y, width, height, fill, and standard font family, weight, and style attributes:
- Set
font-sizefor the maximum size and optionallymin-font-sizefor the one-line and wrapping threshold (defaults to 60%). - The renderer tries one line first, then wraps at spaces and after hyphens, commas, and slashes. It can shrink down to 8 px and split long words at grapheme boundaries to fit. If the box is too small for the full text, the request fails with
400 invalid_svg. - Alignment and spacing options:
align="start|middle|end"(defaultstart),valign="top|middle|bottom"(defaultmiddle), andline-height(default1.2).
SVG rendering limits
| Limit | Value |
|---|---|
| Request body | 16 MiB |
| SVG source size | 1 MiB |
| Output pixels | 4,194,304 pixels (2048 x 2048) |
Input images (files) | Up to 16 PNG or JPEG inputs |
| Per-input image size | 10 MiB raw, 4,096 px max side, 4,194,304 pixels |
| Combined input base64 data | 14 MiB |
| Text measurements | 400 per render |
Agent built-in image tools
builtins: ["images"]exposesrender_image({ svg, files?, path }). The agent provides SVG markup, an optional map of image names to repository file paths, and an outputpath. camelRun renders the PNG, commits it to the agent's repository atpath, and shows the rendered image back to the model so it can visually verify its layout.builtins: ["files"]includesview_image({ path, at? }), which lets the model inspect any existing PNG, JPEG, GIF, or WebP stored in its repository (optionally at a specific ref or commit).
Moderate images (POST /v2/moderations/images)
POST /v2/moderations/images checks a raw image/jpeg or image/png body (up to 5 MiB) against OpenAI's omni-moderation-latest model using your tenant OpenAI key or the platform key:
curl -s -X POST "https://run.camelai.com/v2/moderations/images" \
-H "Authorization: Bearer $CAMELRUN_API_KEY" \
-H "Content-Type: image/png" \
--data-binary @upload.pngResponse:
{
"id": "modr-...",
"model": "omni-moderation-latest",
"flagged": false,
"categories": { "...": false },
"category_scores": { "...": 0.001 },
"category_applied_input_types": { "...": ["image"] }
}