Skip to content

Add support for /image api - #14

Merged
ilyazub merged 7 commits into
mainfrom
image-api
Oct 14, 2026
Merged

ilyazub merged 7 commits into
mainfrom
image-api

Conversation

@strzibny

@strzibny strzibny commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@ilyazub

ilyazub commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Max wrote this:
#17 is merged (7acfb80); against main this PR now conflicts in 4 files (README.md, pkg/api/client.go, pkg/api/client_test.go, pkg/cmd/search.go). What image joins on rebase: errors print as one JSON line on stderr and exit 2 when the command is wrong, which clierrors here already gives; commands build their client with newClient (pkg/cmd/root.go), which applies --timeout and SERPAPI_TIMEOUT; and stdin comes through cmd.InOrStdin(), which the in-process tests in pkg/cmd drive.

@ilyazub

ilyazub commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Max rebase, fixes and tests:

Thanks @strzibny! Rebased onto main 993b281 with 4 fixes on top: image-api moved from 0f16224 to 23bcdc5. If you have no unpushed commits on it, git fetch origin && git switch image-api && git reset --keep origin/image-api updates your branch.

Your commit, now 5ce3edd, keeps your authorship and changed only where main had moved on: the upload shares main's response handling (do, errorMessage) and withSpinner, and your live tests use main's requireLive.

  1. 27f3d20: uploads ignored --timeout, since they built their own client, and image - read os.Stdin. They use newClient and cmd.InOrStdin() now, like search and login: 4 of the 6 new tests failed before.
  2. ae9b8bc: empty and oversized images were uploaded anyway; a 600 KB PNG went up in full. Empty or over 500 KB, the limit https://serpapi.com/image-api states, now exits 2 before any request: 5 of 5 cases.
  3. 32157d9: Ctrl-C on image - waited 3.1s for the forced exit. It now exits 130 in under 0.1s.
  4. 23bcdc5: a timed-out upload got the search advice ("count against your searches", "search archive"). It now says only how to retry; other endpoints are unchanged.

go test -race ./... passes on each commit here, with no key; the live e2e tests run in CI on this push.

Questions:

  • Does an upload count against the searches left? The Cost line lists account, locations and archive as free, so image belongs on one side.
  • Which engines take image_id besides google_lens? If only Lens, search --image could refuse other engines before uploading.

Whichever of this and #16 merges second won't build until do takes #16's tracer (undefined: tr ×5), and logRequest has to print req.Method, or uploads are traced as GETs. git also marks the start of the timeout advice: close #16's debugHint block before this PR's /image branch, and append the hint to the upload's message too.

Label release:minor. To ship this and #16 as one v0.4.0, label the first merge release:skip and the second release:minor.

GPT-6 Astra Max advised.

strzibny and others added 6 commits October 14, 2026 14:12
image and search --image built their client with api.New, so --timeout
and SERPAPI_TIMEOUT didn't apply to uploads and tests couldn't point them
at a fake API, and they read os.Stdin rather than the command's stdin.
They now use newClient and cmd.InOrStdin(), as search and login do; of 6
new tests against the fake API, 4 failed before, sending to serpapi.com.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Image API takes up to 500 KB, but image and search --image read the
file or stdin whole and uploaded it, empty too, for the API to reject
(exit 1). The read now stops one byte past 500 KiB, and an empty or larger
image is a usage error, exit 2, before any request: of 5 such cases in the
new tests, all 5 were uploaded before, none now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
image - read stdin with nothing watching for the signal, so Ctrl-C ended
it only at the forced exit 3s later, "the output may be cut off". The read
now stops on the signal as login's does: exit 130 after 0.0s instead of
3.1s on a terminal. The README says an image given as - reads stdin too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A timed-out upload got the search advice: slow engines such as
google_ai_mode, and that the search may still finish, count against your
searches and be in the archive. An upload has no engine, search or archive
entry, so /image now says only how to retry with a higher --timeout.
Searches and every other endpoint keep the message byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing else checks that an upload shows up in --debug at all: this asserts it is traced as POST /image with its connection timings, never as a GET, and without the API key.
@strzibny strzibny added the release:minor Merging releases the next minor version label Oct 14, 2026
@strzibny

Copy link
Copy Markdown
Contributor Author

@ilyazub PR #16 is merged, this is updated and set as a minor release.

@ilyazub ilyazub added release:skip Merging releases nothing and removed release:minor Merging releases the next minor version labels Oct 14, 2026
@ilyazub
ilyazub merged commit 433aa35 into main Oct 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:skip Merging releases nothing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants