Repository navigation
Conversation
uploadImage(path, params) and uploadImageBytes(bytes, file_name, params), plus the typed uploadImageAs / uploadImageBytesAs, POST the image to https://serpapi.com/image as multipart/form-data and return its image_id for engines such as Google Lens. Ported from serpapi-rust's image-api. - the image goes in field `image`, filename kept (quotes and CR/LF escaped), content type sniffed from the JPEG/PNG/WebP signature, then the extension - api_key and source travel in the body, never in the URL; constructor search defaults (engine, output, ...) are not sent; a call param named `image` is a compile error - images over 500 KiB are rejected with error.ImageTooLarge before being read or sent - the upload shares fetch with every GET: the timeout race, the status check, the error payload rule, and lastError(), whose url is https://serpapi.com/image for a failed upload - live tests: upload from a file and from bytes, invalid image, invalid key, then a google_lens search on the uploaded image; oobt also uploads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Image API support, so an uploaded image can be searched with Google Lens. Ported from serpapi-rust's
image-apibranch; serpapi-ruby'simplement-image-apihas the same shape.Stacked on #1. The base is
parity-fixes, so this diff shows only the upload. When #1 merges, GitHub retargets this PR tomaster.Behavior
uploadImage(path, params)anduploadImageBytes(bytes, file_name, params), plus typeduploadImageAs/uploadImageBytesAsPOST https://serpapi.com/image,multipart/form-data:imagewith its filename kept. Quotes and CR/LF in the name are escaped.api_keyandsourcego in the body, never the URL. Constructor search defaults (engine, output, ...) are not sent. A call param namedimageis a compile error.error.ImageTooLargebefore being read or sent.lastError(). For a failed upload,lastError().urlishttps://serpapi.com/image.Breaking change (shipping in 1.2.0 by decision)
serpapi.ErrorgainsImageTooLarge, so exhaustive switches over it need a prong.Checks (merged with #1)
zig build lint: passzig build test: 41/41zig build itest(live,SERPAPI_KEYset): 22/22, including upload from a file and from bytes, invalid image, invalid key, then agoogle_lenssearch on the uploaded imagezig build oobt: pass (search and upload)Not included
There's no generated example yet: serpapi-library-tests-generator has no
example.zig.erbtemplate.🤖 Generated with Claude Code