class BedrockImageGateway implements ImageGateway

Traits

Methods

createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

string
httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

BedrockRuntimeClient
createBedrockClient(Provider $provider, int|null $timeout = null)

Create a new Bedrock client instance.

string
bedrockRegion(array $config)

Resolve the configured region, falling back to the default.

array
resolveAuthConfig(array $credentials, array $config, int|null $timeout = null)

Resolve the provider authentication configuration.

array
resolveSourceAuthConfig(array $credentials, array $config)

Resolve the auth configuration for static, or automatically discovered, credentials.

assumeRoleCredentialProvider(array $credentials, array $config, int|null $timeout = null)

Create a loader that assumes the configured role.

StsClient
createStsClient(array $credentials, array $config, int|null $timeout = null)

Create the STS client used to assume the configured role.

array
assumeRoleParameters(array $assumeRole)

Build the parameters for the STS assume role request.

mixed
withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

int|null
retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

bool
isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

array
overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

array
insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

array
insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

generateImage(ImageProvider $provider, string $model, string $prompt, array $attachments = [], string|null $size = null, string|null $quality = null, int|null $timeout = null, array $providerOptions = [])

Generate an image using AWS Bedrock.

array
prepareImageRequestBody(string $model, string $prompt, string|null $size, array $options)

Prepare the request body for the given model family.

parseImageResponse(string $model, array $result)

Parse the image response payload into GeneratedImage instances.

array
parseSize(string|null $size)

Parse an aspect-ratio size into explicit [width, height] dimensions.

Details

in CreatesClient at line 21
protected PendingRequest createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

Parameters

string $baseUrl
array $headers
array $configuredHeaders
int|null $timeout
bool $throw

Return Value

PendingRequest

in CreatesClient at line 43
protected string httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

Parameters

Provider $provider

Return Value

string

protected BedrockRuntimeClient createBedrockClient(Provider $provider, int|null $timeout = null)

Create a new Bedrock client instance.

Parameters

Provider $provider
int|null $timeout

Return Value

BedrockRuntimeClient

protected string bedrockRegion(array $config)

Resolve the configured region, falling back to the default.

Parameters

array $config

Return Value

string

in CreatesBedrockClient at line 101
protected array resolveAuthConfig(array $credentials, array $config, int|null $timeout = null)

Resolve the provider authentication configuration.

Parameters

array $credentials
array $config
int|null $timeout

Return Value

array

in CreatesBedrockClient at line 124
protected array resolveSourceAuthConfig(array $credentials, array $config)

Resolve the auth configuration for static, or automatically discovered, credentials.

Parameters

array $credentials
array $config

Return Value

array

in CreatesBedrockClient at line 153
protected Closure assumeRoleCredentialProvider(array $credentials, array $config, int|null $timeout = null)

Create a loader that assumes the configured role.

Parameters

array $credentials
array $config
int|null $timeout

Return Value

Closure

in CreatesBedrockClient at line 167
protected StsClient createStsClient(array $credentials, array $config, int|null $timeout = null)

Create the STS client used to assume the configured role.

Parameters

array $credentials
array $config
int|null $timeout

Return Value

StsClient

in CreatesBedrockClient at line 189
protected array assumeRoleParameters(array $assumeRole)

Build the parameters for the STS assume role request.

Parameters

array $assumeRole

Return Value

array

protected mixed withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

Parameters

string $providerName
Closure $callback

Return Value

mixed

protected int|null retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

Parameters

Throwable $exception

Return Value

int|null

protected bool isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

Parameters

RequestException $exception

Return Value

bool

protected array overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

Return Value

array

protected array insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

Return Value

array

protected array insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

Return Value

array

at line 36
ImageResponse generateImage(ImageProvider $provider, string $model, string $prompt, array $attachments = [], string|null $size = null, string|null $quality = null, int|null $timeout = null, array $providerOptions = [])

Generate an image using AWS Bedrock.

Parameters

ImageProvider $provider
string $model
string $prompt
array $attachments
string|null $size
string|null $quality
int|null $timeout
array $providerOptions

Return Value

ImageResponse

Exceptions

LogicException

at line 82
protected array prepareImageRequestBody(string $model, string $prompt, string|null $size, array $options)

Prepare the request body for the given model family.

Parameters

string $model
string $prompt
string|null $size
array $options

Return Value

array

at line 121
protected Collection parseImageResponse(string $model, array $result)

Parse the image response payload into GeneratedImage instances.

Parameters

string $model
array $result

Return Value

Collection

at line 138
protected array parseSize(string|null $size)

Parse an aspect-ratio size into explicit [width, height] dimensions.

Parameters

string|null $size

Return Value

array