Skip to main content
POST
/
app
/
v1
/
organizations
/
{organizationId}
/
projects
/
{projectId}
/
components
/
{componentId}
/
assets
/
{assetId}
/
optimize
Optimize Asset
curl --request POST \
  --url https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize \
  --header 'Content-Type: application/json' \
  --data '
{
  "options": {},
  "options.quality": 123,
  "options.format": "<string>",
  "options.width": 123,
  "options.height": 123
}
'
Optimize an image asset by converting format, adjusting quality, or resizing.

Path Parameters

organizationId
string
required
Organization ID
projectId
string
required
Project ID
componentId
string
required
Component ID
assetId
string
required
Asset ID

Request Body

options
object
required
Optimization options (at least one property required)
options.quality
number
Image quality (1-100)
options.format
string
Output format: jpeg, png, webp, or avif
options.width
number
Target width in pixels (1-10000)
options.height
number
Target height in pixels (1-10000)

Example Request

{
  "options": {
    "quality": 85,
    "format": "webp",
    "width": 800
  }
}

Response

Returns the optimized Component Asset object.
{
  "id": "asset123",
  "componentId": "c123",
  "name": "hero-image.webp",
  "type": "image/webp",
  "url": "https://cdn.metabind.ai/.../hero-image.webp",
  "size": 45678,
  "status": "active",
  "metadata": {
    "width": 800,
    "height": 600,
    "originalSize": 2048576,
    "optimizedAt": "2024-03-22T10:00:00Z"
  },
  "tags": ["hero"],
  "createdAt": "2024-03-20T10:00:00Z",
  "updatedAt": "2024-03-22T10:00:00Z"
}
Optimization replaces the original file. The original size is stored in metadata for reference.

Error Responses

Unsupported Format

{
  "error": {
    "code": "UNSUPPORTED_FORMAT",
    "message": "Cannot optimize this file type",
    "details": {
      "type": "application/pdf"
    }
  }
}

Asset In Use

{
  "error": {
    "code": "ASSET_IN_USE",
    "message": "Asset is referenced in published packages and cannot be modified",
    "details": {
      "packages": ["1.0.0"]
    }
  }
}

Code Examples

curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/assets/asset123/optimize" \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "options": {
      "quality": 85,
      "format": "webp"
    }
  }'