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
Keep your API key secure! Never expose it in client-side code or public repositories.

Pricing & Credits

Image Ninja uses a credit-based system. Different operations consume different amounts of credits.

Starter
19€/mes
  • 35 créditos/mes
  • Full resolution
  • Email support
Business
99€/mes
  • 280 créditos/mes
  • Bulk processing
  • Dedicated support

Credit Costs per Operation

OperationCreditsAI Provider
Remove Background1ClipDrop
Magic Eraser2ClipDrop + LaMa
AI Upscaler2ClipDrop
Colorize2DeOldify
Restore2GFPGAN
Text to Image3ClipDrop (SDXL)
Image Uncrop (Outpainting)3ClipDrop
Remove Text3ClipDrop
Compress / Convert / Resize1Local
OCR1Tesseract
QR Code1Local
Logo Fetch1Clearbit

Remove Background

POST /api/v1/remove-background 1 credit

Remove background from images using AI.

Parameters

imageFile (required)Image file (PNG, JPG, WebP)
outputString"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

POST /api/v1/text-to-image 3 credits

Generate images from text descriptions using AI (Stable Diffusion XL via ClipDrop).

Parameters

promptString (required)Text description of the image to generate (max 1000 chars)
outputString"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..."
  }
}
Content Policy: Prompts containing inappropriate content (nudity, violence, etc.) will be rejected.

Image Uncrop (Outpainting)

POST /api/v1/image-uncrop 3 credits

Extend images beyond their original boundaries using AI. Perfect for changing aspect ratios or adding more context to cropped images.

Parameters

imageFile (required)Image file (PNG, JPG, WebP)
extend_leftIntegerPixels to extend on the left (0-1024)
extend_rightIntegerPixels to extend on the right (0-1024)
extend_upIntegerPixels to extend upward (0-1024)
extend_downIntegerPixels 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
  }
}
Note: At least one extension direction must be specified. Maximum output size is 2048x2048 pixels.

AI Upscaler

POST /api/v1/upscale 2 credits

Upscale images 2x or 4x using AI while preserving detail and quality.

Parameters

imageFile (required)Image file (PNG, JPG, WebP)
scaleInteger2 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
  }
}
Note: Maximum output size is 4096x4096 pixels. Images will be scaled proportionally if the result would exceed this limit.

Magic Eraser

POST /api/v1/magic-eraser 2 credits

Remove unwanted objects from images using AI inpainting. Uses ClipDrop with LaMa fallback for best results.

Parameters

imageFile (required)Image file (PNG, JPG, WebP)
maskString (required)Base64-encoded mask image (white = areas to remove)
engineString"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

POST /api/v1/remove-text 3 credits

Automatically remove all text, watermarks, captions, and overlays from images using AI.

Parameters

imageFile (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
  }
}
Note: The AI automatically detects and removes all visible text. Works best with clear, legible text on contrasting backgrounds.

Compress Image

POST /api/v1/compress 1 credit

Compress images while maintaining quality.

Parameters

imageFile (required)Image file
qualityInteger1-100 (default: 80)
formatStringjpg, png, webp

Response

{
  "success": true,
  "data": {
    "image": "base64...",
    "original_size": 245000,
    "compressed_size": 89000,
    "savings_percent": 63.7
  }
}

Generate QR Code

POST /api/v1/qr-code 1 credit

Generate QR codes from text or URLs.

Parameters

contentString (required)Text or URL to encode
sizeInteger50-2000 (default: 300)
foregroundStringHex color (default: #000000)
backgroundStringHex color (default: #FFFFFF)

OCR - Extract Text

POST /api/v1/ocr 1 credit

Extract text from images using OCR.

Parameters

imageFile (required)Image file
languageStringeng, 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.

POST /api/v1/florence 1-2 credits

Parameters

imageFile (required)Image file (PNG, JPG, WebP)
taskString (required)caption, ocr, object_detection, dense_caption, grounding, open_detection
detail_levelStringFor caption: short, detailed, very_detailed
with_regionsBooleanFor ocr: include text coordinates
queryStringFor grounding: what to find (e.g., "the red car")
objectsStringFor open_detection: comma-separated list (e.g., "cat, dog, car")

Credit Costs

caption1 creditGenerate image descriptions
ocr1 creditExtract text from images
object_detection2 creditsDetect all objects with bounding boxes
dense_caption2 creditsDescribe regions of the image
grounding2 creditsFind objects by text description
open_detection2 creditsDetect 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 /api/v1/account

Get current account information and credit balance.

Usage Statistics

GET /api/v1/usage

Get API usage statistics.

Parameters

rangeString7d, 30d, 90d, all (default: 30d)

Error Codes

CodeMeaning
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
402Payment Required - Insufficient credits
403Forbidden - Account inactive or unverified
404Not Found - Endpoint does not exist
429Too Many Requests - Rate limit exceeded
500Internal Server Error