Tired of manually converting files? I built MegaConvert — a file conversion API that handles
300+ format pairs: documents, images, video, audio, ebooks, fonts, and more.
In this post I'll show you how to convert files programmatically in 3 steps using Python, JavaScript, or cURL.
## How It Works
Every conversion follows the same flow:
-
POST your file to
/convert -
Poll
/status/{job_id}until it's done -
GET
/download/{job_id}to grab the result
Base URL: https://megaconvert.io/api/v1
Auth: X-API-Key header
## cURL — Quick Test
bash
# Step 1: Submit
curl -X POST https://megaconvert.io/api/v1/convert \
-H "X-API-Key: mc_your_key" \
-F "file=@document.pdf" \
-F "output_format=docx"
# Response: {"job_id": "abc123", "status": "processing"}
# Step 2: Check status
curl https://megaconvert.io/api/v1/status/abc123 \
-H "X-API-Key: mc_your_key"
# Step 3: Download
curl -O https://megaconvert.io/api/v1/download/abc123 \
-H "X-API-Key: mc_your_key"
Python Example
import requests
import time
API_KEY = "mc_your_api_key_here"
BASE = "https://megaconvert.io/api/v1"
headers = {"X-API-Key": API_KEY}
# Submit conversion
with open("image.png", "rb") as f:
r = requests.post(f"{BASE}/convert", headers=headers,
files={"file": f},
data={"output_format": "webp"})
job_id = r.json()["job_id"]
# Wait for completion
while True:
status = requests.get(f"{BASE}/status/{job_id}", headers=headers).json()["status"]
if status == "completed":
break
time.sleep(2)
# Download result
result = requests.get(f"{BASE}/download/{job_id}", headers=headers)
with open("image.webp", "wb") as f:
f.write(result.content)
JavaScript (Node.js)
const fs = require('fs');
const FormData = require('form-data');
const API_KEY = 'mc_your_api_key_here';
const BASE = 'https://megaconvert.io/api/v1';
const headers = { 'X-API-Key': API_KEY };
async function convertFile(inputPath, outputFormat) {
const form = new FormData();
form.append('file', fs.createReadStream(inputPath));
form.append('output_format', outputFormat);
// Submit
const res = await fetch(`${BASE}/convert`, {
method: 'POST',
headers: { ...headers, ...form.getHeaders() },
body: form
});
const { job_id } = await res.json();
// Poll
while (true) {
const status = await fetch(`${BASE}/status/${job_id}`, { headers });
const { status: s } = await status.json();
if (s === 'completed') break;
await new Promise(r => setTimeout(r, 2000));
}
// Download
const download = await fetch(`${BASE}/download/${job_id}`, { headers });
const buffer = Buffer.from(await download.arrayBuffer());
fs.writeFileSync(`output.${outputFormat}`, buffer);
}
convertFile('document.pdf', 'docx');
Built-in Tools
Beyond format conversion, the API has processing tools:
┌────────────────┬────────────────────────────┐
│ Tool │ What it does │
├────────────────┼────────────────────────────┤
│ compress-pdf │ Reduce PDF file size │
├────────────────┼────────────────────────────┤
│ merge-pdf │ Combine multiple PDFs │
├────────────────┼────────────────────────────┤
│ compress-image │ Optimize image size │
├────────────────┼────────────────────────────┤
│ resize-image │ Change dimensions │
├────────────────┼────────────────────────────┤
│ compress-video │ Reduce video file size │
├────────────────┼────────────────────────────┤
│ trim-video │ Cut video segments │
├────────────────┼────────────────────────────┤
│ video-to-gif │ Convert video clips to GIF │
├────────────────┼────────────────────────────┤
│ extract-audio │ Pull audio from video │
└────────────────┴────────────────────────────┘
# Compress a PDF
with open("large.pdf", "rb") as f:
r = requests.post(f"{BASE}/tool", headers=headers,
files={"file": f},
data={"tool": "compress-pdf"})
Supported Formats
300+ conversion pairs across:
- Documents: PDF, DOCX, XLSX, PPTX, ODT, CSV, HTML, RTF, TXT
- Images: JPG, PNG, WebP, HEIC, GIF, BMP, TIFF, SVG
- Video: MP4, WebM, AVI, MOV, MKV
- Audio: MP3, WAV, OGG, FLAC, AAC
- Ebooks: EPUB, MOBI, AZW3
- And more: fonts, subtitles, archives, vector/CAD
Full list: https://megaconvert.io/docs/api
Pricing
API access comes with the 12-month plan at $79/year — that's 100 requests/day, which works out to $0.003 per conversion.
Compare that to CloudConvert ($0.02+) or Zamzar ($0.08+).
Links
- API Docs: https://megaconvert.io/docs/api
- GitHub (examples + docs): https://github.com/rpnet/megaconvert-api
- Try it free: https://megaconvert.io — 3 free conversions/day, no account needed
---
If you have questions or want to see a specific integration example, drop a comment below.
https://megaconvert.io/docs/api
This article was originally published by DEV Community and written by MegaConvert.
Read original article on DEV Community