REST API v1

API Reference

Process images programmatically. Try 3 ops free without signing up — or create a free account for 30/month. Lite and Pro plans unlock more with an API key.

Overview

All API requests are made to the base URL:

https://api.mochify.xyz

Free account

30

ops/mo · 3 without signup

Lite tier

300

operations / month

Pro tier

1,200

operations / month

Max file size

75 MB

Lite · unlimited Pro · 20 MB free

Without an account: 3 ops/month (IP-based). Free account: 30 ops/month. Paid API keys use per-key limits. Each image processed — regardless of operations applied — counts as one operation.

Authentication

The free tier requires no authentication. Pro API keys are generated from your dashboard and passed as a Bearer token:

Header
Authorization: Bearer mchy_••••••••••••••••
!

API keys are shown once at creation and cannot be retrieved again. Store them securely. You can regenerate a key from your dashboard at any time.

POST

/v1/squish

Compress and/or convert a single image. Send the raw image bytes as the request body. Returns the processed image as a binary blob.

Query Parameters

Parameter Default Description
type jpg

Output format.

One of: jpg · webp · avif · jxl

width

Target width in pixels. Aspect ratio is preserved unless smartCrop is also set. Omit or set to 0 for unconstrained.

height

Target height in pixels. Omit or set to 0 for unconstrained.

quality auto

Output quality override (1–100). Overrides smart compression. JXL maps linearly — 70 ≈ distance 3.0.

smartCompress false

Saliency-guided quality selection. High-detail subjects get higher quality, flat areas lower. Accepts 1 or true.

smartCrop

alias: crop

false

Saliency-guided crop — centers the crop on the detected subject. Requires both width and height. Accepts 1 or true.

removeBackground false

AI background removal. Output is PNG/WebP with alpha channel. JPEG outputs flatten to white. Requires Lite or Pro plan. Accepts 1 or true.

rotate 0

Clockwise rotation in degrees.

Supported values: 90 · 180 · 270

stripExif true

Strip EXIF metadata from the output. Set to false or 0 to preserve metadata.

Request Headers

Content-Type

MIME type of the uploaded image. E.g. image/jpeg, image/webp, image/avif, image/png, image/heic, image/jxl

Response

Header / Field Description
Body

Raw compressed image bytes. Supported input formats: JPEG, PNG, WebP, AVIF, HEIF, JXL.

X-Latency-Ms

Processing time in milliseconds.

X-Mochify-Optimized

true if the output is smaller or the format changed; false if the original was returned unchanged.

X-Mochify-Reason

Present when X-Mochify-Optimized: false. Explains why the original was returned, e.g. "Original was smaller".

X-Mochify-Saliency

Saliency score (0.000–1.000). Only present when smartCompress=true.

X-Mochify-Quality

Effective quality value used. Only present when smartCompress=true.

X-Mochify-BgRemoved

true when background removal was applied.

Examples

cURL
curl -X POST "https://api.mochify.xyz/v1/squish?type=webp&stripExif=1" \
  -H "Content-Type: image/jpeg" \
  -H "Authorization: Bearer mchy_your_api_key" \
  --data-binary @photo.jpg \
  --output photo.webp
JavaScript
const file = document.querySelector('input[type="file"]').files[0];

const response = await fetch(
  'https://api.mochify.xyz/v1/squish?type=avif&stripExif=1',
  {
    method: 'POST',
    headers: {
      'Content-Type': file.type,
      'Authorization': 'Bearer mchy_your_api_key',
    },
    body: file,
  }
);

const blob = await response.blob();
const latency = response.headers.get('X-Latency-Ms');

// Save the file
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'output.avif';
a.click();
Python
import requests

with open('photo.jpg', 'rb') as f:
    response = requests.post(
        'https://api.mochify.xyz/v1/squish',
        params={'type': 'webp', 'stripExif': '1'},
        headers={
            'Content-Type': 'image/jpeg',
            'Authorization': 'Bearer mchy_your_api_key',
        },
        data=f,
    )

with open('output.webp', 'wb') as out:
    out.write(response.content)

print(f"Done in {response.headers.get('X-Latency-Ms')}ms")
GET

/v1/checkTokens

Returns the number of remaining operations for the current IP or API key. Useful for checking quota before submitting a batch.

Response

Field Type Description
remaining number

Total remaining operations for the current IP or API key.

available boolean

true if at least one operation remains.

cURL
curl "https://api.mochify.xyz/v1/checkTokens" \
  -H "Authorization: Bearer mchy_your_api_key"

# Response
# { "remaining": 983, "available": true }
POST

/v1/prompt

Interprets a plain-language prompt and returns per-file processing parameters to pass to /v1/squish. This powers the Magic Flow feature.

Request Body application/json

Field Required Description
prompt required

Natural language description of what you want to do. E.g. "Convert to WebP and strip location data".

fileData required

Array of file metadata objects. Used to generate per-file configs.

Each object: { name: string, width: number, height: number }

cURL
curl -X POST "https://api.mochify.xyz/v1/prompt" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer mchy_your_api_key" \
  -d '{
    "prompt": "Convert to AVIF and strip EXIF data",
    "fileData": [
      { "name": "photo.jpg", "width": 4032, "height": 3024 }
    ]
  }'
i

The response contains per-file parameters. Pass them directly to /v1/squish as query params for each file.

Errors

The API uses standard HTTP status codes.

Status Meaning
200

Success. Response body is the processed image.

400

Bad request — missing or invalid parameters.

401

Unauthorized — invalid or missing API key.

429

Rate limit exceeded. Free tier resets monthly; Lite and Pro reset on your billing date. Upgrade for higher limits.

500

Server error — the image could not be processed.

Need more operations?

Upgrade to Pro for 1,000 operations/month and a dedicated API key.