Image Converter API¶
Overview¶
Convert images between JPG, PNG, GIF, WebP, and Base64 formats. Body mode processes the supplied content synchronously. URL and file modes create an asynchronous conversion job.
Endpoint¶
POST https://api.apidatatools.com/image-converter-api
Authentication¶
Include your API key in the x-api-key header:
x-api-key: YOUR_API_KEY
Input modes¶
Select a mode with x-source-type:
| Mode | Behavior |
|---|---|
body | Synchronous. Send the input as the request body. This is the default mode. |
url | Asynchronous. Send a JSON object containing the source URL. |
file | Asynchronous. Send a JSON object containing the exact storage key returned by the upload workflow. |
Headers¶
Header names are case-insensitive. The spellings below are lowercase.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | string | Yes | Your API key | Authenticates the request. |
x-source-type | string | No | body; body, url, or file | Selects the input mode. |
x-source-format | string | Yes | jpg, jpeg, png, gif, webp, or base64 | Declares the source format. jpeg is treated as jpg. |
x-destination-format | string | Yes | jpg, jpeg, png, gif, webp, or base64 | Selects the output format. jpeg is treated as jpg. |
x-image-quality | integer | No | 90; 1–100 | Quality setting for JPG and WebP output. |
x-image-effort | integer | No | 4; 0–6 | Effort setting for WebP output. |
x-image-preserve-metadata | boolean | No | true | Whether to preserve image metadata. |
x-image-progressive | boolean | No | JPG: true; PNG: false | Progressive/interlaced output setting for JPG or PNG. |
x-image-auto-orient | boolean | No | true | Applies automatic orientation to non-animated images. |
x-image-background | string | No | #ffffff; six hexadecimal digits, with or without # | Background color used when JPG output needs transparency flattened. |
x-png-compression | integer | No | 6; 0–9 | Compression setting for PNG output. |
x-image-lossless | boolean | No | false | Selects lossless WebP output when enabled. |
x-gif-dither | integer | No | 100; 0–100 | Dithering setting for GIF output. |
x-gif-effort | integer | No | 7; 1–10 | Effort setting for GIF output. |
x-image-animation | string | No | preserve; preserve, first-frame, or reject | Controls handling of animated images. If the destination does not support animation, reject returns an error; otherwise only the first frame is used. |
Boolean option headers accept true, 1, yes, or on for true, and false, 0, no, or off for false.
Accepted file extensions¶
For URL and file modes, the accepted extensions are:
jpg, jpeg, png, gif, webp, txt
The extension is checked when a URL or file reference is submitted. File-size limits depend on your plan. See tool limits.
Request body¶
Body mode¶
Send the image as the raw request body. For this binary endpoint, use curl --data-binary. Set x-source-format to the input format and x-destination-format to the desired output format.
For Base64 input, set x-source-format: base64 and send the Base64 content as the body. A Base64 data URI is also accepted. Set x-destination-format: base64 to receive Base64-encoded output.
URL mode¶
Send a JSON object with a url property:
{
"url": "https://example.com/input.png"
}
File mode¶
Send a JSON object with a file property containing the exact storage key returned by the upload workflow:
{
"file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}
Examples¶
Body mode¶
curl --request POST \
--url https://api.apidatatools.com/image-converter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--header 'x-source-format: png' \
--header 'x-destination-format: webp' \
--data-binary @input.png
URL mode¶
curl --request POST \
--url https://api.apidatatools.com/image-converter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: url' \
--header 'x-source-format: png' \
--header 'x-destination-format: webp' \
--header 'Content-Type: application/json' \
--data-binary '{"url":"https://example.com/input.png"}'
File mode¶
curl --request POST \
--url https://api.apidatatools.com/image-converter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: file' \
--header 'x-source-format: png' \
--header 'x-destination-format: webp' \
--header 'Content-Type: application/json' \
--data-binary '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'
Success responses¶
Synchronous body mode¶
A successful body-mode conversion returns HTTP 200 with a file URL and preview:
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/...",
"preview": "Conversion successful. Download the converted image."
}
When the destination format is Base64, the output file is text and its preview contains output text. Download URLs are temporary; retention depends on your plan. See tool limits.
Asynchronous URL and file modes¶
A successfully accepted asynchronous request returns HTTP 202:
{
"status": "accepted",
"job_id": "JOB_ID",
"status_url": "https://api.apidatatools.com/jobs/JOB_ID",
"request_id": "REQUEST_ID"
}
Async job status¶
Retrieve a job’s status with an authenticated GET request:
GET https://api.apidatatools.com/jobs/{job_id}
The status response includes request_id, job_id, status, created_at, and updated_at. Its remaining fields depend on the job state.
Queued or processing¶
Both states include a message and retry interval:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "queued",
"created_at": 1700000000,
"updated_at": 1700000000,
"message": "Your job is being processed.",
"retry_after": 2
}
The status value is queued or processing.
Success¶
A completed job includes its result:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "success",
"created_at": 1700000000,
"updated_at": 1700000002,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/...",
"preview": "Conversion successful. Download the converted image."
}
}
Failed¶
A failed job includes an error code, message, and details:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "failed",
"created_at": 1700000000,
"updated_at": 1700000002,
"error": {
"code": "ERROR_CODE",
"message": "Description of the error.",
"details": {
"message": "Description of the error."
}
}
}
The error.details object may contain additional error information.
Error handling¶
HTTP error responses use this envelope:
{
"status": "error",
"error": "ERROR_CODE",
"request_id": "REQUEST_ID",
"details": {
"message": "Description of the error."
}
}
Additional fields may appear in details. The following statuses are grounded in the API implementation:
| HTTP status | Error codes and conditions |
|---|---|
400 | INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION, INVALID_IMAGE_OPTION, INVALID_BASE64, INVALID_IMAGE_FILE, UNSUPPORTED_IMAGE_FILE, IMAGE_FORMAT_MISMATCH, IMAGE_PIXEL_LIMIT, ANIMATED_IMAGE_UNSUPPORTED, IMAGE_CONVERSION_FAILED, MISSING_FORMATS, UNSUPPORTED_FORMAT, MISSING_INPUT_FILE, INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, DDB_ERROR |
401 | UNAUTHORIZED |
404 | USER_NOT_FOUND, UNKNOWN_FUNCTION |
413 | PAYLOAD_TOO_LARGE, FILE_TOO_LARGE |
429 | QUOTA_EXCEEDED, RATE_LIMITED |
500 | PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR |
Errors from asynchronous processing, including DOWNLOAD_FAILED, UPLOAD_FAILED, and INVALID_JOB, are reported in the job’s failed status. Body-size and file-size limits depend on your plan; see tool limits.
Notes¶
- Body mode is synchronous; URL and file modes are asynchronous.
- The declared source format must match the image content for image conversions. Base64 source input is decoded before image conversion.
- Animated images can be kept animated when the destination format supports animation. The
x-image-animationoption controls whether to preserve animation, use the first frame, or reject it. - Download URLs are temporary, and their retention period depends on your plan.