camelAI Documentation

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.

View as Markdown

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:

ts
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 bytes

Over REST

bash
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.png

GET /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.

ts
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>" }:

ts
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-size for the maximum size and optionally min-font-size for 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" (default start), valign="top|middle|bottom" (default middle), and line-height (default 1.2).

SVG rendering limits

LimitValue
Request body16 MiB
SVG source size1 MiB
Output pixels4,194,304 pixels (2048 x 2048)
Input images (files)Up to 16 PNG or JPEG inputs
Per-input image size10 MiB raw, 4,096 px max side, 4,194,304 pixels
Combined input base64 data14 MiB
Text measurements400 per render

Agent built-in image tools

  • builtins: ["images"] exposes render_image({ svg, files?, path }). The agent provides SVG markup, an optional map of image names to repository file paths, and an output path. camelRun renders the PNG, commits it to the agent's repository at path, and shows the rendered image back to the model so it can visually verify its layout.
  • builtins: ["files"] includes view_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:

bash
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.png

Response:

json
{
  "id": "modr-...",
  "model": "omni-moderation-latest",
  "flagged": false,
  "categories": { "...": false },
  "category_scores": { "...": 0.001 },
  "category_applied_input_types": { "...": ["image"] }
}