API Reference

Base URL: https://api.svg.dog

Node.js SDK

The official Node.js client wraps the REST API with full TypeScript support. Zero runtime dependencies, Node.js 18+ native fetch.

bash
npm install @svg.dog/svgdog
typescript
import { optimize } from '@svg.dog/svgdog';
import fs from 'node:fs';

const result = await optimize(fs.readFileSync('icon.svg'), {
  apiKey: process.env.SVGDOG_API_KEY,
});

fs.writeFileSync('icon.min.svg', result.svg);
console.log(`Saved ${result.savingsPercent.toFixed(1)}%`);
View on npm

Authentication

Pass your API key as a Bearer token in the Authorization header. You can get a free key at svg.dog.

Authorization: Bearer svgd_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Plan limits

PlanAuthMax file sizeBatch sizeQuotaURL optimize
AnonymousNone1 MB2020/day
FreeAPI key2 MB10500/month
ProAPI key10 MB50Unlimited
POST/v1/optimize

Optimize a single SVG

Auth: Optional

Uploads an SVG file and returns the optimized version. Anonymous requests are capped at 20/day. Free-plan keys allow up to 500/month.

ParameterTypeRequiredDescription
filemultipart/form-dataYesThe SVG file to optimize.

Request

bash
curl -X POST https://api.svg.dog/v1/optimize \
  -H "Authorization: Bearer <your-key>" \
  -F "file=@icon.svg"

Response

# Binary SVG file returned directly
# Response headers:
X-Original-Size: 4821
X-Optimized-Size: 1204
X-Savings-Percent: 75.04
X-Cached: false
POST/v1/optimize/url

Optimize an SVG from URL

Auth: Required (Free or Pro)

Fetches an SVG from a public URL, optimizes it, and returns the result.

ParameterTypeRequiredDescription
urlstring (JSON body)YesPublicly accessible URL pointing to an SVG file.

Request

bash
curl -X POST https://api.svg.dog/v1/optimize/url \
  -H "Authorization: Bearer <your-key>" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/icon.svg"}'

Response

# Optimized SVG file returned directly
POST/v1/optimize/batch

Optimize multiple SVGs

Auth: Required (Free or Pro)

Upload up to 10 (Free) or 50 (Pro) SVG files in a single request. Returns a JSON array of results.

ParameterTypeRequiredDescription
filesmultipart/form-data (multiple)YesOne or more SVG files. Free: max 10, Pro: max 50.

Request

bash
curl -X POST https://api.svg.dog/v1/optimize/batch \
  -H "Authorization: Bearer <your-key>" \
  -F "files=@icon1.svg" \
  -F "files=@icon2.svg"

Response

[
  {
    "filename": "icon1.svg",
    "success": true,
    "original_size": 4821,
    "optimized_size": 1204,
    "savings_percent": 75.04,
    "optimized": "<svg>...</svg>"
  },
  {
    "filename": "icon2.svg",
    "success": false,
    "error": "Invalid SVG"
  }
]
GET/v1/usage

Get usage statistics

Auth: Required

Returns your current monthly usage, including total optimizations, billable count, and volume saved.

Request

bash
curl https://api.svg.dog/v1/usage \
  -H "Authorization: Bearer <your-key>"

Response

{
  "plan": "pro",
  "month": "2026-04",
  "optimizations": {
    "total": 1240,
    "billable": 740,
    "limit": null,
    "remaining": null
  },
  "volume": {
    "total_input_bytes": 15204800,
    "total_output_bytes": 3801200,
    "total_saved_bytes": 11403600
  }
}
GET/v1/health

Health check

Auth: None

Returns the current API status. Useful for monitoring integrations.

Request

bash
curl https://api.svg.dog/v1/health

Response

{
  "status": "ok"
}

Error codes

StatusMeaning
200Success
400Bad request — missing or invalid parameter
401Unauthorized — invalid or missing API key
413File too large for your plan
422Unprocessable — file is not a valid SVG
429Rate limit or budget cap reached
500Server error