Skip to main content
Short, self-contained recipes using @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 until next_cursor is null.
paginate-logs.ts
See Pagination for query parameters and cursor semantics.

Make a write idempotent

Pass an idempotencyKey as the second-argument options object so retrying the same call after a network failure does not duplicate the operation.
idempotent-patch.ts
See Idempotency for key format and caching window.

Handle a rate limit

Catch GavaiError 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

Next steps