---
title: API reference
description: Every public export of @rebilder/gateway (root + /next, /shopify, /node, /edge, /fetch subpaths), and @rebilder/events, with signatures.
canonical_url: https://rebilder.com/docs/reference
last_updated: "2026-12-03"
---

# [API reference](https://rebilder.com/docs/reference)

> Every public export of `@rebilder/gateway` (root + `/next`, `/shopify`, `/node`, `/edge`, `/fetch` subpaths), and `@rebilder/events`, with signatures.

This site answers questions directly. Ask at https://rebilder.com/ask?q=your+question instead of reading more pages.

- **Updated:** 2026-12-03
- **Author:** Rebilder
- **Section:** Reference
- **Description:** Every public export of @rebilder/gateway (root + /next, /shopify, /node, /edge, /fetch subpaths), and @rebilder/events, with signatures.
- **Publisher:** Rebilder

## Rebilder at a glance

AEO gets you seen. Rebilder gets you heard. When customers ask ChatGPT about your business, your site answers with your real prices and policies.

**Common questions**

- **What does it cost?** Connecting is free. Starter is $49/mo, Pro is $99/mo and Agency is $299/mo. [Pricing](https://rebilder.com/pricing)
- **How does my site answer new questions live?** Rebilder reads your pages, products and policies. When an AI assistant asks, your site answers from them. Nothing on your site changes. [See how it works](https://rebilder.com/autopilot)
- **Can someone trick my site into a wrong price or a discount?** No. Every answer comes from your own pages and is checked against them. If your site does not say it, Rebilder does not say it. [Read security details](https://rebilder.com/security)

**How it compares**

- **Why choose Rebilder?** Choose Rebilder when you want your own site to answer AI assistants with your real facts, and to see who asked. [Compare](https://rebilder.com/compare)

| Compared with | The difference |
| --- | --- |
| Profound, Peec AI, Otterly.ai | These tools watch AI answers and tell you where you show up. Rebilder makes your own site answer when AI comes to check. |
| Cloudflare Markdown for Agents, @vercel/agent-readability, Yoast llms.txt | These tools tidy or map your pages for AI. Rebilder answers from those pages and shows you who asked. |
| Intercom Fin, Tidio Lyro | Chatbots answer the customers who contact you. Rebilder answers the AI assistants that visit your site for them. |
| SEO on its own, Shopify agentic storefronts, Writing an llms.txt yourself | Good SEO, your store platform and a simple llms.txt all help. Here is what Rebilder adds to each. |

Source: [Compare](https://rebilder.com/compare)

## @rebilder/gateway

The framework-agnostic core, over web-standard `Request`/`Response`. Public API from the root export only; adapters are the subpath exports below.

| Export | Signature | Notes |
| --- | --- | --- |
| `classifyRequest` | `(req: Request) => GatewayDecision` | Pure compute, <1ms, no I/O. Returns `{ path, detection }`: the serving path plus the full detection result. |
| `handleRequest` | `(req: Request, config: GatewayConfig, runtime?: GatewayRuntime) => Promise<Response \| null>` | `Response` = markdown served (`text/markdown; charset=utf-8`, `Vary: Accept`, `X-Rebilder-Path: markdown`), including a `.md` URL with `markdownUrls`, or a markdown 404 (`X-Rebilder-Path: not-found`) with `notFound`; `null` = serve your normal HTML. Adapters pass `runtime` so the gateway can read your own pages for [automatic pages](/docs/pages); call it with two arguments yourself. |
| `generateLlmsTxt` | `(config: GatewayConfig, options: LlmsTxtOptions) => Promise<string>` | Deterministic llms.txt; see [llms.txt](/docs/llms-txt). |
| `GatewayConfig` | `{ storeId: string; sources?: GatewaySources; pages?: boolean \| GatewayPages; onEvent?: (event: RebilderEventV0) => void \| Promise<void>; maxBytes?: number; maxBytesBySource?: Partial<Record<SourceKind, number>>; sourceTimeoutMs?: number; protocols?: (req: Request) => Promise<Response \| null>; verification?: GatewayVerification; access?: AccessPolicySource; compatibilityProfile?: CompatibilityProfile \| (() => CompatibilityProfile); markdownUrls?: boolean; frontmatter?: boolean; notFound?: GatewayNotFound; opening?: GatewayOpening \| ((page: URL) => GatewayOpening \| undefined) }` | The one config object, shared by every adapter. `pages` gives every page a markdown copy made from the page your site serves, and is off by default ([Automatic pages](/docs/pages)). `sources` is optional and wins for the pages it answers ([Sources](/docs/sources)). `protocols` is an optional hook for protocol routes, `verification` the Web Bot Auth registry ([Verification](/docs/classification#verification)), `access` the agent access policy ([Access control](/docs/access-control)), and `compatibilityProfile` the synchronous presentation profile ([SDK presentation updates](/docs/sdk-updates)). `markdownUrls`, `frontmatter` and `notFound` are off by default ([Help agents find your markdown](/docs/discovery)). `opening` adds a short block about the whole site to every markdown copy and is unset by default ([Say the whole site in one read](/docs/opening)). |
| `GatewayNotFound` | `{ links?: Array<{ title: string; url: string; note?: string }>; isMissing?: (url: URL) => boolean }` | The markdown 404. `isMissing` is how the Next.js and Node adapters know a page does not exist; the fetch and edge adapters also use your own 404 and 410. |
| `GatewayOpening` | `{ heading: string; about?: string; groups: Array<{ heading: string; lines: Array<{ label: string; value: string; source?: string; sourceTitle?: string }>; columns?: [string, string] }>; maxBytes?: number }` | The opening block. A line is left out of the page that is its `source`, a group with `columns` is a table, and the block never exceeds 2,048 bytes. See [Say the whole site in one read](/docs/opening). |
| `GatewayPages` | `{ origin?: string; include?: (url: URL) => boolean; timeoutMs?: number; cacheSeconds?: number; maxBytes?: number; fetch?: (request: Request) => Response \| Promise<Response> }` | Options for `pages`. `origin` is your site address, `include` chooses which pages get a copy, `cacheSeconds` (default `300`) is how long a copy is kept and `timeoutMs` (default `5000`) is how long a read may take. See [Automatic pages](/docs/pages). |
| `htmlToDocument` | `(html: string, pageUrl: string \| URL) => { document: DocumentSource; noindex: boolean } \| null` | The document a page’s HTML becomes, the same one `pages` renders its copy from. `null` when the HTML has too little text to be a page. Use it to preview a copy or to test your templates. |
| `renderOpening` | `(opening: GatewayOpening, page: URL) => string \| undefined` | The markdown an opening block adds to the copy of `page`, or `undefined` when it adds nothing. Use it to preview a block before you ship it. |
| `OPENING_MAX_BYTES` | `2048` | The ceiling on an opening block, in UTF-8 bytes. `maxBytes` can lower it and cannot raise it. |
| `markdownAlternate` | `(config: GatewayConfig, url: string \| URL) => { rel: 'alternate'; type: 'text/markdown'; href: string } \| null` | The `<link>` for your page head. `null` unless the `match` router confirms a source. |
| `generateSitemapMd` | `(config: GatewayConfig, options: SitemapMdOptions) => Promise<string>` | Deterministic `/sitemap.md`: sections from your sources, then yours. |
| `SitemapMdOptions` | `{ baseUrl: string; title?: string; description?: string; sections?: LlmsTxtSection[] }` | `title` defaults to `Sitemap`. |
| `markdownNotFoundResponse` | `(options: GatewayNotFound, requestUrl: URL, status?: 404 \| 410) => Response` | The markdown 404 on its own, for a route of yours that knows a page is missing. |
| `GatewayVerification` | `{ keys: AgentKeyRegistry; require?: 'protocol' }` | Key registry for Web Bot Auth verification on the protocol path. Populate it with the agent keys you trust. |
| `verifyWebBotAuth` | `(input, options: { keys: AgentKeyRegistry; now?: Date }) => Promise<VerificationResult>` | Re-exported from detection: pure Ed25519 (RFC 9421) over injected keys, with no network, and it never throws. |
| `KNOWN_AGENT_DIRECTORY` | `AgentKeyRegistry` | The built-in registry. Add trusted keys before enabling verification. |
| `AGENT_VERIFIED_HEADER` / `AGENT_VERIFIED_REASON_HEADER` | `'x-rebilder-agent-verified'` / `'x-rebilder-agent-verified-reason'` | The verdict headers the gateway stamps for the protocols hook (client-sent values always overwritten). |
| `GatewaySources` | `{ product?; policies?; catalog?; document?; collection?; match? }` | Each a `SourceResolver`; see [Sources](/docs/sources). |
| `SourceResolver<T>` | `(url: URL) => T \| null \| undefined \| Promise<T \| null \| undefined>` | Sync or async; no slow I/O on the hot path. |
| `GatewayPath` | `'markdown' \| 'protocol' \| 'html'` | The serving-path union. |
| `GatewayDecision` | `{ path: GatewayPath; detection: DetectionResult }` | What `classifyRequest` returns. |
| `LlmsTxtOptions` / `LlmsTxtSection` / `LlmsTxtLink` | `{ baseUrl; siteName; description; sections? }` / `{ title; links }` / `{ title; url; note? }` | llms.txt inputs. |
| `acceptsMarkdownHeader` | `(accept: string \| null \| undefined) => boolean` | Re-exported Accept header predicate used by request classification. |
| `compileAccessPolicy` / `createAccessLimiter` / `createAccessRuntime` / `evaluateAccess` / `accessDeniedResponse` | access-control helpers | Compile, validate, rate-limit, evaluate, and render `403`/`429` responses for agent access policies; see [Access control](/docs/access-control). |
| `inspectGatewayConfig` / `inspectGatewayResponse` | `(config: GatewayConfig) => GatewayConfigReport` / `(response: Response \| null) => GatewayDiagnostic[]` | Local, offline wiring checks with no network calls or source-data exposure; see [Troubleshooting](/docs/troubleshooting). |
| `BASELINE_PROFILE` / `COMPATIBILITY_RUNTIME_VERSION` / `validateCompatibilityProfile` / `applyCompatibilityProfile` | compatibility profile runtime | Baseline presentation profile, runtime version constant, validation, and synchronous profile application. |
| `createCompatibilityUpdater` / `canonicalCompatibilityManifest` / `validateCompatibilityManifest` / `verifyCompatibilityManifest` | signed profile updater | Background signed manifest polling, Ed25519 verification, durable cache restore, and local rollback; see [SDK presentation updates](/docs/sdk-updates). |
| `runCompatibilityEvaluation` / `promotableProfilesFromReport` / `COMPATIBILITY_EVALUATOR_VERSION` | compatibility evaluation helpers | Offline evaluation runner and promotion filter for candidate presentation profiles. |

**Re-exported dependency types** (so you only install `@rebilder/gateway`): `ProductSource`, `ProductVariantSource`, `ShippingSource`, `ReturnsSource`, `PolicySource`, `CatalogItemSource`, `DocumentSource`, `CollectionSource`, `Money`, `Availability`, `CompatibilityProfile`, `CompatibilityRendering` (from the renderer), `AccessAction`, `AccessDecision`, `AccessLimit`, `AccessLimiter`, `AccessPolicy`, `AccessPolicySource`, `AccessRule`, `AccessSubject`, `CompiledAccessPolicy`, `GatewayConfigReport`, `GatewayDiagnostic`, `CompatibilityManifest`, `SignedCompatibilityManifest`, `CompatibilityUpdateOptions`, `CompatibilityUpdateStatus`, `CompatibilityEvaluationCase`, `CompatibilityModelAnswer`, `CompatibilityModelAdapter`, `CompatibilityEvaluationResult`, `CompatibilityEvaluationReport` (from the gateway core), `DetectionResult`, `RequesterKind`, `AgentPlatform`, `AgentKeyRegistry`, `AgentKeyRegistryEntry`, `AgentPublicKey`, `Ed25519PublicJwk`, `VerificationResult`, `VerificationFailureReason` (from detection), and `RebilderEventV0` (from events).

## @rebilder/gateway/next

| Export | Signature | Notes |
| --- | --- | --- |
| `createGatewayProxy` | `(config: GatewayConfig, fallthrough: (req: Request) => Response \| Promise<Response>) => (req: Request) => Promise<Response>` (also 1-arg `(config: GatewayConfig) => (req: Request) => Promise<Response \| null>`) | The Next.js middleware/proxy entry point. Passing `fallthrough` (recommended) returns a `Response` for every request and adds `Vary: Accept` plus `Link: rel="alternate"` to HTML responses; the 1-arg form returns `null` on pass-through so you own negotiation headers. |
| `withNegotiationHeaders` | `(response: Response, config: GatewayConfig, url: URL) => Response` | Appends `Vary: Accept` and (when `sources.match` confirms a source) `Link: rel="alternate"` to a pass-through response; used with the 1-arg `createGatewayProxy` form. |
| `createGatewayRouteHandler` | `(config: GatewayConfig, options?: GatewayRouteHandlerOptions) => (req: Request) => Promise<Response>` | Always-markdown GET route. Source match returns 200 markdown and emits a `sourced` event; no match returns 404 `{ "error": "not_found" }` and emits an `unsourced` event. |
| `GatewayRouteHandlerOptions` | `{ stripPrefix?: string }` | Prefix stripped (whole path segments only) before consulting sources. Default: strip nothing. |
| `createLlmsTxtRouteHandler` | `(config: GatewayConfig, options: LlmsTxtOptions) => (req: Request) => Promise<Response>` | `text/plain; charset=utf-8` with `public, max-age=300, s-maxage=3600, stale-while-revalidate=86400`. |
| `createSitemapMdRouteHandler` | `(config: GatewayConfig, options: SitemapMdOptions) => (req: Request) => Promise<Response>` | `/sitemap.md` as `text/markdown; charset=utf-8`, with the same cache headers as llms.txt. |
| `markdownAlternateTypes` | `(config: GatewayConfig, url: string \| URL) => { 'text/markdown': string } \| undefined` | For `alternates.types` in Next.js metadata. |

## @rebilder/gateway/shopify

| Export | Signature | Notes |
| --- | --- | --- |
| `createShopifyAppProxyHandler` | `(config: GatewayConfig, options: ShopifyAppProxyOptions) => (req: Request) => Promise<Response>` | Signature-verified app-proxy endpoint; see [Shopify adapter](/docs/adapters/shopify) for the 401/404 semantics. |
| `ShopifyAppProxyOptions` | `{ sharedSecret: string; pathPrefix?: string; fallback?: (url: URL, req: Request) => Response \| null \| Promise<Response \| null> }` | `pathPrefix` default `'/apps/rebilder'`; strip is a no-op if the path arrives canonical. `fallback` answers a verified request the gateway did not; `null` keeps the 404. |
| `verifyAppProxySignature` | `(url: URL, sharedSecret: string) => Promise<boolean>` | The HMAC check alone, exported for reuse. Web Crypto, constant-time comparison. |

## @rebilder/gateway/node

| Export | Signature | Notes |
| --- | --- | --- |
| `createGatewayMiddleware` | `(config: GatewayConfig) => NodeGatewayMiddleware` | Connect-style `(req, res, next) => void` for Express/Fastify; see [Node adapter](/docs/adapters/node). |
| `toWebRequest` | `(nodeReq: NodeRequestLike, options?: ToWebRequestOptions) => Request` | Builds the web-standard Request the middleware uses; exported for custom servers. |
| `NodeRequestLike` / `NodeResponseLike` | structural interfaces | Only what the adapter reads/writes; any real Node req/res satisfies them. |
| `NodeGatewayMiddleware` / `NodeNextFunction` | `(req, res, next) => void` / `() => void` | The middleware and continuation shapes. |
| `ToWebRequestOptions` | `{ fallbackHost?: string }` | Host used when no Host header is present. Default `'localhost'`. |

## @rebilder/gateway/edge

| Export | Signature | Notes |
| --- | --- | --- |
| `createGatewayFetchHandler` | `(config: GatewayConfig, options?: GatewayFetchHandlerOptions) => (req: Request) => Promise<Response>` | A complete fetch handler; see [Cloudflare & edge](/docs/adapters/cloudflare). With `notFound`, the origin’s 404 or 410 to a markdown request becomes the markdown 404. |
| `GatewayFetchHandlerOptions` | `{ fallback?: (req: Request) => Response \| Promise<Response> }` | Serves every non-markdown request. Default: `fetch(req)`, the origin pass-through. |

## @rebilder/gateway/fetch

| Export | Signature | Notes |
| --- | --- | --- |
| `createFetchMiddleware` | `(config: GatewayConfig) => FetchMiddleware` | Framework-neutral middleware; see [Frameworks](/docs/adapters/frameworks). |
| `FetchMiddleware` / `FetchNext` | `(request: Request, next: FetchNext) => Promise<Response>` / `() => Response \| Promise<Response>` | Markdown short-circuits without calling `next`; everything else returns `next()`’s response with the negotiation headers added. With `notFound`, your 404 or 410 to a markdown request becomes the markdown 404. |
| `negotiationHeaders` | `(config: GatewayConfig, url: URL) => Array<[string, string]>` | The headers to append to a pass-through response, for hosts that cannot wrap it (Nitro, Vercel Routing Middleware). |
| `withNegotiationHeaders` | `(response: Response, config: GatewayConfig, url: URL) => Response` | A copy of `response` with the negotiation headers; safe on immutable `fetch()` responses. |
| `handleRequest` | `(req: Request, config: GatewayConfig) => Promise<Response \| null>` | Re-exported from the root for recipes that need the core call directly. |

## @rebilder/events

The observation-layer contract: the frozen v0 schema, structural runtime validation, and the emission sinks. Zero runtime dependencies; edge-safe (web-standard `fetch`/`setTimeout` only).

| Export | Signature | Notes |
| --- | --- | --- |
| `EVENTS_SCHEMA_VERSION` | `'v0'` | The current schema version constant. |
| `validateEventV0` | `(value: unknown) => value is RebilderEventV0` | Boolean type guard; never throws. Unknown extra keys are allowed at every level (additive schema). |
| `assertEventV0` | `(value: unknown) => asserts value is RebilderEventV0` | Throws a descriptive `Error` naming the first offending field. |
| `createHttpEventSink` | `(options: HttpEventSinkOptions) => EventSink` | The batching HTTP emission client; see [Events](/docs/events). |
| `createConsoleEventSink` | `() => EventSink` | One `[rebilder-event] {json}` line per event via `console.info`. |
| `EventSink` | `{ emit(event): void; flush(): Promise<void>; close(): Promise<void> }` | `emit` never throws; `flush`/`close` never reject. |
| `HttpEventSinkOptions` | `{ url; apiKey; maxBatch?; flushIntervalMs?; fetchImpl?; onError? }` | Full option table on the [Events](/docs/events) page. |
| `RebilderEventV0` (+ subtypes) | `RebilderEventRequesterV0`, `RebilderEventRequestV0`, `RebilderEventResponseV0`, `RebilderEventOutcomeV0`, `RequesterKindV0`, `RequesterPlatformV0`, `ResponsePathV0` | The frozen v0 type contract, with a field-by-field reference on the [Events](/docs/events) page. |
| `EVENTS_PACKAGE_STATUS` | `string` | Human-readable phase/status constant. |