Image API
Upload an image for use with Search API engines such as the Google Lens API by sending a multipart/form-data POST request to https://serpapi.com/image. Head to the example for more details.
JSON Results
JSON output includes the image_id of the uploaded image. The image_id can be used with the Search API engines, such as the Google Lens API.
*The uploaded image_id will be expired after 10 minutes.
Example
POST
-
https://serpapi.com/image
Multipart form data
-
image=@/path/to/image.png
Example in cURL
-
curl -X POST https://serpapi.com/image \ -F "image=@/path/to/image.png" \ -F "api_key=secret_api_key"
JSON Output Example
{
"message": "Image uploaded successfully.",
"image_id": "xokJFnic22FmYZ6SbJZmYmCaamhsbpZsmZxsmZpsbgEAYzoHYg"
}
Error handling
When using the Image API, you can detect errors by checking for the presence of the error key in the response. If this key exists, it indicates that there was an issue uploading the image.
POST
-
https://serpapi.com/image
Multipart form data
-
image=@/path/to/invalid.txt
Example in cURL
-
curl -X POST https://serpapi.com/image \ -F "image=@/path/to/invalid.txt" \ -F "api_key=secret_api_key"
JSON Output Example
{
"error": "Invalid image format. Supported format: jpg, jpeg, png, webp"
}