API Docs
v1.0.0

API Reference

The ToSVG API lets you convert images to SVG, remove backgrounds, and resize images programmatically. All endpoints accept multipart/form-data requests and return JSON responses.

Base URL

https://tosvg.com/api/v1

Quick Start

Make your first API call in seconds. Get your API key from the dashboard, then:

curl -X POST "https://tosvg.com/api/v1/convert/image-to-svg" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "[email protected]" \
  -F "options[color_mode]=color"
Formats
PNG, JPG, BMP, GIF, TIFF, WebP
Max File Size
10 MB
Max Dimensions
4096 × 4096 px

Authentication

Authenticate requests by including your API key in the X-API-Key header.

You need an API key to make requests. Create a free account to get started.

API Key Format

tosvg_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Prefix
Environment (live / test)
32-char identifier

Request Header

X-API-Key: tosvg_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You can also use Authorization: Bearer YOUR_KEY as an alternative.

Security Best Practices

  • Store API keys in environment variables, never in source code
  • Use test keys during development, live keys in production
  • Rotate keys regularly and restrict by IP when possible
  • Never expose API keys in client-side code or public repos

Endpoints

Core API endpoints for image processing. All require authentication via API key.

POST/api/v1/convert/image-to-svg

Image to SVG Conversion

Convert various image formats to scalable vector graphics (SVG). Supports multiple color modes and conversion algorithms for optimal results.

Parameters

NameTypeDescription
imagerequired
fileImage file (PNG, JPG, JPEG, BMP, GIF, TIFF, WebP)
options.color_mode
stringColor mode: color or bw (black & white)Default: color
colorbw
options.mode
stringConversion mode: polygon (sharp edges) or spline (smooth curves)Default: polygon
polygonspline
options.filter_speckle
integerFilter speckle size - removes noise (0-20)Default: 8
options.corner_threshold
integerCorner threshold angle in degrees (0-180)Default: 30
options.color_precision
integerColor precision level (1-10, higher = more colors)Default: 4

Example Request

curl -X POST "https://tosvg.com/api/v1/convert/image-to-svg" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "[email protected]" \
  -F "options[color_mode]=color" \
  -F "options[mode]=spline"
POST/api/v1/background/remove

Remove Background

Remove background from images using advanced AI models. Perfect for product photos, portraits, and any image that needs a transparent background.

Parameters

NameTypeDescription
imagerequired
fileImage file (PNG, JPG, JPEG, WebP, TIFF)
model
stringAI model to use for background removalDefault: u2net
u2netisnet-general-useisnet-anime
format
stringOutput image formatDefault: png
pngjpgjpegwebp

Example Request

curl -X POST "https://tosvg.com/api/v1/background/remove" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "[email protected]" \
  -F "model=u2net" \
  -F "format=png"
POST/api/v1/resize/image

Image Resize

Resize images with high-quality algorithms. Supports aspect ratio preservation, custom dimensions, and multiple output formats.

Parameters

NameTypeDescription
imagerequired
fileImage file (All formats supported)
widthrequired
integerTarget width in pixels (1-4096)
heightrequired
integerTarget height in pixels (1-4096)
quality
integerOutput image quality (1-100)Default: 90
format
stringOutput image formatDefault: png
pngjpgjpegwebp
maintain_aspect_ratio
booleanMaintain original aspect ratioDefault: true

Example Request

curl -X POST "https://tosvg.com/api/v1/resize/image" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "[email protected]" \
  -F "width=800" \
  -F "height=600" \
  -F "quality=90" \
  -F "format=webp"

Info Endpoints

Utility endpoints for checking API status and capabilities. No authentication required.

GET/api/v1/testPublic

Test if the API is working correctly. Returns basic API information.

GET/api/v1/healthPublic

Check the health status of all services including database and storage.

GET/api/v1/convert/supported-formatsPublic

Get list of supported image formats and their limitations.

GET/api/v1/background/modelsPublic

Get available AI models for background removal with descriptions.

GET/api/v1/resize/limitsPublic

Get resize operation limits and constraints.

Rate Limits

API requests are limited based on your subscription plan. Limits reset daily at 00:00 UTC.

PlanDaily LimitPer HourPer Minute
Free000
Starter000
Pro000
Enterprise000

Rate Limit Headers

Every API response includes rate limit information in the headers:

X-RateLimit-LimitMaximum requests allowed per day
X-RateLimit-RemainingRequests remaining in the current period
X-RateLimit-ResetUnix timestamp when the limit resets

429 Too Many Requests — When you exceed your rate limit, the API returns a 429 status with a Retry-After header indicating seconds to wait. Our official SDKs handle this automatically with exponential backoff.

Error Codes

The API returns standard HTTP status codes with a JSON error body containing a machine-readable code field.

Error Response Format
{
  "success": false,
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid"
  }
}

SDKs & Libraries

Official SDKs to integrate ToSVG into your application. Use the SDK for your preferred language, or call the REST API directly.

TypeScript-first SDK with zero dependencies. Supports file path, Buffer, and ReadStream inputs. Auto retry on rate limit with exponential backoff.

TypeScript-firstZero dependenciesAuto retryESM + CJS
$ npm install @tosvg/node

Quick Start

Node.js
import { ToSVGClient } from "tosvg-api";

const client = new ToSVGClient("tosvg_live_your_api_key");

// Convert image to SVG
const result = await client.imageToSvg("./photo.png", {
  colorMode: "color",
  mode: "spline"
});
console.log(result.svg);

// Remove background
const bg = await client.removeBackground("./photo.png", {
  returnBase64: true
});

// Resize image
const resized = await client.resizeImage("./photo.png", {
  width: 800,
  height: 600
});

Detailed Examples

Image to SVG
import { ToSVGClient } from "tosvg-api";
import { writeFileSync } from "node:fs";

const client = new ToSVGClient(process.env.TOSVG_API_KEY);

const result = await client.imageToSvg("./logo.png", {
  colorMode: "bw",
  mode: "spline",
  colorPrecision: 8
});

writeFileSync("./logo.svg", result.svg);
console.log(`Converted in ${result.conversionTime}s`);
Remove Background
const bg = await client.removeBackground("./portrait.jpg", {
  provider: "rembg",
  model: "isnet-general-use",
  returnBase64: true,
  format: "png"
});

writeFileSync("./portrait-nobg.png", Buffer.from(bg.image, "base64"));
Resize Image
const resized = await client.resizeImage("./photo.png", {
  width: 1200,
  height: 630,
  format: "webp",
  quality: 80,
  maintainAspectRatio: true
});

console.log(resized.dimensions); // { width: 1200, height: 630 }
🔧

Use any HTTP client

The ToSVG API is a standard REST API. You can use any HTTP client (cURL, fetch, Axios, httpx, Guzzle, etc.) to make requests directly. View all repos on GitHub →

Ready to get started?

Create your free account and start converting images in minutes.