Add image upload support (/image API) - #27
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class Image API support to the Ruby client so users can upload an image to /image (multipart/form-data) and then use the returned image_id with engines like google_lens.
Changes:
- Adds
SerpApi::Client#upload_imageand supporting POST/multipart request plumbing. - Refactors request execution to a unified
execute_request(method, endpoint, options)helper and introduces aposthelper. - Adds Image API documentation + examples to README, and introduces specs for file-path and IO-based uploads.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/serpapi/client.rb |
Implements upload_image, adds multipart POST support, refactors request execution. |
spec/serpapi/client/image_api_spec.rb |
Adds isolated specs for image upload behavior and error handling. |
README.md.erb |
Documents Image API usage and example flow (upload_image → search with image_id). |
README.md |
Same documentation update as README.md.erb for the published README. |
Suppressed comments (1)
spec/serpapi/client/image_api_spec.rb:43
- This spec checks that the request hits
/image, but it doesn’t assert that the multipart form includesapi_key(required by the Image API). Adding an assertion here will catch regressions where authentication isn’t sent for IO uploads.
expect(socket).to receive(:post) do |endpoint, options|
expect(endpoint).to eq('/image')
response
end
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ## Contributing | ||
|
|
||
| Contributions are welcome. Make sure to read our [contributing guide](./CONTRIBUTING.md). | ||
| Contributions are welcome. Make sure to read our [contributing guide](https://github.com/serpapi/serpapi-ruby/blob/master/CONTRIBUTING.md). |
There was a problem hiding this comment.
I originally kept a local link so when you work with the repo or it's hosted somewhere it works as usual. The .erb version has a full link because it's on the website. Can you explain more?
There was a problem hiding this comment.
Ah, okay. Thanks for noticing.

Documentation: https://serpapi.com/image-api
Changes:
SerpApi::Client#upload_image/imageas multipart/form-data.