OpenRouterClassificationGateway
class OpenRouterClassificationGateway implements ClassificationGateway
Traits
Methods
Get the path of the endpoint that answers questions.
Answer the given questions about the state, sending image attachments as image parts of the state.
Get the name of the model that answered the questions.
Map an answer to an answer object, skipping unknown answer types.
Cast the string level keys the provider returns to integers.
Create an HTTP client with the provider's request options.
Select a boot-registered connection without retaining dynamic provider names.
Execute a callback with failoverable error handling.
Get the short Retry-After delay of a rate limited or overloaded response, if it has one.
Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.
Get the status codes that indicate a provider is transiently unavailable and the request should fail over.
Get the patterns used to detect insufficient credits or quota errors.
Get the error codes or types that indicate insufficient credits or quota on a 429 response.
Resolve an attachment to an image with its content and MIME type.
Append the images to the state as data URL image parts, each named image preceded by its name.
Details
at line 101
protected string
classificationEndpoint()
Get the path of the endpoint that answers questions.
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.
in
AnswersQuestions at line 81
protected string
answeringModel(array $data, string $model)
Get the name of the model that answered the questions.
in
AnswersQuestions at line 89
protected array
mapQuestion(Question $question)
Map a question to the decisions wire format.
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.
in
AnswersQuestions at line 132
protected array
withIntegerKeys(array $levels)
Cast the string level keys the provider returns to integers.
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.
in
CreatesClient at line 43
protected string
httpConnection(Provider $provider)
Select a boot-registered connection without retaining dynamic provider names.
in
CreatesOpenRouterClient at line 18
protected PendingRequest
client(Provider $provider, int|null $timeout = null)
Get an HTTP client for the OpenRouter API.
at line 109
protected string
baseUrl(Provider $provider)
Get the base URL for the Decisions API, which is served outside of the versioned API.
in
HandlesFailoverErrors at line 26
protected mixed
withErrorHandling(string $providerName, Closure $callback)
Execute a callback with failoverable error handling.
in
HandlesFailoverErrors at line 91
protected int|null
retryAfterSeconds(Throwable $exception)
Get the short Retry-After delay of a rate limited or overloaded response, if it has one.
in
HandlesFailoverErrors at line 115
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.
in
HandlesFailoverErrors at line 138
protected array
overloadedStatusCodes()
Get the status codes that indicate a provider is transiently unavailable and the request should fail over.
in
HandlesFailoverErrors at line 148
protected array
insufficientCreditPatterns()
Get the patterns used to detect insufficient credits or quota errors.
in
HandlesFailoverErrors at line 158
protected array
insufficientCreditCodes()
Get the error codes or types that indicate insufficient credits or quota on a 429 response.
in
ResolvesInlineImages at line 25
protected array
resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)
Resolve an attachment to an image with its content and MIME type.
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.
at line 86
protected array
mapImage(File|UploadedFile $attachment)
Map an image to a data URL image part.