class OpenRouterClassificationGateway implements ClassificationGateway

Traits

Methods

string
classificationEndpoint()

Get the path of the endpoint that answers questions.

classify(ClassificationProvider $provider, string $model, string|array $state, array $questions, int $timeout = 30, array $providerOptions = [], array $attachments = [])

Answer the given questions about the state, sending image attachments as image parts of the state.

string
answeringModel(array $data, string $model)

Get the name of the model that answered the questions.

array
mapQuestion(Question $question)

Map a question to the decisions wire format.

Answer|null
mapAnswer(array $answer, Question|null $question = null)

Map an answer to an answer object, skipping unknown answer types.

array
withIntegerKeys(array $levels)

Cast the string level keys the provider returns to integers.

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 OpenRouter API.

string
baseUrl(Provider $provider)

Get the base URL for the Decisions API, which is served outside of the versioned API.

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
resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)

Resolve an attachment to an image with its content and MIME type.

array
stateWithImages(string|array $state, array $attachments)

Append the images to the state as data URL image parts, each named image preceded by its name.

array
mapImage(File|UploadedFile $attachment)

Map an image to a data URL image part.

Details

at line 101
protected string classificationEndpoint()

Get the path of the endpoint that answers questions.

Return Value

string

at line 41
ClassificationResponse classify(ClassificationProvider $provider, string $model, string|array $state, array $questions, int $timeout = 30, array $providerOptions = [], array $attachments = [])

Answer the given questions about the state, sending image attachments as image parts of the state.

Parameters

ClassificationProvider $provider
string $model
string|array $state
array $questions
int $timeout
array $providerOptions
array $attachments

Return Value

ClassificationResponse

in AnswersQuestions at line 81
protected string answeringModel(array $data, string $model)

Get the name of the model that answered the questions.

Parameters

array $data
string $model

Return Value

string

in AnswersQuestions at line 89
protected array mapQuestion(Question $question)

Map a question to the decisions wire format.

Parameters

Question $question

Return Value

array

in AnswersQuestions at line 114
protected Answer|null mapAnswer(array $answer, Question|null $question = null)

Map an answer to an answer object, skipping unknown answer types.

Parameters

array $answer
Question|null $question

Return Value

Answer|null

in AnswersQuestions at line 132
protected array withIntegerKeys(array $levels)

Cast the string level keys the provider returns to integers.

Parameters

array $levels

Return Value

array

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 OpenRouter API.

Parameters

Provider $provider
int|null $timeout

Return Value

PendingRequest

at line 109
protected string baseUrl(Provider $provider)

Get the base URL for the Decisions API, which is served outside of the versioned API.

Parameters

Provider $provider

Return Value

string

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 resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)

Resolve an attachment to an image with its content and MIME type.

Parameters

File|UploadedFile $attachment
string $endpoint
array $formats

Return Value

array

Exceptions

InvalidArgumentException

at line 66
protected array stateWithImages(string|array $state, array $attachments)

Append the images to the state as data URL image parts, each named image preceded by its name.

Parameters

string|array $state
array $attachments

Return Value

array

at line 86
protected array mapImage(File|UploadedFile $attachment)

Map an image to a data URL image part.

Parameters

File|UploadedFile $attachment

Return Value

array

Exceptions

InvalidArgumentException