ESC
Type to search across all documentation

SVG Generation & Conversion

Two endpoints for producing scalable vector graphics. /svg/generate creates an SVG from a text prompt by running FLUX image generation followed by vtracer vectorization. /svg/convert accepts an uploaded raster image and vectorizes it directly via vtracer. Both endpoints return multiple SVG candidates with different tracing presets. Each call consumes 3 credits.

POST /svg/generate 3 credits

Generate a scalable vector graphic from a text description. FLUX renders an intermediate raster image, then vtracer converts it to clean SVG paths. Multiple vectorization presets are returned so you can choose the best result.

Endpoint

POST https://coals.ai/api/v1/graphicoal/svg/generate
Required scope: graphicoal:generate

Parameters

Parameter Type Required Description
prompt string required Text description of the desired vector graphic. For best results, describe shapes and composition rather than photorealistic scenes. Max 2000 characters.
colormode string optional Vectorization color mode. "color" produces a full-color SVG; "binary" produces a black-and-white SVG. Default: "color".

Request Example

curl -X POST https://coals.ai/api/v1/graphicoal/svg/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Minimalist geometric mountain range logo, three peaks, flat design, bold shapes",
    "colormode": "color"
}'
// Using Guzzle
$response = $client->post('https://coals.ai/api/v1/graphicoal/svg/generate', [
  'headers' => ['Authorization' => 'Bearer YOUR_API_KEY'],
  'json' => [
    "prompt" => "Minimalist geometric mountain range logo, three peaks, flat design, bold shapes",
    "colormode" => "color"
]
]);
$data = json_decode($response->getBody(), true);
# Using requests
import requests

response = requests.post(
  "https://coals.ai/api/v1/graphicoal/svg/generate",
  headers={"Authorization": "Bearer YOUR_API_KEY"},
  json={
    "prompt": "Minimalist geometric mountain range logo, three peaks, flat design, bold shapes",
    "colormode": "color"
}
)
data = response.json()
# Using net/http
require "net/http"
require "json"

uri = URI("https://coals.ai/api/v1/graphicoal/svg/generate")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer YOUR_API_KEY"
req["Content-Type"] = "application/json"
req.body = '{
    "prompt": "Minimalist geometric mountain range logo, three peaks, flat design, bold shapes",
    "colormode": "color"
}'

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
data = JSON.parse(res.body)
// Using fetch (Node 18+)
const response = await fetch("https://coals.ai/api/v1/graphicoal/svg/generate", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "prompt": "Minimalist geometric mountain range logo, three peaks, flat design, bold shapes",
    "colormode": "color"
})
});
const data = await response.json();
POST /svg/convert 3 credits

Upload a raster image (PNG, JPEG, or WebP) and receive back vectorized SVG candidates. Uses vtracer directly without an intermediate generation step, making it ideal for converting logos, icons, and illustrations you already have.

Endpoint

POST https://coals.ai/api/v1/graphicoal/svg/convert
Required scope: graphicoal:convert

Parameters

Parameter Type Required Description
image string required The source image as a base64-encoded data URI (e.g. data:image/png;base64,...). PNG, JPEG, and WebP are supported.
colormode string optional Vectorization color mode. "color" preserves the original colors; "binary" outputs a black-and-white vector. Default: "color".

Request Example

curl -X POST https://coals.ai/api/v1/graphicoal/svg/convert \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
    "colormode": "binary"
}'
// Using Guzzle
$response = $client->post('https://coals.ai/api/v1/graphicoal/svg/convert', [
  'headers' => ['Authorization' => 'Bearer YOUR_API_KEY'],
  'json' => [
    "image" => "data =>image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
    "colormode" => "binary"
]
]);
$data = json_decode($response->getBody(), true);
# Using requests
import requests

response = requests.post(
  "https://coals.ai/api/v1/graphicoal/svg/convert",
  headers={"Authorization": "Bearer YOUR_API_KEY"},
  json={
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
    "colormode": "binary"
}
)
data = response.json()
# Using net/http
require "net/http"
require "json"

uri = URI("https://coals.ai/api/v1/graphicoal/svg/convert")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer YOUR_API_KEY"
req["Content-Type"] = "application/json"
req.body = '{
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
    "colormode": "binary"
}'

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
data = JSON.parse(res.body)
// Using fetch (Node 18+)
const response = await fetch("https://coals.ai/api/v1/graphicoal/svg/convert", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
    "colormode": "binary"
})
});
const data = await response.json();

Response (Both Endpoints)

{
  "success": true,
  "image_id": "img_01jkbv4xt9w2p6r8n7m",
  "svg_url": "https://coals.ai/images/img_01jkbv4xt9w2p6r8n7m_default.svg",
  "svg_candidates": [
    {
      "preset": "default",
      "url": "https://coals.ai/images/img_01jkbv4xt9w2p6r8n7m_default.svg",
      "size_bytes": 18432
    },
    {
      "preset": "detailed",
      "url": "https://coals.ai/images/img_01jkbv4xt9w2p6r8n7m_detailed.svg",
      "size_bytes": 34816
    },
    {
      "preset": "simplified",
      "url": "https://coals.ai/images/img_01jkbv4xt9w2p6r8n7m_simplified.svg",
      "size_bytes": 9216
    }
  ],
  "credits_charged": 3
}

Response Fields

Field Type Description
success boolean Always true on a successful response.
image_id string Unique identifier for this SVG job stored in your gallery.
svg_url string Direct URL to the recommended default SVG candidate.
svg_candidates array Array of SVG outputs from different vtracer presets. Each object contains preset (name), url (hosted SVG URL), and size_bytes (file size).
credits_charged integer Credits deducted from your balance for this operation.

For the cleanest vector output, use high-contrast source images with distinct color regions. Photorealistic images with gradients produce more complex SVG paths and larger file sizes — consider using colormode: "binary" for simpler, more scalable results.