Skip to main content

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.

The aisdk/openrouter package is the official OpenRouter provider for the PHP AI SDK. Installed via Composer, it gives your PHP application a single, consistent interface to hundreds of AI models — without managing separate client libraries for each provider. Under the hood it delegates all HTTP communication to the shared aisdk/openai-compatible wire adapter, so every request travels over OpenRouter’s OpenAI-compatible API surface with no extra overhead.

What is OpenRouter?

OpenRouter is a unified AI gateway that aggregates models from OpenAI, Anthropic, Google, xAI, Meta, Mistral, and dozens of other providers behind a single endpoint and billing account. You pick a model by its provider/model-id slug — for example openai/gpt-4o or anthropic/claude-sonnet-4 — and OpenRouter handles authentication, routing, and fallback on your behalf.

Key Features

Text Generation

Generate completions, answers, and structured output from any of OpenRouter’s supported chat models using a fluent PHP builder API.

Streaming

Stream tokens back to your application in real time for responsive UIs and long-form generation without waiting for the full response.

Image Generation

Produce images from natural-language prompts using models such as openai/gpt-image-1, with control over size, count, and aspect ratio.

370+ Models

Access every model available on OpenRouter — from frontier GPT-4o and Claude Sonnet to open-weight Llama and Mistral variants — through one package.

Provider Routing

Pass raw provider directives to OpenRouter to pin requests to specific inference providers, set fallback order, or configure reasoning effort.

Model Capabilities

Introspect declared capabilities — such as Capability::Reasoning or Capability::ImageInput — at runtime before dispatching a request.

How It Works

aisdk/openrouter wraps OpenRouter’s OpenAI-compatible REST API. When you call OpenRouter::model('openai/gpt-4o') the SDK instantiates an OpenRouterTextModel backed by an OpenRouterProvider. That provider delegates serialisation and transport to aisdk/openai-compatible, which formats the request body and sends it to https://openrouter.ai/api/v1/chat/completions. The response is unmarshalled back into the same result objects used by every other PHP AI SDK provider, so you can swap providers by changing a single line.

Requirements

RequirementVersion
PHP^8.3
aisdk/core^0.2
aisdk/openai-compatible^0.2
Both aisdk/core and aisdk/openai-compatible are pulled in automatically by Composer when you install aisdk/openrouter.
Ready to make your first API call? Follow the Quickstart to generate text and an image in under five minutes.

Build docs developers (and LLMs) love