Skip to content

ServerClientOptions

ServerClientOptions<S> = object

Options for createServerClient. S is one site’s schema, indexed out of the types edgekit types pull generates: createServerClient<EdgeKitDecisions['site_example']>({ siteId: 'site_example', … }).

Pass the site, not all of EdgeKitDecisions. TypeScript has no partial type-argument inference, so createServerClient<EdgeKitDecisions>(…) drops the 'site_example' literal and leaves only the feature names every site shares, which is often none. With the site as the type argument, siteId: S['id'] makes calling a feature on a site that does not run it a compile error.

S extends SiteSchema

apiKey: string

A site-pinned tenant API key from the console. Keep it on your server.


baseUrl: string

Your tenant host, as an absolute URL, e.g. https://edgekit.example.com. Required: there is no default, and the client does not discover it.


optional collectorFetch?: typeof fetch

Sends the request that records experiment exposures, to /edgekit/a/t on baseUrl, instead of fetch. Pass it whenever fetch is a service binding to the decide Worker, which does not reach the collector: bind the collector Worker too, as collectorFetch: (input, init) => env.EDGEKIT_COLLECTOR.fetch(input, init). Without it there, no exposure is recorded.


optional fetch?: typeof fetch

Sends the request instead of the global fetch. Needed in a Cloudflare Worker on the same zone as your tenant host, where a global fetch to that host never reaches EdgeKit: pass a service binding to the decide Worker, as a closure so the binding keeps its this: fetch: (input, init) => env.EDGEKIT_DECIDE.fetch(input, init). baseUrl stays required and still names the tenant host. A binding skips the zone’s WAF and rate limiting rules.

The request that records experiment exposures goes through it too, unless you pass collectorFetch.


siteId: S["id"]

The site this client serves. It must be S’s id and the site the API key is pinned to; the route answers 403 on a mismatch. One client serves one site: three sites need three keys and three clients.


optional timeoutMs?: number

Request timeout in milliseconds. Defaults to 5000.

edgekit.ai