Skip to content

RapidAPI examples

These are the same calls as examples.md, adapted for consumers who reach Purlo through RapidAPI rather than directly.

The difference is authentication and host:

  • Direct: call https://api.purlo.dev/v1/image with Authorization: Bearer purlo_YOUR_KEY.
  • Via RapidAPI: call the RapidAPI gateway host with your RapidAPI key. RapidAPI proxies the request to Purlo and adds the proxy secret itself — you never send a Purlo key.

Send both RapidAPI headers on every request:

X-RapidAPI-Key:  <your RapidAPI application key>
X-RapidAPI-Host: purlo.p.rapidapi.com

The request URL is the RapidAPI gateway path for the endpoint (RapidAPI shows the exact one on the listing — typically https://purlo.p.rapidapi.com/v1/image). The body is identical to the direct API: multipart form-data with an operations JSON field and an image file (or a url field instead of a file).

Paste-ready for the RapidAPI listing's "Code Snippets" / example section. RapidAPI can also auto-generate these; keep whichever reads cleaner, but the shapes below match the real endpoint exactly.

Each example does the canonical call: resize photo.jpg to 800px wide, convert to WebP, compress at quality 80, and strip EXIF metadata.

curl

curl -X POST https://purlo.p.rapidapi.com/v1/image \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: purlo.p.rapidapi.com" \
  -F 'operations={"resize":{"w":800},"format":"webp","quality":80,"strip":true}' \
  -F "image=@photo.jpg" \
  -o out.webp

JavaScript (fetch, Node 18+ or browser)

import { readFile, writeFile } from 'node:fs/promises';

const operations = {
  resize: { w: 800 },
  format: 'webp',
  quality: 80,
  strip: true,
};

const form = new FormData();
form.append('operations', JSON.stringify(operations));
form.append('image', new Blob([await readFile('photo.jpg')]), 'photo.jpg');

const res = await fetch('https://purlo.p.rapidapi.com/v1/image', {
  method: 'POST',
  headers: {
    'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY',
    'X-RapidAPI-Host': 'purlo.p.rapidapi.com',
  },
  body: form,
});

if (!res.ok) {
  const { error } = await res.json();
  throw new Error(`${error.code}: ${error.message}`);
}

await writeFile('out.webp', Buffer.from(await res.arrayBuffer()));

In a browser, drop the node:fs/promises import and build the Blob from a <input type="file"> element's files[0] instead.

PHP (curl)

<?php

$operations = [
    'resize'  => ['w' => 800],
    'format'  => 'webp',
    'quality' => 80,
    'strip'   => true,
];

$ch = curl_init('https://purlo.p.rapidapi.com/v1/image');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'X-RapidAPI-Key: YOUR_RAPIDAPI_KEY',
        'X-RapidAPI-Host: purlo.p.rapidapi.com',
    ],
    CURLOPT_POSTFIELDS => [
        'operations' => json_encode($operations),
        'image'      => new CURLFile('photo.jpg'),
    ],
    CURLOPT_RETURNTRANSFER => true,
]);

$body   = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status !== 200) {
    fwrite(STDERR, $body . PHP_EOL);
    exit(1);
}

file_put_contents('out.webp', $body);

Python (requests)

import json
import requests

operations = {
    "resize": {"w": 800},
    "format": "webp",
    "quality": 80,
    "strip": True,
}

with open("photo.jpg", "rb") as image:
    resp = requests.post(
        "https://purlo.p.rapidapi.com/v1/image",
        headers={
            "X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
            "X-RapidAPI-Host": "purlo.p.rapidapi.com",
        },
        data={"operations": json.dumps(operations)},
        files={"image": image},
    )

resp.raise_for_status()

with open("out.webp", "wb") as f:
    f.write(resp.content)

Fetching by URL instead of uploading

Send a url field instead of an image file (curl):

curl -X POST https://purlo.p.rapidapi.com/v1/image \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: purlo.p.rapidapi.com" \
  -F 'operations={"resize":{"w":800},"format":"webp","quality":80,"strip":true}' \
  -F "url=https://example.com/photo.jpg" \
  -o out.webp

See Reference for every operation and Errors & limits for status codes and quota behaviour. Quotas and rate limits for RapidAPI traffic are governed by your RapidAPI plan, not the direct-signup tiers.