Implementation:Helicone Helicone RequestWrapper Create
| Knowledge Sources | |
|---|---|
| Domains | LLM Observability, Proxy Architecture, Request Handling |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete factory method for intercepting incoming HTTP requests in the Helicone Cloudflare Worker proxy, provided by the RequestWrapper class.
Description
RequestWrapper.create is an asynchronous static factory method that accepts a raw Cloudflare Workers Request and the worker Env, then produces a fully initialized RequestWrapper instance. The wrapper parses the URL, extracts Helicone-specific headers (via the HeliconeHeaders class), buffers the request body into a replayable IRequestBodyBuffer, resolves prompt settings, and performs authorization -- including proxy key resolution and customer portal key lookup. If authorization fails, the method returns an error result rather than throwing.
The RequestWrapper instance is the primary request abstraction used throughout the worker proxy pipeline. It is passed to routers, proxy forwarders, and logging utilities, providing a consistent interface for accessing headers, body content, authentication state, and Helicone metadata.
Usage
Use RequestWrapper.create at the entry point of every Cloudflare Worker handler to convert the raw platform Request into a structured, validated wrapper before routing or forwarding.
Code Reference
Source Location
- Repository: Helicone
- File:
worker/src/lib/RequestWrapper.ts(lines 229-256)
Signature
static async create(
request: Request,
env: Env
): Promise<Result<RequestWrapper, string>>
Import
import { RequestWrapper } from "../lib/RequestWrapper";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | Request |
Yes | The raw Cloudflare Workers Request object representing the inbound HTTP request from the client. |
| env | Env |
Yes | The Cloudflare Workers environment bindings containing configuration such as SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, VAULT_ENABLED, DATADOG_ENABLED, and queue credentials.
|
Outputs
| Name | Type | Description |
|---|---|---|
| result | Result<RequestWrapper, string> |
On success, data contains a fully initialized RequestWrapper with parsed URL, headers, body buffer, prompt settings, and resolved authorization. On failure, error contains a human-readable string describing the authorization or parsing failure.
|
Usage Examples
Basic Usage
import { RequestWrapper } from "../lib/RequestWrapper";
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const { data: requestWrapper, error } = await RequestWrapper.create(
request,
env
);
if (error !== null) {
return new Response(error, { status: 401 });
}
// Access parsed Helicone headers
const heliconeHeaders = requestWrapper.heliconeHeaders;
const userId = await requestWrapper.getUserId();
// Forward to router or proxy
// ...
},
};