> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Media

> Convert images on demand and save conversion settings as reusable presets.

The Media API converts images on demand. You upload an original, ask for a conversion, and download the result. Save the settings you use often as conversion presets.

```text theme={null}
https://api.occtoo.com
```

## Conversion flow

**1. Request a conversion**

Call `POST /v1/image-conversions` with the original's `filename`. The response returns an `id` and a signed `uploadUrl`.

**2. Upload the original**

Send the file with `PUT` to `uploadUrl` and the header `x-ms-blob-type: BlockBlob`. The file goes straight to Azure Blob Storage.

**3. Queue the conversion**

Call `POST /v1/image-conversions/{id}/convert` with `parameters`, or with the `id` of a preset as `preset`. The response returns a job, and the `Location` header holds its URL.

**4. Read the result**

Call `GET /v1/image-conversions/jobs/{jobId}` every 1–2 seconds. When `status` is `Completed`, download the image from `result.url`. When it is `Failed`, `error` says why.

Upload links and download links are valid for 1 hour. Occtoo deletes originals and converted images after one day.

## Conversion parameters

| Field | What it does |
| - | - |
| `mode` | `Fit` keeps the proportions inside the canvas. `FillBackground` fits the image inside the padding and fills the rest with `background`. `Crop` fills the canvas and crops from the center. `Auto` crops when the image and canvas have the same orientation, and fits otherwise. |
| `targetSize` | The longer side of the canvas in pixels, from 1 to 8000. |
| `aspectRatio` | The canvas as `width:height`, for example `1:1` or `4:3`. Each side is a whole number from 1 to 100. |
| `paddingPercent` | Padding on each side as a percentage of `targetSize`, from 0 to 49. Required with `FillBackground` and not allowed with other modes. |
| `background` | Optional color as six hex digits without `#`, for example `FFFFFF`. |
| `outputFormat` | `Jpg`, `Png`, or `Webp`. |
| `quality` | From 1 to 100. |

## Conversion presets

A preset saves `parameters` under an `id`, so you can convert with `preset` instead of sending the parameters each time. Manage presets under `/v1/conversion-presets`.

* `id` starts with a lowercase letter and can contain lowercase letters, digits, `_`, and `-`, up to 64 characters. You cannot change it.
* `version` starts at 1 and goes up by one when `parameters` change.
* You cannot delete a preset that a card definition uses. The request returns `409`.

## Authentication

The tenant comes from the credential. Send an [Application access token](https://docs.occtoo.com/api-reference/authentication/application-token.md) as `Authorization: Bearer <token>`, or an organization API key as `x-api-key`.

| Operation | Scope |
| - | - |
| List and get presets | `read:media` |
| Create, replace, and delete presets | `write:media` |
| All image conversion operations | `write:media` |

## Errors

A failed conversion is not an error response. Reading its job returns `200` with `status` set to `Failed`.

Errors use [Problem Details](https://www.rfc-editor.org/rfc/rfc9457) (`application/problem+json`).

| Status | Meaning |
| - | - |
| `400` | The request failed validation, for example invalid `parameters`, or both or neither of `preset` and `parameters`. |
| `401` | The credential is missing or invalid. |
| `403` | The credential lacks the required scope. |
| `404` | The conversion, job, or preset does not exist, or the files were already deleted. |
| `409` | A preset with that `id` exists, or a card definition still uses the preset. |

Retry `500` with exponential backoff. A convert call that returned `500` may still have queued the conversion.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.