class OpenAiFileGateway implements FileGateway

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.

client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the OpenAI API.

string
baseUrl(Provider $provider)

Get the base URL for the OpenAI-compatible API.

string
resourceId(string $id)

Encode the given provider resource ID as a single URL path segment.

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.

array
prepareStorableFile(StorableFile $file)

Prepare file data for upload.

array
resolveProviderOptionsAndHeaders(StorableFile $file, Lab|string $provider)

Resolve the upload body options and HTTP headers for the given file.

getFile(FileProvider $provider, string $fileId)

Get a file by its ID.

putFile(FileProvider $provider, StorableFile $file)

Store the given file.

void
deleteFile(FileProvider $provider, string $fileId)

Delete a file by its ID.

string
defaultPurpose()

Get the default purpose to use when a file does not specify one.

Lab
providerOptionsKey()

Get the provider key used to resolve file upload options.

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 PendingRequest client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the OpenAI API.

Parameters

Provider $provider
int|null $timeout

Return Value

PendingRequest

protected string baseUrl(Provider $provider)

Get the base URL for the OpenAI-compatible API.

Parameters

Provider $provider

Return Value

string

in EncodesResourceIds at line 16
protected string resourceId(string $id)

Encode the given provider resource ID as a single URL path segment.

Parameters

string $id

Return Value

string

Exceptions

InvalidArgumentException

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

protected array prepareStorableFile(StorableFile $file)

Prepare file data for upload.

Parameters

StorableFile $file

Return Value

array

protected array resolveProviderOptionsAndHeaders(StorableFile $file, Lab|string $provider)

Resolve the upload body options and HTTP headers for the given file.

Parameters

StorableFile $file
Lab|string $provider

Return Value

array

at line 29
FileResponse getFile(FileProvider $provider, string $fileId)

Get a file by its ID.

Parameters

FileProvider $provider
string $fileId

Return Value

FileResponse

at line 46
StoredFileResponse putFile(FileProvider $provider, StorableFile $file)

Store the given file.

Parameters

FileProvider $provider
StorableFile $file

Return Value

StoredFileResponse

at line 73
void deleteFile(FileProvider $provider, string $fileId)

Delete a file by its ID.

Parameters

FileProvider $provider
string $fileId

Return Value

void

at line 86
protected string defaultPurpose()

Get the default purpose to use when a file does not specify one.

Return Value

string

at line 94
protected Lab providerOptionsKey()

Get the provider key used to resolve file upload options.

Return Value

Lab