OpenRouterProvider
class OpenRouterProvider extends Provider implements AudioProvider, ClassificationProvider, EmbeddingProvider, FileProvider, ImageProvider, RerankingProvider, SupportsWebFetch, SupportsWebSearch, TextProvider, TranscriptionProvider
Traits
Properties
| protected AudioGateway | $audioGateway | from HasAudioGateway | |
| protected ClassificationGateway | $classificationGateway | from HasClassificationGateway | |
| protected EmbeddingGateway | $embeddingGateway | from HasEmbeddingGateway | |
| protected FileGateway | $fileGateway | from HasFileGateway | |
| protected ImageGateway | $imageGateway | from HasImageGateway | |
| protected RerankingGateway | $rerankingGateway | from HasRerankingGateway | |
| protected StepTextGateway | $textGateway | from HasTextGateway | |
| protected TextGenerationLoop|null | $textGenerationLoop | from HasTextGateway | |
| protected TranscriptionGateway | $transcriptionGateway | from HasTranscriptionGateway |
Methods
Get the provider connection configuration other than the driver, key, and name.
Get a provider instance that sends the given HTTP headers with each request.
Run the given gateway call, dispatching the event built from its exception before rethrowing.
Format the given provider / model list.
Get provider and model pairs without discarding on-demand instances.
Restore the provider from its serialized representation.
Answer the given questions about the state.
Determine if the provider can classify attachments alongside the state.
Generate audio from the given text.
Get embedding vectors representing the given inputs.
Determine if the provider may omit dimensions and use a model's native embedding dimensions.
Validate embeddings inputs against the provider's supported media types.
Generate an image.
Get the tool approval to resume with, unless a faked agent has no paused approval to resume.
Replace another provider's raw paused-turn replay state with its generic mapping, since raw blocks are only valid verbatim on the provider that produced them.
Determine whether the prompt is a resume that runs the approved tools.
Get a callback that captures a resume's resolved approval results for its completion event.
Resolve the tools for the given prompt, wrapping any agent instances as tools.
Get the tools the agent declares, including the tool that loads its skills.
Resolve a tool returned by the agent into a native tool instance when needed.
Build the run's context, letting a remembered conversation claim and record the approval decisions the run resumes.
Build the context that identifies this run and reports its step and tool events.
Dispatch the terminal failure event for a run, unless the caller may still retry it against another provider.
Throw when a pause has surfaced on a prompt that cannot be resumed from persisted or replayed history.
Transcribe the given audio to text.
Get the provider's audio gateway.
Get the provider's classification gateway.
Get the provider's embedding gateway.
Get the provider's file gateway.
Get the provider's image gateway.
Get the provider's reranking gateway.
Get the provider's text gateway.
Get the multi-step text generation loop wrapping the provider's text gateway.
Get the provider's transcription gateway.
Rerank the given documents based on their relevance to the query.
Get the parameters for an OpenRouter server tool.
Get the name of the default text model.
Get the name of the cheapest text model.
Get the name of the smartest text model.
Get the name of the default image model.
Get the default / normalized image options for the provider.
Get the name of the default audio (TTS) model.
Get the name of the default transcription (STT) model.
Get the name of the default embeddings model.
Get the default dimensions of the default embeddings model.
Get the name of the default reranking model.
Get the name of the default classification model.
Details
at line 73
__construct(array $config, Dispatcher $events)
Create an OpenRouter provider instance.
in
Provider at line 34
string
name()
Get the name of the underlying AI provider.
in
Provider at line 42
string
driver()
Get the name of the underlying AI driver.
in
Provider at line 50
array
providerCredentials()
Get the credentials for the underlying AI provider.
in
Provider at line 60
array
additionalConfiguration()
Get the provider connection configuration other than the driver, key, and name.
in
Provider at line 72
Provider
withHeaders(array $headers)
| internal |
Get a provider instance that sends the given HTTP headers with each request.
in
Provider at line 92
protected mixed
dispatchingFailure(Closure $call, Closure $failed)
Run the given gateway call, dispatching the event built from its exception before rethrowing.
in
Provider at line 114
static array
formatProviderAndModelList(Provider|Lab|array|string $providers, string|null $model = null)
Format the given provider / model list.
in
Provider at line 132
static array
providerAndModelPairs(Provider|Lab|array|string $providers, string|null $model = null)
| internal |
Get provider and model pairs without discarding on-demand instances.
in
Provider at line 164
array
__serialize()
Get the serializable representation of the provider.
in
Provider at line 174
void
__unserialize(array $data)
Restore the provider from its serialized representation.
in
Provider at line 190
string
__toString()
Convert the provider to its string representation.
in
Classifies at line 30
ClassificationResponse
classify(string|array $state, array $questions, string|null $model = null, int $timeout = 30, array $providerOptions = [], array $attachments = [])
Answer the given questions about the state.
at line 271
bool
supportsClassificationAttachments()
Determine if the provider can classify attachments alongside the state.
in
GeneratesAudio at line 23
AudioResponse
audio(string $text, string $voice = 'default-female', string|null $instructions = null, string|null $model = null, int $timeout = 30, array $providerOptions = [])
Generate audio from the given text.
in
GeneratesEmbeddings at line 29
EmbeddingsResponse
embeddings(array $inputs, int|null $dimensions = null, string|null $model = null, int $timeout = 30, array $providerOptions = [])
Get embedding vectors representing the given inputs.
in
GeneratesEmbeddings at line 87
protected bool
supportsNativeEmbeddingDimensions()
Determine if the provider may omit dimensions and use a model's native embedding dimensions.
in
GeneratesEmbeddings at line 97
protected void
validateEmbeddingInputs(array $inputs, string $model)
Validate embeddings inputs against the provider's supported media types.
in
GeneratesImages at line 26
ImageResponse
image(string $prompt, array $attachments = [], string|null $size = null, string|null $quality = null, string|null $model = null, int|null $timeout = null, array $providerOptions = [])
Generate an image.
in
ResumesToolApprovals at line 26
protected array|null
resumableApprovalFor(AgentPrompt $prompt, array $messages, array $tools)
Get the tool approval to resume with, unless a faked agent has no paused approval to resume.
in
ResumesToolApprovals at line 37
protected array
withoutForeignReplayBlocks(array $messages)
Replace another provider's raw paused-turn replay state with its generic mapping, since raw blocks are only valid verbatim on the provider that produced them.
in
ResumesToolApprovals at line 57
protected bool
resumesApproval(AgentPrompt $prompt, array $messages, array $tools)
Determine whether the prompt is a resume that runs the approved tools.
in
ResumesToolApprovals at line 76
protected Closure|null
approvalResultRecorderFor(AgentPrompt $prompt, array|null $approval, Collection|null $resolvedApprovalResults)
Get a callback that captures a resume's resolved approval results for its completion event.
in
GeneratesText at line 53
AgentResponse
prompt(AgentPrompt $prompt)
Invoke the given agent.
in
GeneratesText at line 175
protected array
gatherMiddlewareFor(Agent $agent)
Gather the internal run middleware for the given agent.
in
GeneratesText at line 193
protected array
resolveTools(AgentPrompt $prompt)
Resolve the tools for the given prompt, wrapping any agent instances as tools.
in
GeneratesText at line 204
protected array
declaredTools(Agent $agent)
Get the tools the agent declares, including the tool that loads its skills.
in
GeneratesText at line 214
protected mixed
resolveTool(mixed $tool)
Resolve a tool returned by the agent into a native tool instance when needed.
in
GeneratesText at line 233
protected RunContext
prepareRunContext(string $invocationId, AgentPrompt $prompt, array|null $approval)
Build the run's context, letting a remembered conversation claim and record the approval decisions the run resumes.
in
GeneratesText at line 257
protected RunContext
runContextFor(string $invocationId, AgentPrompt $prompt)
Build the context that identifies this run and reports its step and tool events.
in
GeneratesText at line 268
protected void
recordAgentFailure(string $invocationId, AgentPrompt $prompt, Throwable $exception, bool $retryable = true)
Dispatch the terminal failure event for a run, unless the caller may still retry it against another provider.
in
GeneratesText at line 285
protected void
throwIfNotResumable(AgentPrompt $prompt)
Throw when a pause has surfaced on a prompt that cannot be resumed from persisted or replayed history.
in
GeneratesTranscriptions at line 24
TranscriptionResponse
transcribe(TranscribableAudio $audio, string|null $language = null, bool $diarize = false, string|null $model = null, int|null $timeout = null, array $providerOptions = [])
Transcribe the given audio to text.
at line 191
AudioGateway
audioGateway()
Get the provider's audio gateway.
in
HasAudioGateway at line 27
HasAudioGateway
useAudioGateway(AudioGateway $gateway)
Set the provider's audio gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 255
ClassificationGateway
classificationGateway()
Get the provider's classification gateway.
in
HasClassificationGateway at line 27
HasClassificationGateway
useClassificationGateway(ClassificationGateway $gateway)
Set the provider's classification gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 127
EmbeddingGateway
embeddingGateway()
Get the provider's embedding gateway.
in
HasEmbeddingGateway at line 27
HasEmbeddingGateway
useEmbeddingGateway(EmbeddingGateway $gateway)
Set the provider's embedding gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 247
FileGateway
fileGateway()
Get the provider's file gateway.
in
HasFileGateway at line 27
HasFileGateway
useFileGateway(FileGateway $gateway)
Set the provider's file gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 159
ImageGateway
imageGateway()
Get the provider's image gateway.
in
HasImageGateway at line 27
HasImageGateway
useImageGateway(ImageGateway $gateway)
Set the provider's image gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 279
RerankingGateway
rerankingGateway()
Get the provider's reranking gateway.
in
HasRerankingGateway at line 27
HasRerankingGateway
useRerankingGateway(RerankingGateway $gateway)
Set the provider's reranking gateway.
Changing a shared provider's gateway affects subsequent operations.
at line 119
StepTextGateway
textGateway()
Get the provider's text gateway.
in
HasTextGateway at line 30
HasTextGateway
useTextGateway(StepTextGateway $gateway)
Set the provider's text gateway.
Changing a shared provider's gateway affects subsequent operations.
in
HasTextGateway at line 42
TextGenerationLoop
textGenerationLoop()
Get the multi-step text generation loop wrapping the provider's text gateway.
at line 207
TranscriptionGateway
transcriptionGateway()
Get the provider's transcription gateway.
in
HasTranscriptionGateway at line 27
HasTranscriptionGateway
useTranscriptionGateway(TranscriptionGateway $gateway)
Set the provider's transcription gateway.
Changing a shared provider's gateway affects subsequent operations.
in
ManagesFiles at line 23
FileResponse
getFile(string $fileId)
Get a file by its ID.
in
ManagesFiles at line 31
StoredFileResponse
putFile(StorableFile $file)
Store the given file.
in
ManagesFiles at line 68
void
deleteFile(string $fileId)
Delete a file by its ID.
in
Reranks at line 24
RerankingResponse
rerank(array $documents, string $query, int|null $limit = null, string|null $model = null, int $timeout = 30, array $providerOptions = [])
Rerank the given documents based on their relevance to the query.
in
StreamsText at line 37
StreamableAgentResponse
stream(AgentPrompt $prompt)
Stream the response from the given agent.
at line 80
array
webFetchToolOptions(WebFetch $fetch)
Get the web fetch tool options for the provider.
at line 88
array
webSearchToolOptions(WebSearch $search)
Get the web search tool options for the provider.
at line 105
protected array
serverToolOptions(WebFetch|WebSearch $tool, array $parameters = [])
Get the parameters for an OpenRouter server tool.
at line 135
string
defaultTextModel()
Get the name of the default text model.
at line 143
string
cheapestTextModel()
Get the name of the cheapest text model.
at line 151
string
smartestTextModel()
Get the name of the smartest text model.
at line 167
string
defaultImageModel()
Get the name of the default image model.
at line 175
array
defaultImageOptions(string|null $size = null, string|null $quality = null)
Get the default / normalized image options for the provider.
at line 199
string
defaultAudioModel()
Get the name of the default audio (TTS) model.
at line 215
string
defaultTranscriptionModel()
Get the name of the default transcription (STT) model.
at line 223
string
defaultEmbeddingsModel()
Get the name of the default embeddings model.
at line 231
int
defaultEmbeddingsDimensions()
Get the default dimensions of the default embeddings model.
at line 239
string
defaultRerankingModel()
Get the name of the default reranking model.
at line 263
string
defaultClassificationModel()
Get the name of the default classification model.