Class: FallbackImageProxy
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:138
An IImageProvider that wraps an ordered chain of image providers and implements automatic failover for every operation.
Retry chain logic
Providers are tried left-to-right (index 0 first). The first provider that succeeds returns immediately. When a provider throws:
- If it is NOT the last provider: a
image:fallbackevent is emitted and the next provider is tried. - If it IS the last provider: an
AggregateErrorcontaining every collected error is thrown. - If the chain is empty: an
Error('No providers in image fallback chain')is thrown immediately.
For optional operations (edit/upscale/variate), providers that do not
implement the method or throw a *NotSupportedError are silently
skipped, since they are structurally incapable rather than transiently
failing.
Implements
Constructors
Constructor
new FallbackImageProxy(
chain,emitter):FallbackImageProxy
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:164
Creates a new FallbackImageProxy wrapping the given provider chain.
Parameters
chain
Ordered list of image providers to try. Must contain at least one entry for operations to succeed (an empty chain always throws).
emitter
EventEmitter
EventEmitter on which image:fallback events are
published so callers can observe the failover path.
Returns
FallbackImageProxy
Example
const proxy = new FallbackImageProxy(
[openaiProvider, stabilityProvider],
new EventEmitter(),
);
Properties
defaultModelId?
readonlyoptionaldefaultModelId:string
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:146
Default model from the first provider, if set.
Implementation of
isInitialized
readonlyisInitialized:boolean=true
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:143
Always true — the proxy is ready as soon as it is constructed.
Implementation of
providerId
readonlyproviderId:string
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:140
Identifier derived from the first provider in the chain.
Implementation of
Methods
editImage()
editImage(
request):Promise<ImageGenerationResult>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:218
Edit an image, falling back through providers that support editing.
Providers that do not implement editImage or that throw a
*NotSupportedError are silently skipped.
Parameters
request
The edit request forwarded to each capable provider.
Returns
Promise<ImageGenerationResult>
The result from the first provider that succeeds.
Throws
When every provider fails or does not support editing.
Implementation of
generateImage()
generateImage(
request):Promise<ImageGenerationResult>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:197
Generate an image, falling back through the provider chain on failure.
Parameters
request
The generation request forwarded to each provider.
Returns
Promise<ImageGenerationResult>
The result from the first provider that succeeds.
Throws
When every provider in the chain fails.
Throws
When the chain is empty.
Implementation of
initialize()
initialize(
_config):Promise<void>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:180
No-op initialisation — individual providers in the chain should already be initialised before being passed to the proxy.
Parameters
_config
Record<string, unknown>
Returns
Promise<void>
Implementation of
listAvailableModels()
listAvailableModels():
Promise<ImageModelInfo[]>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:294
Returns the model list from the first provider in the chain that
implements listAvailableModels. Returns an empty array when none do.
Returns
Promise<ImageModelInfo[]>
Implementation of
IImageProvider.listAvailableModels
shutdown()
shutdown():
Promise<void>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:312
Shuts down all providers in the chain. Errors are caught per-provider so a single provider's failure does not prevent the others from cleaning up.
Returns
Promise<void>
Implementation of
upscaleImage()
upscaleImage(
request):Promise<ImageGenerationResult>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:244
Upscale an image, falling back through providers that support upscaling.
Parameters
request
The upscale request forwarded to each capable provider.
Returns
Promise<ImageGenerationResult>
The result from the first provider that succeeds.
Throws
When every provider fails or does not support upscaling.
Implementation of
variateImage()
variateImage(
request):Promise<ImageGenerationResult>
Defined in: packages/agentos/src/core/images/FallbackImageProxy.ts:271
Generate variations of an image, falling back through providers that support the operation.
Parameters
request
The variation request forwarded to each capable provider.
Returns
Promise<ImageGenerationResult>
The result from the first provider that succeeds.
Throws
When every provider fails or does not support variations.