---
search:
  tags:
    - Convert
    - POST
seo:
  description: >-
    Converts a file in one request: reserve, upload, queue, wait and return the
    result, on the same… Reference for the POST /v1/convert endpoint in the
    convt API.
sidebar:
  label: Convert a file in one request
  badge: POST
title: Convert a file in one request
type: openapi-operation
---
Converts a file in one request: reserve, upload, queue, wait and return the result, on the same pipeline, spend cap and billing as the jobs routes.

Send the file as a multipart `file` field (with `to`, and optionally `from` and `options`), as the raw body with `to` in the query, or send JSON with `source_url`. `to` and `from` take format ids or extensions; `from` is inferred from the file name, URL or `Content-Type` when left out.

When the job succeeds with one output of at most 25 MB, this is its first delivery, and `Accept` does not ask for JSON, the response is the file, named after yours in `Content-Disposition`, with the `Convt-Job-Id` header. A larger result, or a replay, answers `303` with the signed storage URL in `Location`: clients that follow it receive the stored file, whose headers come from storage, so read the job id from the `303` or its JSON body. With several outputs (a multi-page PDF to PNG) or `Accept: application/json`, it is JSON with signed URLs. When the job is still running after `wait` seconds, a request with `Accept: application/json` gets `202` and the job keeps running; a file request gets `409 still_running` if it sent an `Idempotency-Key` (the job keeps running) or `504 timeout` if not (the job is cancelled).

Without an `Idempotency-Key`, hanging up before the answer cancels the job; that is best effort, and a job that already succeeded is billed. With one, the job keeps running and a retry with the same key collects it.

`POST /v1/convert`

**Request body** (`application/json`, required)

- `source_url` (string<uri>, required)
- `to` (string)
- `from` (string)
- `options` (Options) — Conversion settings. Every field is optional, and an unknown field, a value of the wrong type or an out-of-range value fails with \`400 invalid\_options\` when you create the job.

Request body example:

```json
{
  "source_url": "http://example.com",
  "to": "string",
  "from": "string",
  "options": {
    "quality": 1,
    "max_size": 1,
    "video_height": 2,
    "audio_bitrate": 8,
    "pages": "string",
    "dpi": 18,
    "video_codec": "h264",
    "background": "string",
    "strip_audio": false,
    "target_size": 10000,
    "strip_metadata": false,
    "trim_start": 0,
    "trim_end": 0,
    "fps": 1
  }
}
```

**Responses**

- `200` — The converted file, when the job produced one output of at most 25 MB, this is its first delivery, and \`Accept\` does not ask for JSON. With several outputs or \`Accept: application/json\`, JSON with signed URLs.
- `202` — Sent only with \`Accept: application/json\`: the job is still running after \`wait\` seconds. It keeps running and is billed if it succeeds; poll \`Location\`.
- `303` — A result over 25 MB, or a replay of a finished request: \`Location\` is the signed storage URL of the only output (valid for \`expires\_in\` seconds). Follow it; the body is the same JSON as with \`Accept: application/json\`.
- `400` — \`invalid\_request\`, \`input\_format\_required\`, \`unsupported\_format\`, \`invalid\_options\`, \`invalid\_source\_url\`, \`invalid\_idempotency\_key\` or an empty file (\`file\_too\_large\`).
- `401` — \`unauthorized\`: no \`Authorization: Bearer\` header.
- `403` — \`unauthorized\` (key invalid or revoked) or a billing limit.
- `404` — \`not\_found\`: the job does not exist, belongs to another account, or has expired.
- `408` — \`request\_timeout\`: the upload took longer than 2 minutes. Use \`POST /v1/jobs\` for slow or large uploads.
- `409` — \`cancelled\` (the job was cancelled first), \`still\_running\` (a file request with an \`Idempotency-Key\` that isn't done after \`wait\`; retry with the key) or \`idempotency\_key\_reused\`.
- `413` — \`file\_too\_large\`: over 25 MB. Use \`POST /v1/jobs\` or \`source\_url\`.
- `422` — The conversion failed. \`code\` is the job's \`error\_code\`, such as \`conversion\_failed\` or \`source\_fetch\_failed\`. Not charged.
- `429` — \`rate\_limited\`: more than 120 requests in a minute for this key.
- `500` — \`internal\`. If the job already exists, the body has \`job\_id\` and \`Convt-Job-Id\` and \`Location\` name it: check it before retrying, because it may still finish and be billed.
- `502` — \`storage\_unavailable\`: storage did not answer. If the body names a job, read it with \`GET /v1/jobs/{id}\` first: a succeeded job was billed, so fetch its outputs from \`/download\` instead of converting again; a job still \`created\`, \`queued\` or \`running\` can be collected by retrying the original request with its original \`Idempotency-Key\`. \`output\_missing\`: the job succeeded and was billed but an output is gone from storage; fresh links will not help, so contact us with the job id.
- `503` — \`server\_busy\`: too many uploads in progress. Retry after \`Retry-After\` seconds.
- `504` — \`timeout\`: a file request without an \`Idempotency-Key\` did not finish within \`wait\`. The job was cancelled; not charged.

Response example, 200:

```json
{
  "job": {
    "id": "string",
    "status": "created",
    "input_format": "string",
    "target_format": "string",
    "options": {
      "quality": 1,
      "max_size": 1,
      "video_height": 2,
      "audio_bitrate": 8,
      "pages": "string",
      "dpi": 18,
      "video_codec": "h264",
      "background": "string",
      "strip_audio": false,
      "target_size": 10000,
      "strip_metadata": false,
      "trim_start": 0,
      "trim_end": 0,
      "fps": 1
    },
    "input_bytes": 0,
    "attempt": 0,
    "error_code": "string",
    "expires_at": "2019-08-24T14:15:22Z",
    "created_at": "2019-08-24T14:15:22Z",
    "source_url": "string",
    "webhook_url": "string"
  },
  "outputs": [
    {
      "name": "string",
      "url": "http://example.com"
    }
  ],
  "expires_in": 0
}
```
