Skip to content

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

Open
tanysheng wants to merge 7 commits into
masterfrom
implement-image-api
Open

Add image upload support (/image API)#27
tanysheng wants to merge 7 commits into
masterfrom
implement-image-api

Conversation

@tanysheng

@tanysheng tanysheng commented Aug 17, 2026

Copy link
Copy Markdown

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

Changes:

  • Add SerpApi::Client#upload_image
  • Send images to POST /image as multipart/form-data.
  • Support image uploads from:
    • File paths
    • IO objects, including File and StringIO

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_image and supporting POST/multipart request plumbing.
  • Refactors request execution to a unified execute_request(method, endpoint, options) helper and introduces a post helper.
  • 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_imagesearch 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 includes api_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.

Comment thread lib/serpapi/client.rb
Comment thread lib/serpapi/client.rb
Comment thread spec/serpapi/client/image_api_spec.rb
Comment thread lib/serpapi/client.rb Outdated
@tanysheng
tanysheng requested a review from strzibny August 18, 2026 05:18
Comment thread README.md
## 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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was generated from the .erb version. We are actually using just the .md on the website, it is broken atm.

CleanShot 2026-08-18 at 15 57 14@2x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Thanks for noticing.

@strzibny strzibny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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