Skip to content

Add image upload support (/image API) - #3

Merged
jvmvik merged 8 commits into
devfrom
image-api
Nov 3, 2026
Merged

jvmvik merged 8 commits into
devfrom
image-api

Conversation

@strzibny

@strzibny strzibny commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Documentation: https://serpapi.com/image-api

Done on top of #2 which should be merged first.

@tanysheng

Copy link
Copy Markdown

@strzibny Can you resolve the conflicts?

@strzibny

Copy link
Copy Markdown
Contributor Author

@tanysheng Done.

- raw() reuses the query() helper and keeps the non-2xx status check
- Keep both Markdown and Image API docs in README and lib.rs
- Keep 1.2.1 changelog entry below the unreleased Image API entry
# Conflicts:
#	README.md
@jvmvik jvmvik self-assigned this Nov 2, 2026
jvmvik and others added 4 commits November 2, 2026 06:48
- Clean up the upload test temp file even when the upload fails
- Name the upload temp file per pid to avoid collisions
- Align the Google Lens example with the other examples

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
post_multipart() parsed the response body as JSON without checking the
HTTP status. SerpApi reports upload errors as non-2xx JSON (400 for an
unsupported image, 401 for an invalid API key), so these only surfaced
because the body happened to hold an "error" field. A non-JSON error
page from a proxy (502, 413...) failed with a cryptic serde parse error
such as "expected value at line 1 column 1".

- Extract send() from raw() to check the status and read the body
- Route post_multipart() through send() so uploads report HTTP errors
  like GET requests: "/image failed with HTTP <status>: <body>"
- Assert the HTTP status in the invalid image test
- Add upload_image_rejects_invalid_api_key to cover HTTP 401

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Send only api_key and source to the Image API
- Detect the image MIME type from its signature
- Reject images over 500 KB before uploading
- Check the sample image download status in the example
- Handle missing visual_matches in the example

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvmvik
jvmvik merged commit b55a3bb into dev Nov 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants