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/v1Quick 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"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
live / test)Request Header
X-API-Key: tosvg_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxYou can also use Authorization: Bearer YOUR_KEY as an alternative.
Security Best Practices
- •Store API keys in environment variables, never in source code
- •Use
testkeys during development,livekeys 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.
/api/v1/convert/image-to-svgImage to SVG Conversion
Convert various image formats to scalable vector graphics (SVG). Supports multiple color modes and conversion algorithms for optimal results.
Parameters
| Name | Type | Description |
|---|---|---|
imagerequired | file | Image file (PNG, JPG, JPEG, BMP, GIF, TIFF, WebP) |
options.color_mode | string | Color mode: color or bw (black & white)Default: colorcolorbw |
options.mode | string | Conversion mode: polygon (sharp edges) or spline (smooth curves)Default: polygonpolygonspline |
options.filter_speckle | integer | Filter speckle size - removes noise (0-20)Default: 8 |
options.corner_threshold | integer | Corner threshold angle in degrees (0-180)Default: 30 |
options.color_precision | integer | Color 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"/api/v1/background/removeRemove Background
Remove background from images using advanced AI models. Perfect for product photos, portraits, and any image that needs a transparent background.
Parameters
| Name | Type | Description |
|---|---|---|
imagerequired | file | Image file (PNG, JPG, JPEG, WebP, TIFF) |
model | string | AI model to use for background removalDefault: u2netu2netisnet-general-useisnet-anime |
format | string | Output image formatDefault: pngpngjpgjpegwebp |
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"/api/v1/resize/imageImage Resize
Resize images with high-quality algorithms. Supports aspect ratio preservation, custom dimensions, and multiple output formats.
Parameters
| Name | Type | Description |
|---|---|---|
imagerequired | file | Image file (All formats supported) |
widthrequired | integer | Target width in pixels (1-4096) |
heightrequired | integer | Target height in pixels (1-4096) |
quality | integer | Output image quality (1-100)Default: 90 |
format | string | Output image formatDefault: pngpngjpgjpegwebp |
maintain_aspect_ratio | boolean | Maintain 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.
/api/v1/testPublicTest if the API is working correctly. Returns basic API information.
/api/v1/healthPublicCheck the health status of all services including database and storage.
/api/v1/convert/supported-formatsPublicGet list of supported image formats and their limitations.
/api/v1/background/modelsPublicGet available AI models for background removal with descriptions.
/api/v1/resize/limitsPublicGet resize operation limits and constraints.
Rate Limits
API requests are limited based on your subscription plan. Limits reset daily at 00:00 UTC.
| Plan | Daily Limit | Per Hour | Per Minute |
|---|---|---|---|
| Free | 0 | 0 | 0 |
| Starter | 0 | 0 | 0 |
| Pro | 0 | 0 | 0 |
| Enterprise | 0 | 0 | 0 |
Rate Limit Headers
Every API response includes rate limit information in the headers:
X-RateLimit-Limit | Maximum requests allowed per day |
X-RateLimit-Remaining | Requests remaining in the current period |
X-RateLimit-Reset | Unix 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.
{
"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.
Quick Start
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
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`);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"));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.