earendil-works/pi · error

createGatewayBindingFetch: cannot express

Error message

createGatewayBindingFetch: cannot express ${method} ${url} as a universal gateway request (${reason}); route it over HTTPS with gateway auth instead

What it means

For URLs inside the gateway prefix that the universal gateway endpoint cannot express (per the computed reason), the wrapper throws instead of degrading. The caller must route the request over normal HTTPS with gateway auth headers; there is no safe automatic rewrite.

Solutions

  1. Route the request over HTTPS with gateway auth instead of the binding fetch.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/ai/src/api/cloudflare-gateway-binding.ts:111 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/4bd77d0270de191e. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/api/cloudflare-gateway-binding.ts:111

			parsed = new URL(url);
		} catch {
			parsed = undefined;
		}
		// Out-of-prefix URLs are a configuration bug, not passthrough traffic: silently
		// forwarding would ship the auth sentinel to whatever host the URL names.
		if (parsed === undefined || parsed.origin !== base.origin || !parsed.pathname.startsWith(basePath)) {
			throw new Error(
				`createGatewayBindingFetch: ${method} ${url} is outside the configured gateway ` +
					`prefix (${base.origin}${basePath}); this fetch only serves its gateway-bound client`,
			);
		}

		// In-prefix requests the universal endpoint cannot express always reject: forwarding
		// them over HTTPS would send the sentinel to the gateway and fail with a misleading
		// auth error instead of naming the real problem. Callers that need such endpoints
		// route them over HTTPS with real gateway auth themselves.
		const unexpressible = (reason: string): never => {
			throw new Error(
				`createGatewayBindingFetch: cannot express ${method} ${url} as a universal ` +
					`gateway request (${reason}); route it over HTTPS with gateway auth instead`,
			);
		};
		if (method !== "POST") return unexpressible("only POST is supported");

		const rest = parsed.pathname.slice(basePath.length);
		const slash = rest.indexOf("/");
		if (slash <= 0) {
			return unexpressible("missing provider/endpoint path");
		}
		const provider = rest.slice(0, slash);
		// Keep the query string on the endpoint — it's part of what HTTPS would have sent.
		const endpoint = rest.slice(slash + 1) + parsed.search;

		const bodyText = await readBodyText(request, init);
		let query: unknown;
		try {

View on GitHub (pinned to 4af9d21d3b)