CloudflareModelFactory

@ApiStatus.Experimental
open class CloudflareModelFactory constructor(accountId: String, apiKey: Supplier<String?>, restClientBuilder: <Error class: unknown class>? = null, observationRegistry: <Error class: unknown class> = ObservationRegistry.NOOP, val defaultModel: String = CLEF, maxResponseBytes: Int = SystemOneEndpoint.DEFAULT_MAX_RESPONSE_BYTES) : SystemOneModelFactory

Builds decision services for the decision models on Cloudflare Workers AI: the CLEF models Cloudflare hosts, and Jev, which it runs as a third-party model. Workers AI serves System One behind its own REST API, so this is a SystemOneModelFactory with Cloudflare's address for the account, its envelope and its limits.

Cloudflare always needs an API key, which is a Cloudflare API token. A missing key fails each call as unavailable before anything is sent, and buildValidated rejects it. Building a service never reads the key.

Parameters

accountId

the Cloudflare account that runs the models, 32 hexadecimal characters

apiKey

supplies the API key (a Cloudflare API token) with Workers AI access for each call

restClientBuilder

the application's HTTP client builder, or null for the factory's own

observationRegistry

records decision and request observations

defaultModel

the model build and buildValidated return

maxResponseBytes

the largest response body that is read

Constructors

Link copied to clipboard
constructor(accountId: String, apiKey: Supplier<String?>, restClientBuilder: <Error class: unknown class>? = null, observationRegistry: <Error class: unknown class> = ObservationRegistry.NOOP, defaultModel: String = CLEF, maxResponseBytes: Int = SystemOneEndpoint.DEFAULT_MAX_RESPONSE_BYTES)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard

Returns a service for the default model.

Returns a service for the named model. The endpoint's binding checks the name first, and the endpoint decides whether a model it accepts exists.

Link copied to clipboard

Reads the key once, checks it by listing the endpoint's models with it, then returns a service for the default model. A missing key, a rejected listing or an unreachable endpoint all count as an invalid key. A key supplier that throws InvalidApiKeyException itself, as one that insists on a key does for a blank one, counts as a missing key. An already interrupted caller is cancelled before the key is read, including when no key is configured. An interrupted key supplier also throws a CancellationException.

Link copied to clipboard

Lists the models the endpoint serves.

Link copied to clipboard
open override fun toString(): String