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

# Optimize Asset

> Create an optimized version of an asset with format conversion and resizing

Create an optimized version of an image asset with specified transformations. This permanently creates a new optimized version of the asset.

<Note>
  For on-demand transformations without creating new assets, use [CDN URL parameters](/rest/assets/cdn) instead.
</Note>

## Path Parameters

<ParamField path="organizationId" type="string" required>
  The unique identifier of the organization
</ParamField>

<ParamField path="projectId" type="string" required>
  The unique identifier of the project
</ParamField>

<ParamField path="id" type="string" required>
  The unique identifier of the asset
</ParamField>

## Request Body

<ParamField body="options" type="object" required>
  Optimization options

  <Expandable title="options properties">
    <ParamField body="quality" type="number">
      Output quality (1-100). Lower values = smaller file size.
    </ParamField>

    <ParamField body="format" type="string">
      Output format: `jpeg`, `png`, `webp`, `avif`
    </ParamField>

    <ParamField body="width" type="number">
      Target width in pixels (1-4096)
    </ParamField>

    <ParamField body="height" type="number">
      Target height in pixels (1-4096)
    </ParamField>
  </Expandable>
</ParamField>

## Response

Returns the optimized Asset object with updated metadata.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/assets/asset789/optimize" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "options": {
        "quality": 80,
        "format": "webp",
        "width": 1200,
        "height": 800
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/assets/asset789/optimize',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        options: {
          quality: 80,
          format: 'webp',
          width: 1200,
          height: 800
        }
      })
    }
  );
  const data = await response.json();
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "data": {
      "id": "asset789",
      "name": "hero-image.webp",
      "type": "image/webp",
      "status": "active",
      "url": "https://cdn.metabind.ai/org123/proj456/assets/asset789/hero-image.webp",
      "size": 245760,
      "metadata": {
        "width": 1200,
        "height": 800,
        "format": "webp",
        "originalSize": 2048576,
        "compressionRatio": 0.12
      },
      "tags": ["hero", "optimized"],
      "createdAt": "2024-03-20T10:00:00Z",
      "updatedAt": "2024-03-21T17:00:00Z"
    }
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": "BAD_REQUEST",
      "message": "Optimization is only supported for images"
    }
  }
  ```
</ResponseExample>

## Optimization Tips

<AccordionGroup>
  <Accordion title="Web Images">
    For general web use, convert to WebP with quality 80:

    ```json theme={null}
    {
      "options": {
        "format": "webp",
        "quality": 80
      }
    }
    ```
  </Accordion>

  <Accordion title="Thumbnails">
    For thumbnails, resize and compress aggressively:

    ```json theme={null}
    {
      "options": {
        "format": "webp",
        "quality": 70,
        "width": 300,
        "height": 300
      }
    }
    ```
  </Accordion>

  <Accordion title="Maximum Compression">
    For smallest file size, use AVIF (where supported):

    ```json theme={null}
    {
      "options": {
        "format": "avif",
        "quality": 60
      }
    }
    ```
  </Accordion>
</AccordionGroup>
