# Image conversions

Vectorize an image to SVG, or export PNG, PDF, TIFF and PPTX, including flowcharts.

Source: https://scifig.ai/docs/api/image-conversions

## JSON body

`POST /images/conversions`. Required scope: `images:convert`.

| Field | Type | Required | Default | Rules |
| --- | --- | --- | --- | --- |
| image | string | yes | — | A PNG or JPEG `file_id` or a flowchart’s SVG output, up to 20 MB; `svg` also takes WebP |
| format | string | yes | — | `svg`, `png`, `pdf`, `tiff` or `pptx` |
| vector_mode | string | no | `editable_text` | Only for `svg`: `editable_text` or `full_vector` |
| dpi | integer | no | 300 | Not for `svg`: 300, 600 or 1000 |
| width | integer | no | 2048 | Only for flowchart SVG sources: long edge in pixels, 256–4096, at most 4,194,304 pixels in total |

## SVG vectorization

- Costs 150 credits and needs a paid plan; the same vectorizer as Edit in Canvas on the website. The source is a PNG, JPEG or WebP image.
- `editable_text` keeps text as editable SVG text; `full_vector` traces everything, including text, as paths.
- It runs as a job. Credits are reserved only once the vectorization task has been accepted, and the job’s `credits` are read back from the ledger. A failed vectorization is refunded and returns `TASK_FAILED` for that key.
- Converting an image that was already vectorized returns the earlier SVG and costs this job nothing.
- If the vectorizer is temporarily unavailable before the task starts, the answer is `503 SERVICE_UNAVAILABLE` with `Retry-After`: retry with the same key.

## PNG, PDF, TIFF and PPTX

- Free, up to 200 conversions per account per day. PNG/JPEG sources finish synchronously. Flowchart SVG sources return an asynchronous 202 job; with `jobs:read`, poll the existing job without creating another. The 10-minute total deadline includes queueing and cold starts; each render has a 120-second limit.
- A conversion counts against the daily allowance only after its input has passed every check, and once per Idempotency-Key: retrying the same key does not count again. Beyond the allowance the answer is `429 RATE_LIMITED` with `details.reason = DAILY_CONVERSION_LIMIT` and `Retry-After` until the day window resets.
- The source is a PNG or JPEG image or a flowchart’s SVG output; WebP is not accepted (`UNSUPPORTED_SOURCE_FORMAT`).
- A file whose encoded output would exceed 24 MiB is refused with `400 INVALID_REQUEST` (`OUTPUT_TOO_LARGE`); convert a smaller image.
- `dpi` is written into the file and sets the physical page size of PDF and PPTX; pixels are not resampled. For more pixels, [upscale](/docs/api/image-upscales) first.
- PNG and TIFF need a PNG source; PDF and PPTX also accept JPEG. TIFF uses lossless Deflate compression.
- The PPTX is one slide with the image; it is not editable shapes.

## Flowchart exports

Flowchart SVG outputs use a private renderer with Arial and Noto fonts, then export PNG, PDF, TIFF or PPTX. The long edge defaults to 2048px, is at most 4096px, and must fit the 4,194,304-pixel budget (square: 2048px). Larger requests return `RENDER_TOO_LARGE` before counting the daily allowance. Unsupported SVG or missing glyphs are rejected rather than drawn incorrectly. Other SVG inputs are not accepted. Execution errors are visible on the existing asynchronous job; never recreate it merely because waiting stopped.

## cURL

```bash
curl -X POST https://scifig.ai/api/v1/images/conversions \
  -H "Authorization: Bearer $SCIFIG_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Prefer: wait=25" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "<file_id>",
    "format": "pdf",
    "dpi": 600
  }'
```

## JavaScript

```javascript
const response = await fetch('https://scifig.ai/api/v1/images/conversions', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
    'Idempotency-Key': crypto.randomUUID(),
    Prefer: 'wait=25',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "image": "<file_id>",
    "format": "pdf",
    "dpi": 600
  }),
});
const result = await response.json();
console.log(response.status, result);
```

## Python

```python
import os
import uuid

import requests

headers = {
    "Authorization": f"Bearer {os.environ['SCIFIG_API_KEY']}",
    "Idempotency-Key": str(uuid.uuid4()),
    "Prefer": "wait=25",
}
response = requests.post(
    "https://scifig.ai/api/v1/images/conversions",
    headers=headers,
    json={
        "image": "<file_id>",
        "format": "pdf",
        "dpi": 600
    },
    timeout=60,
)
print(response.status_code, response.json())
```
