@gavai/sdk. Each example is a working snippet you can drop into a file and run with bun run. By the end of this page you will have seen every common pattern at least once — read calls, paginated lists, idempotent writes, rate-limit retries, and custom fetch injection.
Fetch the current user
me.ts
Patch a page and publish
Fetch the current page, build an RFC 6902 JSON Patch operation array, apply it, then publish to live.patch-page.ts
Iterate a paginated list
Log resources use cursor-based pagination. Keep fetching untilnext_cursor is null.
paginate-logs.ts
Make a write idempotent
Pass anidempotencyKey as the second-argument options object so retrying the same call after a network failure does not duplicate the operation.
idempotent-patch.ts
Handle a rate limit
CatchGavaiError with code === "rate_limited", wait for the duration the server signals via Retry-After, then retry once. Wrap in a bounded loop for production.
rate-limit.ts
Inject a custom fetch
Swap in a custom fetch implementation — useful for tests against a mock server or for environments that require proxy configuration.custom-fetch.ts