Constructs an AIBinding instance.
Optionalsettings: AISettings
Resolved settings. Defaults to resolve('ai'), so callers
normally construct this with no arguments at all.
Private Optional ReadonlygatewayAI Gateway id used to route inference, when configured.
Private ReadonlymodelModel used when a call does not name one.
Private ReadonlysettingsThis accessor’s settings, resolved on first read.
The binding name this instance resolves.
The binding name as declared in wrangler.json.
Returns an AI Gateway handle for lower-level gateway operations.
The Worker environment.
OptionalgatewayId: string
Gateway id. Falls back to the configured gateway.
The AI Gateway instance.
Checks whether the binding is available on the given environment.
Use this to degrade gracefully when a binding is optional.
The Worker environment.
true when the binding is present.
Returns the AI Gateway log id of the most recent inference call.
Useful for correlating a response with its gateway log entry.
The Worker environment.
The log id, or null when the last call was not routed through a gateway.
Resolves the binding, failing fast when it is not configured.
The Worker environment.
The resolved binding.
MissingBindingError When the binding is absent from the environment.
Runs an inference request against a Workers AI model.
The Worker environment.
Model inputs, shaped by the model being called.
Optionalmodel: string
Model to run. Falls back to the configured model.
The model output.
MissingBindingError When the AI binding is absent.
Resolves the binding without throwing.
The Worker environment.
The resolved binding, or null when it is not configured.
Accessor for the Workers AI binding (
aiinwrangler.json).Which model it runs, which gateway it routes through, and which binding it reads are all decided by the configuration layer — this class receives the settled values and has no idea whether they came from the defaults or from
config/AIConfig.ts.Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.0.0