Image Ninja API
Process images with AI-powered tools. Remove backgrounds, upscale, extract text, colorize old photos, and more.
Introduction
The Image Ninja API provides powerful image processing capabilities through a simple REST interface. All endpoints accept POST requests with multipart form data for image uploads.
Base URL
https://image-ninja.io/api/v1
Quick Example
curl -X POST "https://image-ninja.io/api/v1/remove-background" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]"
Authentication
All API requests require authentication using an API key. Include your key in the Authorization header:
Authorization: Bearer ninja_sk_xxxxxxxxxxxxxxxxxxxxx
Alternatively, you can use the X-Api-Key header:
X-Api-Key: ninja_sk_xxxxxxxxxxxxxxxxxxxxx
Pricing & Credits
Image Ninja uses a credit-based system. Different operations consume different amounts of credits.
- 35 créditos/mes
- Full resolution
- Email support
- 100 créditos/mes
- Priority processing
- Priority support
- 280 créditos/mes
- Bulk processing
- Dedicated support
Credit Costs per Operation
| Operation | Credits | AI Provider |
|---|---|---|
| Remove Background | 1 | ClipDrop |
| Magic Eraser | 2 | ClipDrop + LaMa |
| AI Upscaler | 2 | ClipDrop |
| Colorize | 2 | DeOldify |
| Restore | 2 | GFPGAN |
| Text to Image | 3 | ClipDrop (SDXL) |
| Image Uncrop (Outpainting) | 3 | ClipDrop |
| Remove Text | 3 | ClipDrop |
| Compress / Convert / Resize | 1 | Local |
| OCR | 1 | Tesseract |
| QR Code | 1 | Local |
| Logo Fetch | 1 | Clearbit |
Remove Background
Remove background from images using AI.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
output | String | "json" (default) or "raw" for binary image |
Example
curl -X POST "https://image-ninja.io/api/v1/remove-background" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]"
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/png",
"width": 800,
"height": 600,
"processing_time_ms": 1234
}
}
Text to Image
Generate images from text descriptions using AI (Stable Diffusion XL via ClipDrop).
Parameters
prompt | String (required) | Text description of the image to generate (max 1000 chars) |
output | String | "json" (default) or "raw" for binary image |
Example
curl -X POST "https://image-ninja.io/api/v1/text-to-image" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "prompt=A serene mountain landscape at sunset with a calm lake"
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/png",
"width": 1024,
"height": 1024,
"prompt": "A serene mountain landscape..."
}
}
Image Uncrop (Outpainting)
Extend images beyond their original boundaries using AI. Perfect for changing aspect ratios or adding more context to cropped images.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
extend_left | Integer | Pixels to extend on the left (0-1024) |
extend_right | Integer | Pixels to extend on the right (0-1024) |
extend_up | Integer | Pixels to extend upward (0-1024) |
extend_down | Integer | Pixels to extend downward (0-1024) |
Example
curl -X POST "https://image-ninja.io/api/v1/image-uncrop" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "extend_left=200" \
-F "extend_right=200"
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/png",
"original_width": 800,
"original_height": 600,
"width": 1200,
"height": 600,
"extend_left": 200,
"extend_right": 200
}
}
AI Upscaler
Upscale images 2x or 4x using AI while preserving detail and quality.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
scale | Integer | 2 or 4 (default: 2) |
Example
curl -X POST "https://image-ninja.io/api/v1/upscale" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "scale=2"
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/jpeg",
"original_width": 400,
"original_height": 300,
"width": 800,
"height": 600,
"scale": 2
}
}
Magic Eraser
Remove unwanted objects from images using AI inpainting. Uses ClipDrop with LaMa fallback for best results.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
mask | String (required) | Base64-encoded mask image (white = areas to remove) |
engine | String | "auto" (default), "clipdrop", or "lama" |
Example
curl -X POST "https://image-ninja.io/api/v1/magic-eraser" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "mask=data:image/png;base64,..."
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/png",
"width": 800,
"height": 600,
"engine": "clipdrop"
}
}
Remove Text
Automatically remove all text, watermarks, captions, and overlays from images using AI.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
Example
curl -X POST "https://image-ninja.io/api/v1/remove-text" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@photo_with_text.jpg"
Response
{
"success": true,
"data": {
"image": "base64_encoded_image...",
"mime_type": "image/png",
"width": 800,
"height": 600
}
}
Compress Image
Compress images while maintaining quality.
Parameters
image | File (required) | Image file |
quality | Integer | 1-100 (default: 80) |
format | String | jpg, png, webp |
Response
{
"success": true,
"data": {
"image": "base64...",
"original_size": 245000,
"compressed_size": 89000,
"savings_percent": 63.7
}
}
Generate QR Code
Generate QR codes from text or URLs.
Parameters
content | String (required) | Text or URL to encode |
size | Integer | 50-2000 (default: 300) |
foreground | String | Hex color (default: #000000) |
background | String | Hex color (default: #FFFFFF) |
Logo Fetcher
Get company logo for any domain.
Example
curl "https://image-ninja.io/api/v1/logo/google.com" \
-H "Authorization: Bearer YOUR_API_KEY"
Response
{
"success": true,
"data": {
"domain": "google.com",
"logo": "base64...",
"favicon_url": "https://...",
"brand_colors": ["#4285F4", "#34A853", "#FBBC05", "#EA4335"]
}
}
OCR - Extract Text
Extract text from images using OCR.
Parameters
image | File (required) | Image file |
language | String | eng, spa, fra, deu, ita, etc. |
Response
{
"success": true,
"data": {
"text": "Extracted text content...",
"word_count": 42,
"line_count": 5,
"language": "eng"
}
}
Florence-2 AI Vision
Microsoft Florence-2 is a powerful vision-language model for image understanding. One endpoint supports multiple tasks: captioning, OCR, object detection, grounding, and more.
Parameters
image | File (required) | Image file (PNG, JPG, WebP) |
task | String (required) | caption, ocr, object_detection, dense_caption, grounding, open_detection |
detail_level | String | For caption: short, detailed, very_detailed |
with_regions | Boolean | For ocr: include text coordinates |
query | String | For grounding: what to find (e.g., "the red car") |
objects | String | For open_detection: comma-separated list (e.g., "cat, dog, car") |
Credit Costs
caption | 1 credit | Generate image descriptions |
ocr | 1 credit | Extract text from images |
object_detection | 2 credits | Detect all objects with bounding boxes |
dense_caption | 2 credits | Describe regions of the image |
grounding | 2 credits | Find objects by text description |
open_detection | 2 credits | Detect specific named objects |
Example: Image Captioning
curl -X POST https://image-ninja.io/api/v1/florence \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "task=caption" \
-F "detail_level=detailed"
Response (Caption)
{
"success": true,
"data": {
"task": "caption",
"caption": "A golden retriever sitting on a green lawn in a sunny park, with trees in the background.",
"detail_level": "detailed",
"processing_time_ms": 1234,
"image_size": {"width": 1920, "height": 1080}
}
}
Example: Object Detection
curl -X POST https://image-ninja.io/api/v1/florence \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "task=object_detection"
Response (Object Detection)
{
"success": true,
"data": {
"task": "object_detection",
"objects": [
{"label": "car", "bbox": {"x1": 100, "y1": 200, "x2": 400, "y2": 500}},
{"label": "person", "bbox": {"x1": 450, "y1": 150, "x2": 550, "y2": 600}}
],
"total_objects": 5,
"object_counts": {"car": 2, "person": 3},
"unique_labels": ["car", "person"],
"processing_time_ms": 1567
}
}
Example: Visual Grounding
curl -X POST https://image-ninja.io/api/v1/florence \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "task=grounding" \
-F "query=the red sofa"
Response (Grounding)
{
"success": true,
"data": {
"task": "grounding",
"query": "the red sofa",
"found": true,
"match_count": 1,
"matches": [
{"phrase": "the red sofa", "bbox": {"x1": 50, "y1": 300, "x2": 600, "y2": 550}}
],
"processing_time_ms": 1123
}
}
Account Info
Get current account information and credit balance.
Usage Statistics
Get API usage statistics.
Parameters
range | String | 7d, 30d, 90d, all (default: 30d) |
Error Codes
| Code | Meaning |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 402 | Payment Required - Insufficient credits |
| 403 | Forbidden - Account inactive or unverified |
| 404 | Not Found - Endpoint does not exist |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |