# Upscale image

> Beta. Queues an enlargement of an image and returns the task. `effort` picks the upscaler and sets a flat price; `size` never changes it. The result can be at most 4096x4096 pixels, so a larger request fails with `output_too_large` and is not charged.

`POST /image/upscale`

**Auth:** API key or OAuth token

## Request body

- `url` (required, string) — format: uri.
- `size` (required, object | string) — How much to enlarge each side. The upscaled image can be at most 4096x4096 pixels. One of: `"2x"`, `"4x"`.
  - `type` (required, "scale")
  - `factor` (required, number) — One of: `2`, `4`.
- `effort` (required, string) — Upscaler to run, and the price. 'low' is fast and sharp; 'high' rebuilds fine detail such as small text and faces. One of: `"low"`, `"high"`.
- `output` (object)
  - `format` (string) — One of: `"png"`, `"jpg"`, `"webp"`.
- `generate_public_access_token` (boolean) — Return a short-lived public access token as `public_access_token`, for polling this task from browser code without your API key. Defaults to false.
- `webhook` (object)
  - `registered` (boolean) — Set to false to skip the webhooks registered on the account for this task. Custom webhooks in `custom` are still sent.
  - `custom` (object[]) — ≥ 1 items, ≤ 5 items.
    - `url` (required, string) — Receives this task's events, unsigned. Use https and a public host, and put a secret token in the query string to verify deliveries: only `scheme://host` is ever shown back. Example `"https://example.com/hooks/mynth?token=your-secret-token"`.
- `destination` (string) — ≥ 1 characters, ≤ 64 characters. Example `"bunny-prod"`.
- `metadata` (object)

## Response

### 201 — Image upscale task created

- `data` (required, object)
  - `task_id` (required, string) — Task ID Example `"tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP"`.
  - `estimated_cost` (required, string) — Estimated cost in USD reserved for this task. Work that fails is refunded, so the final cost may be lower. Example `"0.03"`.
  - `public_access_token` (string) — Short-lived public access token for polling this task's status and result. Safe to hand to browser code instead of your API key. Returned only when the request set `generate_public_access_token: true`. Example `"pat_eyJhbGciOi..."`.

```json
{
  "data": {
    "task_id": "tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP",
    "estimated_cost": "0.03",
    "public_access_token": "pat_eyJhbGciOi..."
  }
}
```

### 400 — The request was rejected before anything was queued. `error.message` says what to change. A field that failed the schema, or one the endpoint does not take, is also listed in `error.issues`.

- `error` (required, object)
  - `code` (required, string) — `validation_error` for a body that failed validation, `invalid_json` for one that is not JSON. One of: `"validation_error"`, `"invalid_json"`.
  - `message` (required, string) — Every problem, in one sentence each, led by the field it is about.
  - `issues` (object[]) — One entry per field that failed the schema, and one per field the endpoint does not take.
    - `path` (required, (string | integer)[]) — Where the problem is, e.g. `["inputs", 0, "source"]`. Empty for the body as a whole.
    - `message` (required, string)

```json
{
  "error": {
    "code": "validation_error",
    "message": "count: Too big: expected number to be <=20. colour: Unknown field.",
    "issues": [
      {
        "path": [
          "count"
        ],
        "message": "Too big: expected number to be <=20"
      },
      {
        "path": [
          "colour"
        ],
        "message": "Unknown field."
      }
    ]
  }
}
```

## Request samples

### cURL

```bash
curl -X POST https://api.mynth.io/image/upscale \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "string",
    "size": "2x",
    "effort": "low",
    "destination": "bunny-prod"
  }'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/image/upscale", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "url": "string",
    "size": "2x",
    "effort": "low",
    "destination": "bunny-prod"
  }),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
