How to pass your own fetch to the SDK (deps.fetch)
Pass deps: { fetch: yourFetch } to createKernelClient or createVerifyClient. The SDK uses it for every request. Without it, the SDK uses the fetch built into Node.js 18.
Last updated
Steps
Pass it in
const client = createKernelClient({ deps: { fetch: myFetch }, });Use it to simulate API errors in tests
const errorFetch = async () => ({ ok: false, status: 429, json: async () => ({ error: 'Rate limit exceeded' }), }); // errorFetch answers locally, so this key is never sent anywhere. const client = createKernelClient({ hosted: { apiKey: 'not-sent' }, deps: { fetch: errorFetch } });
When you need it
- Tests that should not call the network but need a hosted-shaped error.
- A proxy or logging wrapper around
fetch. - Older runtimes with no global
fetch.