"<accountId>:<apiToken>", the API token alone (the account ID then comes from
CLOUDFLARE_ACCOUNT_ID), or an AI Credential's values in JSON.
OptionalbaseURL: stringOverrides the base URL, the credential's endpoint and CLOUDFLARE_WORKERS_AI_BASE_URL; see the class notes.
Static ReadonlyACCOUNT_The environment variable the account ID is read from when the API key does not carry one.
Static ReadonlyBASE_The environment variable that overrides the base URL, for an AI Gateway.
Static ReadonlyDEFAULT_The Workers AI base URL the model is appended to, with the account ID placeholder.
Static ReadonlyDEFAULT_The model used when DecisionParams.Model is empty.
The Cloudflare account ID, from the credential, the API key or CLOUDFLARE_ACCOUNT_ID; undefined when none has one.
ProtectedapiOnly sub-classes can access the API key
The base URL the model is appended to, before the account ID is filled in.
ProtectedCredentialThe credential, read from the API key with ParseSystemOneCredential.
ProtectedDefaultThe model used when DecisionParams.Model is empty.
ProtectedSecretsThe whole key and the token alone, since the token is what an error body would echo.
ProtectedServiceThe API's name in error messages, such as 'OpenRouter Decisions API'.
ProtectedBuildThe request body: { model, state, questions }.
Executes a typed decision request across one or more questions about a given state. This method wraps driver execution with input validation, output verification, execution timing, and structured error handling. It never throws.
Decision request parameters including state, questions, and model.
A Promise resolving to a DecisionResult.
ProtectedDescribeNames the envelope's errors[].message when the body has them, otherwise the start of the body.
ProtectedDoSends the questions and maps the typed answers.
ProtectedFailMarks the result failed because the response could not be mapped. Another model may still answer, so the failure allows failover (and is not 'Fatal', which would stop the failover loop).
ProtectedGetA credential without a token, or without an account ID when the URL needs one, stops the call
before any request, with a message that names how to supply it. It is a NoCredentials error
that allows failover: another candidate may be configured, and the type does not exclude the
vendor's other models, whose rows may have their own credentials bound.
ProtectedGetThe base URL with the account ID filled in, then the model's APIName.
ProtectedGetThe error type for a non-2xx status whose ErrorAnalyzer reading is wrong for this API, or
undefined (the default) to leave it to ErrorAnalyzer, which reads the message and the status. A
type returned here is attached to the thrown error as a Retriable error that allows failover:
another candidate may answer what this API refused.
The HTTP status.
ProtectedGetThe API token, without the account ID the key may carry, as a bearer token.
ProtectedGetWorkers AI's model selector is the APIName's last segment: clef for @cf/cloudflare/clef.
ProtectedResolveThe model to ask: DecisionParams.Model trimmed, or DefaultModel when it is empty.
ProtectedSendSends the request. This is the driver's only network call; a test double overrides it to stand in for the network.
The endpoint from GetEndpointURL.
The POST: method, headers, JSON body and the caller's cancellation signal.
ProtectedUnwrapCloudflare's v4 API wraps the response as { result, success, errors, messages }; a Worker or a
gateway may return it bare. A wrapped response that reports success: false is an error.
ProtectedValidateValidates driver output DecisionResult against the requested questions.
Original decision request parameters.
Result returned by the driver.
An array of error descriptions, empty if valid.
ProtectedValidateValidates input DecisionParams against the decision contract.
Parameters to validate.
An array of error descriptions, empty if valid.
A
BaseDecisiondriver for Cloudflare's Clef decision models (@cf/cloudflare/clefand@cf/cloudflare/clef-flash) on Workers AI. They speak the System One decisions format (the one TypeSafe's Jev speaks), so the wire mapping comes from BaseSystemOneDecision; this class supplies the Workers AI endpoint, the account ID and the token, and unwraps Cloudflare's v4 response envelope.Credentials. Workers AI needs an account ID in the URL and an API token. The API key is either
"<accountId>:<apiToken>", or the token alone with the account ID in theCLOUDFLARE_ACCOUNT_IDenvironment variable. A key that names an account wins over the variable. An AI Credential's values arrive as JSON: itsapiKeyis read the same way, and anaccountIdfield wins over both.Endpoint.
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run, followed by the model. To go through an AI Gateway instead, setCLOUDFLARE_WORKERS_AI_BASE_URL, give the credential anendpoint, or pass a base URL to the constructor (the constructor wins, then the credential, then the variable): the URL the model is appended to, such ashttps://gateway.ai.cloudflare.com/v1/{account_id}/my-gateway/workers-ai.{account_id}is replaced with the account ID; a base URL without it needs none.Model.
DecisionParams.Modelis the model-vendor row'sAPIName(@cf/cloudflare/clef), which is the URL's last part; the body'smodelfield is its last segment (clef).