npm package
@svgnew/sdk
The official TypeScript SDK for the SVG.new API. Vectorize images, edit colors, simplify palettes, remove backgrounds, and batch process — all type-safe.

Quick start
Vectorize in 3 lines
import { SvgNew } from '@svgnew/sdk';
import { readFileSync, writeFileSync } from 'fs';
const client = new SvgNew('svk_your_api_key');
// Convert an image to SVG
const image = readFileSync('photo.png', 'base64');
const { svg } = await client.vectorize({
image: `data:image/png;base64,${image}`,
});
writeFileSync('output.svg', svg);Methods
Full API
client.vectorize(input)
Convert a raster image to SVG. Costs 1 credit.
const { id, svg, metadata } = await client.vectorize({
image: 'data:image/png;base64,...',
});
// metadata.credits_remaining → 997client.recolor(input)
Change colors in an SVG. Free — no credit cost.
const { svg } = await client.recolor({
svg: svgString,
colorMap: { '#ff0000': '#0000ff', '#00ff00': '#ffff00' },
});client.simplify(input)
Reduce the color count. Free — no credit cost.
const { svg, colorsBefore, colorsAfter } = await client.simplify({
svg: svgString,
maxColors: 8,
});
// colorsBefore → 142, colorsAfter → 8client.removeBackground(input)
Remove the background from an SVG. Costs 1 credit.
const { svg } = await client.removeBackground({
svg: vectorizedSvg,
image: 'data:image/png;base64,...', // original raster
});client.batch(images)
Submit multiple images for vectorization. 1 credit each.
const batch = await client.batch([
{ image: 'data:image/png;base64,...' },
{ image: 'data:image/png;base64,...' },
]);
const status = await client.getBatchStatus(batch.batchId);
// status.items → [{ index, status, svg }, ...]Configuration
Options
// Simple — just an API key
const client = new SvgNew('svk_your_api_key');
// Full options
const client = new SvgNew({
apiKey: 'svk_your_api_key',
baseUrl: 'https://svg.new', // default
timeout: 120_000, // 2 min default
});Error handling
import { SvgNew, SvgNewError } from '@svgnew/sdk';
try {
await client.vectorize({ image: '...' });
} catch (e) {
if (e instanceof SvgNewError) {
console.log(e.status); // 401, 402, 429, etc.
console.log(e.code); // 'login_required', 'upgrade_required', etc.
console.log(e.message); // Human-readable error
}
}Why use the SDK
Type-safe
Full TypeScript types for inputs, outputs, and errors. Autocomplete everywhere.
Zero dependencies
Uses the standard Fetch API. Works in Node.js 18+ and modern browsers.
Dual format
Ships as both ESM and CommonJS. Works with import and require.
Error classes
SvgNewError with status code, error code, and message. No guessing.
Configurable timeout
Default 2-minute timeout with per-client override. AbortController under the hood.
Batch support
Submit up to 50 images at once and poll for results.
FAQ
Common questions
What runtimes does the SDK support?
The SDK works in Node.js 18+ and modern browsers. It uses the standard Fetch API with no native dependencies.
How do I get an API key?
Sign up at svg.new, then go to svg.new/account to generate an API key. Keys start with svk_ and are shown only once.
What does vectorization cost?
Each vectorization costs 1 credit. Recolor and simplify are free. The free plan includes 3 credits per day. Pro plans start at $9.99/month with 1,000 credits.
Can I use the SDK in a browser app?
Yes. The SDK uses the Fetch API and works in browsers. However, your API key would be exposed in client-side code, so it's best to proxy through your own backend.
Start building
Install the SDK, get an API key, and vectorize your first image in under a minute.