Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openrouter/llms.txt
Use this file to discover all available pages before exploring further.
OpenRouterTextModel handles text generation by POSTing to /chat/completions on the OpenRouter API. It is built on top of the shared OpenAI-compatible wire adapter, so any model exposed through OpenRouter’s chat completions endpoint works out of the box.
Basic usage
Pass a model identifier toOpenRouter::model() and chain it with the Generate::text() builder. Call ->run() to execute the request synchronously and receive a TextModelResponse.
instructions() to set a system prompt that shapes the model’s behaviour across the entire conversation:
Response object
Generate::text()->run() returns a TextModelResponse. The fields most commonly used are:
| Field | Type | Description |
|---|---|---|
$result->text | string | The model’s completion text. |
$result->usage->inputTokens | int | Number of tokens consumed by the prompt. |
$result->usage->outputTokens | int | Number of tokens in the completion. |
$result->providerMetadata['openrouter']['id'] | string | The completion ID returned by OpenRouter (e.g. chatcmpl_openrouter). |
$result->providerMetadata['openrouter']['model'] | string | The model ID echoed back by the API (e.g. openai/gpt-4o). |
Model selection
OpenRouter model IDs follow theprovider/model-name format. Pass the full identifier string to OpenRouter::model():
OpenRouter::model() is a static helper that calls OpenRouter::default()->textModel($modelId) on the configured provider instance. You can browse the full list of available model IDs in the OpenRouter model catalogue.