Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 1.2.0 (unreleased)
## 1.2.0 (2026-11-30)

### Features

Expand Down Expand Up @@ -29,13 +29,28 @@
- CI: the coverage job runs on Linux arm64 (Debian trixie container) instead
of macOS, where kcov hung the unit-test binary until the step timed out on
every run. It is no longer advisory, and fails below 90% line coverage
- Usage reporting moves from the `source` query parameter to the
`User-Agent` header, following serpapi-ruby and SerpApi#11027. Every
request (GET and the Image API POST alike) sends
`serpapi-zig/<version> zig/<zig version> (<os>; <arch>)`, e.g.
`serpapi-zig/1.2.0 zig/0.16.0 (macos; aarch64)`, in place of std.http's
default `zig/0.16.0 (std.http)`. The Zig version is the compiler that
built the client and the platform is the build target. The value is a
compile-time constant, exported as `serpapi.user_agent`

### Behavior changes

- `errorMessage()` and `lastError()` describe the most recent request only:
every request clears the previous failure, so they return null after a
success or a transport error. Previously the last failure lingered, and a
DNS error after a 404 still reported the 404
- The client no longer adds `source=serpapi-zig:<version>` to request URLs
or to the Image API form, so it no longer shows up in `lastError().url`
either
- Fix: a `source` passed to the constructor is sent once, as given.
Previously the library appended its own, and the request carried two
`source` values. A `source` passed to a call was, and still is, sent as
given

### Breaking changes

Expand Down
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ Released versions are listed on the
[releases page](https://github.com/serpapi/serpapi-zig/releases); changes
are recorded in [CHANGELOG.md](CHANGELOG.md). The version number lives in
one place, `build.zig.zon`: `build.zig` forwards it to the library as
`serpapi.version`, which is what the client reports to serpapi.com, and
`rake release` reads it to name the tag.
`serpapi.version`, which is what the client reports to serpapi.com in its
`User-Agent` header, and `rake release` reads it to name the tag.

## Simple Usage

Expand Down Expand Up @@ -170,9 +170,18 @@ The client reports its configuration back:
```zig
client.engine() // ?[]const u8: default engine, "google" here
client.apiKey() // ?[]const u8: the API key given to the constructor
serpapi.version // the library version, "1.2.0", reported to serpapi.com
serpapi.version // the library version, "1.2.0"
serpapi.user_agent // "serpapi-zig/1.2.0 zig/0.16.0 (macos; aarch64)"
```

Every request sends `serpapi.user_agent` as its `User-Agent` header, so
SerpApi can see which library versions, Zig versions and platforms are in
use and focus testing on them. It names the library version, the Zig
compiler that built the client, and the build target's OS and CPU
architecture; it carries no search parameters and nothing about your
account. The client adds no `source` query parameter: a `source` you pass
yourself, to the constructor or a call, is sent as given.

Printing the client masks the API key, as serpapi-ruby's `inspect` does —
the first and last four characters of a key longer than eight, `****`
otherwise:
Expand Down Expand Up @@ -358,7 +367,7 @@ connection, TLS) — such errors carry no details beyond the Zig error itself.
```zig
var archived = client.searchArchive(search_id) catch |err| {
if (client.lastError()) |info| {
// SerpApiError: HTTP 404 https://serpapi.com/searches/<id>.json?source=serpapi-zig%3A1.2.0: Search not found.
// SerpApiError: HTTP 404 https://serpapi.com/searches/<id>.json: Search not found.
std.debug.print("{t}: HTTP {?d} {?s}: {s}\n", .{
err, if (info.status) |s| @intFromEnum(s) else null, info.url, info.message,
});
Expand Down Expand Up @@ -484,7 +493,7 @@ zig build cov
open zig-out/coverage/merged/kcov-merged/index.html
```

Current state: **94.01% of lines covered** (596 of 634) without an API key,
Current state: **95.07% of lines covered** (867 of 912) without an API key,
since the tests covering `html`, `md`, `searchArchive`, and `account` skip
themselves rather than fail. With `SERPAPI_KEY` set — as in CI, which
publishes the figure to every job summary and fails below 90% — those paths
Expand All @@ -503,6 +512,32 @@ generates code for a generic (`anytype`) function that no test instantiates
as uncovered. `zig build cov` therefore measures the unit and integration
binaries and merges the two reports.

## Changelog

Full details in [CHANGELOG.md](CHANGELOG.md).

- [2026-11-30] 1.2.0 Image API, error details, User-Agent usage reporting and a safer client dump
- Added `uploadImage()` and `uploadImageBytes()` (and typed `uploadImageAs()` / `uploadImageBytesAs()`) for the [Image API](https://serpapi.com/image-api), returning the `image_id` to use with engines such as `google_lens`. The `api_key` goes in the form body, never in the URL, and images over 500 KiB fail fast with `error.ImageTooLarge`
- Added `lastError()`, returning a `serpapi.ErrorInfo` with the message, HTTP status, request URL (without the `api_key`) and `search_id` of the last failure
- Printing a client with `{f}` masks the API key (`abcd****wxyz`)
- `errorMessage()` and `lastError()` describe the most recent request only: a success or a transport error clears the previous failure
- **Breaking:** the API key moved out of `Client.params` (use `apiKey()`), `Client.last_error` is now `?serpapi.ErrorInfo`, and `serpapi.Error` gains `ImageTooLarge`. Pin `v1.1.0` to keep the old API
- `rake release` runs lint, tests, integration tests and oobt, and only from a clean `master`
- Every request identifies the library, the Zig version and the platform in its `User-Agent` header (`serpapi.user_agent`, e.g. `serpapi-zig/1.2.0 zig/0.16.0 (macos; aarch64)`) instead of the `source` query parameter, as serpapi-ruby does
- A `source` passed to the constructor is sent once, as given; it was previously sent alongside the library's own
- [2026-09-23] 1.1.0 Markdown output, timeouts and connection reuse
- Added `md()` and `searchArchiveMd()` for `output=md` results optimized for LLMs and AI agents
- `serpapi.Error` is exported from the module root, and `serpapi.version` comes from `build.zig.zon`
- Fixed persistent connections, which were never actually reused (3-4x faster for repeated searches)
- Fixed the `timeout` option, which was never applied; a stalled request now returns `error.Timeout`
- One error rule for every decoder: an `{"error": ...}` payload is `SerpApiError` whatever the HTTP status
- Fixed a double free in `html()` on non-200 responses, and Search Archive ids are percent-encoded
- Added the browser wasm demo and the flight tracker demo
- [2026-08-13] 1.0.0 Initial release, ported from [serpapi-ruby](https://github.com/serpapi/serpapi-ruby)
- `search()`, `html()`, `location()`, `searchArchive()`, `searchArchiveHtml()` and `account()`
- Persistent HTTP connections on by default
- Zero dependency: Zig standard library only

## License

MIT License — see [LICENSE](LICENSE).
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void {
});

// The library version reported to serpapi.com comes straight from the
// package manifest, so `rake release` and the `source` parameter agree.
// package manifest, so `rake release` and the User-Agent agree.
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", manifest.version);
mod.addOptions("build_options", build_options);
Expand Down
Loading
Loading