> ## 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.

# Request an image conversion and get a link to upload the original to

> Starts a conversion and returns a signed link to upload the original to. Nothing is stored yet.

`PUT` the original's bytes to `uploadUrl` with the header `x-ms-blob-type: BlockBlob` before `uploadExpiresAt`. The bytes go straight to Azure Blob Storage and never pass through Occtoo. The original must be smaller than `maxFileSize` bytes.

`filename` is required, at most 200 characters, can't contain `/`, `\`, `..` or control characters, and can't start or end with a space or `.`. The converted image keeps its name with the output format's extension.



## OpenAPI

````yaml /api-reference/openapi/media.json post /v1/image-conversions
openapi: 3.2.0
info:
  title: Media API
  description: >-
    Convert images on demand and manage the tenant's conversion presets. The
    tenant comes from the credential, never from the route or request body.


    ## The conversion flow


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

    2. `PUT` the original to `uploadUrl` with the header `x-ms-blob-type:
    BlockBlob`. The bytes go straight to Azure Blob Storage and never pass
    through Occtoo.

    3. `POST /v1/image-conversions/<id>/convert` with the conversion
    `parameters`, or with a `preset` (see [Conversion
    presets](#conversion-presets)), queues the conversion and returns a job. The
    `Location` header holds its URL.

    4. `GET /v1/image-conversions/jobs/<jobId>` every 1–2 seconds until `status`
    is `Completed`, with a signed `result.url` to download the converted image,
    or `Failed`, with an `error` that says why. A queued job waits behind other
    conversions, so how long that takes depends on how much is queued.


    The upload link is valid for 1 hour. Each read of a completed job signs a
    download link valid for 1 hour from that read. Originals and converted
    images are deleted after a day. Converting after that answers `404`, and so
    does reading the completed job.


    ## Parameters


    | Field | Rule |

    |---|---|

    | `mode` | `Fit` scales the image to fit inside the canvas, keeping its
    proportions, so one side can come out shorter. `FillBackground` fits it
    inside the canvas minus the padding and fills the rest with `background`.
    `Crop` fills the canvas and crops from the centre. `Auto` crops when the
    image and canvas share an orientation and fits otherwise. |

    | `targetSize` | The canvas's longer side in pixels, from 1 to 8000. |

    | `aspectRatio` | The canvas as `width:height`, each side a whole number
    from 1 to 100, for example `1:1` or `4:3`. |

    | `paddingPercent` | Padding on each side as a percentage of `targetSize`,
    from 0 to 49. Required with `FillBackground` and not allowed with any other
    mode. The canvas minus the padding on both sides must be at least 1 px. |

    | `background` | Optional. The colour behind transparent areas and padding,
    as six hex digits without `#`, for example `FFFFFF`. |

    | `outputFormat` | `Jpg`, `Png` or `Webp`. |

    | `quality` | From 1 to 100. |


    `mode` and `outputFormat` are case-insensitive strings; numbers aren't
    accepted.


    ## Conversion presets


    A preset stores `parameters` under an `id` so you can reuse them by name.
    `/v1/conversion-presets` lists, gets, creates, replaces and deletes presets.
    To convert with a preset, send its `id` as `preset` to the convert endpoint
    in place of `parameters`. The conversion uses the preset's current
    `parameters`.


    - `id`: a lower-case letter, then lower-case letters, digits, `_` or `-`, at
    most 64 characters. It can't be changed.

    - `displayName`: 2–50 printable ASCII characters, with no leading or
    trailing space.

    - `parameters`: the same fields and rules as above. An unset
    `paddingPercent` or `background` is returned as `null`.

    - `version`: 1 when created. Goes up by one when `parameters` change or a
    deleted preset is created again. Changing only `displayName` keeps it.


    The list is ordered by `id` and comes back one page at a time as `items`,
    `after` and `totalCount`. `limit` sets the page size, from 1 to 200, default
    50. Pass a page's `after` as the `after` parameter to get the next page.
    It's `null` on the last page. `totalCount` is `null` unless you set
    `includeTotalCount=true`.


    ## Authentication and access


    Select **Authorize** to reuse the existing Occtoo browser session, provide a
    tenant-scoped bearer token, or send an organization API key through
    `x-api-key`. Listing and getting presets need the `read:media` permission.
    Creating, replacing and deleting presets, and the conversion endpoints, need
    `write:media`.


    ## Responses


    Successful responses return the resource directly. Requesting a conversion
    and creating a preset answer `201`, converting answers `202`, deleting a
    preset answers `204`, and everything else answers `200`. A conversion that
    fails isn't an error response: reading its job answers `200` with `status`
    `Failed` and an `error`.


    | Status | When |

    |---|---|

    | `400` | An invalid `filename`; neither or both of `preset` and
    `parameters`, or invalid `parameters`; an original of `maxFileSize` bytes or
    more; an invalid preset `id`, `displayName` or `parameters`; a list `limit`
    out of range, an `after` the list didn't return, or a `before` or `offset`
    parameter. |

    | `401` | No credential, or an invalid one. |

    | `403` | A credential without the operation's permission. |

    | `404` | An unknown `id`, another tenant's `id`, nothing uploaded yet, or
    an original that was already deleted; an unknown or deleted preset; an
    unknown job, or a completed job whose result is no longer kept. |

    | `409` | Creating a preset whose `id` is in use; deleting a preset whose
    conversion property a card definition binds on a source. |

    | `500` | Anything else. |


    Errors use ProblemDetails (RFC 9457) with the `application/problem+json`
    content type. A validation `400` lists each invalid field under `errors`,
    for example `Parameters.TargetSize`, or `Preset` when a convert sends
    neither or both of `preset` and `parameters`. A body that isn't valid JSON,
    misses a required field, or has a value of the wrong type, an unknown enum
    name, or an `aspectRatio` or `background` in the wrong format, answers `400`
    without `errors`. Retry `500` with bounded exponential backoff. A convert
    that answered `500` may have queued the conversion anyway, so a retry can
    queue a second one.


    Machine-readable contract:
    [OpenAPI](https://api.occtoo.com/openapi/media.json)
  version: 1.0.0
  summary: >-
    Convert images on demand and manage conversion presets (named, reusable
    conversion parameters).
servers:
  - url: https://api.occtoo.com
    description: Occtoo public API
security: []
tags:
  - name: Conversion presets
  - name: Image conversions
paths:
  /v1/image-conversions:
    post:
      tags:
        - Image conversions
      summary: Request an image conversion and get a link to upload the original to
      description: >-
        Starts a conversion and returns a signed link to upload the original to.
        Nothing is stored yet.


        `PUT` the original's bytes to `uploadUrl` with the header
        `x-ms-blob-type: BlockBlob` before `uploadExpiresAt`. The bytes go
        straight to Azure Blob Storage and never pass through Occtoo. The
        original must be smaller than `maxFileSize` bytes.


        `filename` is required, at most 200 characters, can't contain `/`, `\`,
        `..` or control characters, and can't start or end with a space or `.`.
        The converted image keeps its name with the output format's extension.
      operationId: requestImageConversion
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestImageConversionRequest'
            examples:
              example:
                summary: Request a conversion of a TIFF
                value:
                  filename: shoe.tif
        required: true
      responses:
        '201':
          description: The conversion id and a link to upload the original to.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageConversion'
              examples:
                example:
                  summary: A link to upload the original to
                  value:
                    id: 3f9d2c1e-8b4a-4e6f-9a7d-1c2b3d4e5f60
                    uploadUrl: >-
                      https://occtoomedia.blob.core.windows.net/conversion-scratch/6b1f0b3c-6f2e-4a52-9a1e-7c6f0c2f9a10/3f9d2c1e-8b4a-4e6f-9a7d-1c2b3d4e5f60/original/shoe.tif?sv=2024-11-04&se=...&sig=...
                    uploadExpiresAt: '2026-11-05T13:30:00+00:00'
                    maxFileSize: 33554432
        '400':
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/HttpValidationProblemDetails'
        '401':
          description: Unauthorized
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '403':
          description: Forbidden
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '500':
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
      security:
        - kindeOAuth: []
        - bearerAuth: []
        - apiKey: []
components:
  schemas:
    RequestImageConversionRequest:
      required:
        - filename
      type: object
      properties:
        filename:
          type: string
          description: >-
            The original's name, with its extension. Required, at most 200
            characters; can't contain `/`, `\`, `..` or control characters, and
            can't start or end with a space or `.`.
    ImageConversion:
      required:
        - id
        - uploadUrl
        - uploadExpiresAt
        - maxFileSize
      type: object
      properties:
        id:
          type: string
          description: The conversion's id, passed to `convertImage`.
          format: uuid
        uploadUrl:
          type: string
          description: >-
            The link to upload the original to with a PUT carrying the header
            `x-ms-blob-type: BlockBlob`.
        uploadExpiresAt:
          type: string
          description: When the upload link expires.
          format: date-time
        maxFileSize:
          pattern: ^-?(?:0|[1-9]\d*)$
          type:
            - integer
            - string
          description: The original must be smaller than this many bytes.
          format: int64
      description: An on-demand image conversion that is waiting for its original.
    HttpValidationProblemDetails:
      type: object
      properties:
        type:
          type:
            - 'null'
            - string
        title:
          type:
            - 'null'
            - string
        status:
          pattern: ^-?(?:0|[1-9]\d*)$
          type:
            - 'null'
            - integer
            - string
          format: int32
        detail:
          type:
            - 'null'
            - string
        instance:
          type:
            - 'null'
            - string
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
    ProblemDetails:
      type: object
      properties:
        type:
          type:
            - 'null'
            - string
        title:
          type:
            - 'null'
            - string
        status:
          pattern: ^-?(?:0|[1-9]\d*)$
          type:
            - 'null'
            - integer
            - string
          format: int32
        detail:
          type:
            - 'null'
            - string
        instance:
          type:
            - 'null'
            - string
  securitySchemes:
    kindeOAuth:
      type: oauth2
      description: >-
        Sign in with the existing Occtoo Studio identity and selected
        organization.
      flows:
        authorizationCode:
          authorizationUrl: >-
            https://auth.occtoo.com/oauth2/auth?audience=https%3A%2F%2Fapi-weu.occtoo.com
          tokenUrl: https://auth.occtoo.com/oauth2/token
          scopes:
            openid: Authenticate the user with OpenID Connect.
            profile: Read the user's basic profile.
            email: Read the user's email address.
            offline: Refresh the access token without another interactive sign-in.
          x-usePkce: SHA-256
          x-scalar-redirect-uri: https://api.occtoo.com/docs/
    bearerAuth:
      type: http
      description: >-
        Tenant-scoped Occtoo access token, including Kinde machine-to-machine
        application tokens.
      scheme: bearer
      bearerFormat: JWT
    apiKey:
      type: apiKey
      description: Occtoo organization API key.
      name: x-api-key
      in: header

````

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