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

# TinyPNG API reference

> API reference for the TinyPNG plugin in Corsair: every `tinypng.api.*` operation with its input and output types, taken from the plugin's Zod schemas.

> [!NOTE]
>
> **New to Corsair?** See [API access](https://docs.corsair.dev/concepts/api.md), [authentication](https://docs.corsair.dev/concepts/auth.md), and [error handling](https://docs.corsair.dev/concepts/error-handling).

## Account

### getCompressionCount

`account.getCompressionCount`

Get the number of compressions made this calendar month

**Risk:** `read`

```ts theme={null}
await corsair.tinypng.api.account.getCompressionCount({});
```

**Input:** *empty object*

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `compressionCount` | `number` | Yes | — |

***

## Images

### compressAndStoreInAzure

`images.compressAndStoreInAzure`

Compress an image and upload the result to Azure Blob Storage through a SAS URL

**Risk:** `write`

```ts theme={null}
await corsair.tinypng.api.images.compressAndStoreInAzure({
	source: { url: 'https://tinypng.com/images/panda-happy.png' },
	blobUrl: 'https://myaccount.blob.core.windows.net/images/panda.png?sv=2022-11-02&sig=REDACTED',
});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `source` | `object` | Yes | — |
| `blobUrl` | `string` | Yes | Full blob URL with a SAS token granting create/write, e.g. [https://acct.blob.core.windows.net/container/name.png?sv=](https://acct.blob.core.windows.net/container/name.png?sv=)... |
| `cacheControl` | `string` | No | — |
| `resize` | `object` | No | — |
| `convert` | `object` | No | Several types return the smallest result |
| `transform` | `object` | No | — |
| `preserve` | `(copyright \| creation \| location)[]` | No | — |

> [accordion] source full type
>
> ```ts theme={null}
> {
>   url: string
> } | {
>   base64: string
> }
> ```

> [accordion] resize full type
>
> ```ts theme={null}
> {
>   method: scale | fit | cover | thumb,
>   width?: number,
>   height?: number
> }
> ```

> [accordion] convert full type
>
> ```ts theme={null}
> {
>   type: image/avif | image/webp | image/jpeg | image/png | image/jxl | */* | (image/avif | image/webp | image/jpeg | image/png | image/jxl | */*)[]
> }
> ```

> [accordion] transform full type
>
> ```ts theme={null}
> {
>   background: string
> }
> ```

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `imageId` | `string` | Yes | — |
| `blobUrl` | `string` | Yes | Blob URL without the SAS query string |
| `contentType` | `string` | Yes | — |
| `size` | `number` | Yes | — |
| `width` | `number` | No | — |
| `height` | `number` | No | — |
| `compressionCount` | `number` | No | — |
| `etag` | `string` | No | — |

***

### output

`images.output`

Download a compressed image by its Tinify image ID. On Corsair up to about 700 KB comes back inline as base64 and a larger image comes back as fileId, a Files id; without a host that keeps files the image comes back inline as base64 up to 100 MB, or contentOmitted beyond it.

**Risk:** `read`

```ts theme={null}
await corsair.tinypng.api.images.output({ imageId: '2xnsp7jn34e5' });
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `imageId` | `string` | Yes | — |

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `contentType` | `string` | Yes | — |
| `byteLength` | `number` | Yes | Size of the file in bytes. |
| `filename` | `string` | No | The file name, when known. |
| `contentOmitted` | `not_requested \| over_limit` | No | Set when the content was left out: the caller did not ask for it, or the file was over the limit. |
| `fileId` | `string` | No | Where the host saved the file. Over the limit it comes in place of the content; a host that keeps every file sets it beside the content too. On Corsair it is a Files id (fil\_…): pass it to another app wherever that app takes a file URL, or read a text file or PDF with files.read\_text. |
| `imageId` | `string` | Yes | — |
| `size` | `number` | Yes | — |
| `width` | `number` | No | — |
| `height` | `number` | No | — |
| `compressionCount` | `number` | No | — |
| `base64` | `string` | No | The image, base64-encoded. Missing when contentOmitted is set, or when a host kept a file too large to return inline (fileId). |

***

### shrink

`images.shrink`

Compress an image from a URL or base64 bytes and return its Tinify image ID (uses one compression)

**Risk:** `write`

```ts theme={null}
await corsair.tinypng.api.images.shrink({
	source: { url: 'https://tinypng.com/images/panda-happy.png' },
});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `source` | `object` | Yes | — |

> [accordion] source full type
>
> ```ts theme={null}
> {
>   url: string
> } | {
>   base64: string
> }
> ```

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `imageId` | `string` | Yes | — |
| `outputUrl` | `string` | Yes | — |
| `compressionCount` | `number` | No | — |
| `input` | `object` | Yes | — |
| `output` | `object` | No | — |

> [accordion] input full type
>
> ```ts theme={null}
> {
>   size: number,
>   type: string
> }
> ```

> [accordion] output full type
>
> ```ts theme={null}
> {
>   size: number,
>   type: string,
>   width?: number,
>   height?: number,
>   ratio?: number
> }
> ```

***

### transform

`images.transform`

Resize, convert, fill the background of, or preserve metadata on a compressed image, optionally storing it on S3 or GCS. A returned image comes back like images.output: inline up to about 700 KB on Corsair, as fileId beyond it.

**Risk:** `write`

```ts theme={null}
await corsair.tinypng.api.images.transform({
	imageId: '2xnsp7jn34e5',
	resize: { method: 'fit', width: 150, height: 100 },
	convert: { type: 'image/webp' },
});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `imageId` | `string` | Yes | — |
| `resize` | `object` | No | — |
| `convert` | `object` | No | Several types return the smallest result |
| `transform` | `object` | No | — |
| `preserve` | `(copyright \| creation \| location)[]` | No | — |
| `store` | `object` | No | Upload the result to S3 or GCS instead of returning the bytes |

> [accordion] resize full type
>
> ```ts theme={null}
> {
>   method: scale | fit | cover | thumb,
>   width?: number,
>   height?: number
> }
> ```

> [accordion] convert full type
>
> ```ts theme={null}
> {
>   type: image/avif | image/webp | image/jpeg | image/png | image/jxl | */* | (image/avif | image/webp | image/jpeg | image/png | image/jxl | */*)[]
> }
> ```

> [accordion] transform full type
>
> ```ts theme={null}
> {
>   background: string
> }
> ```

> [accordion] store full type
>
> ```ts theme={null}
> {
>   service: s3,
>   aws_access_key_id: string,
>   aws_secret_access_key: string,
>   region: string,
>   path: string,
>   headers?: {
>     Cache-Control: string
>   },
>   acl?: string
> } | {
>   service: gcs,
>   gcp_access_token: string,
>   path: string,
>   headers?: {
>     Cache-Control: string
>   }
> }
> ```

**Output:** `object`

> [accordion] Output full type
>
> ```ts theme={null}
> {
>   contentType: string,
>   byteLength: number,
>   filename?: string,
>   contentOmitted?: not_requested | over_limit,
>   fileId?: string,
>   imageId: string,
>   size: number,
>   width?: number,
>   height?: number,
>   compressionCount?: number,
>   base64?: string,
>   stored: false
> } | {
>   stored: true,
>   imageId: string,
>   location: string,
>   width?: number,
>   height?: number,
>   compressionCount?: number
> }
> ```

***


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