Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

CloudflareClient unstable

HTTP client for Cloudflare Clef decisions through Workers AI REST.

6 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Builds a Cloudflare client without automatic retries.

Signature

declare const make: (...args: [options: Options]) => Effect<Service, never, HttpClient>

Layers

layer

unstable
Since v4.0.0

Provides a Cloudflare client from explicit options.

Signature

declare function layer(options: Options): Layer<CloudflareClient, never, HttpClient>

layerConfig

unstable
Since v4.0.0

Provides a client from configuration. It reads CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN, and the optional CLOUDFLARE_AI_GATEWAY_ID by default.

Signature

declare function layerConfig(options?: {
readonly accountId?: Config<string>;
readonly apiKey?: Config<Redacted<string>>;
readonly apiUrl?: Config<string>;
readonly gatewayId?: Config<string>;
readonly transformClient?: (client: HttpClient) => HttpClient;
}): Layer<CloudflareClient, ConfigError, HttpClient>

Options

Options

interface unstable
Since v4.0.0

Account, authentication, AI Gateway, API base URL, and HTTP customization options.

Signature

interface Options {
readonly accountId: string;
readonly apiKey: Redacted<string>;
readonly apiUrl?: string;
readonly gatewayId?: string;
readonly transformClient?: (client: HttpClient) => HttpClient;
}

Services

Since v4.0.0

Cloudflare Workers AI client service.

Signature

declare class CloudflareClient extends Shape<"@effect/ai-cloudflare/CloudflareClient", Service, this> {
constructor(_: never);
}

Service

interface unstable
Since v4.0.0

Low-level Cloudflare decision operations.

Signature

interface Service {
readonly client: HttpClient;
readonly createDecisions: (request: {
readonly images?: readonly Array<string | {
readonly base64: string;
readonly content_type: string & {} | "image/png" | "image/jpeg" | "image/webp";
}>;
readonly model: "clef" | "clef-flash" | string & {};
readonly questions: {
[key: string]: {
readonly criteria: {
[key: string]: string | {
[key: string]: Json;
} | readonly Array<Json> | null;
};
readonly instructions: string | {
[key: string]: Json;
} | readonly Array<Json>;
readonly type: "choice";
} | {
readonly criteria: readonly Array<Json>;
readonly instructions: string | {
[key: string]: Json;
} | readonly Array<Json>;
readonly type: "score";
} | {
readonly criteria?: {
readonly false: Json;
readonly true: Json;
};
readonly instructions: string | {
[key: string]: Json;
} | readonly Array<Json>;
readonly type: "noul";
};
};
readonly state: Json;
}) => Effect<{
readonly answers: {
[key: string]: {
readonly choice: string;
readonly confidence: number;
readonly probabilities: {
[key: string]: number;
};
readonly type: "choice";
} | {
readonly confidence: number;
readonly legend: {
[key: string]: Json;
};
readonly probabilities: {
[key: string]: number;
};
readonly score: number;
readonly type: "score";
} | {
readonly noul: number;
readonly type: "noul";
};
};
readonly model: string;
readonly usage: {
readonly input_tokens: number;
readonly output_tokens: number;
};
}, AiError>;
}