Download the PHP package unlikelysource/simplified-openrouter-php-sdk without Composer
On this page you can find all versions of the php package unlikelysource/simplified-openrouter-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unlikelysource/simplified-openrouter-php-sdk
More information about unlikelysource/simplified-openrouter-php-sdk
Files in unlikelysource/simplified-openrouter-php-sdk
Package simplified-openrouter-php-sdk
Short Description Unofficial PHP SDK for the OpenRouter.ai API, modeled after the official Python SDK.
License MIT
Homepage https://github.com/dbierer/openrouter_php_sdk
Informations about the package simplified-openrouter-php-sdk
simplified_openrouter_php_sdk
An unofficial PHP SDK for the OpenRouter.ai API, modeled after the official Python SDK. This is a hand-written, idiomatic PHP client, not a generated 1:1 port — covering the core of the OpenRouter API:
- Chat Completions — including streaming
- Models — list, get, count
- Endpoints — list provider endpoints for a model
- Generations — request/usage metadata lookup
- Credits — account balance
- API Keys — full CRUD (management key required)
- Embeddings
The Python SDK is auto-generated from OpenRouter's OpenAPI spec and covers ~90 endpoint groups
(TTS/STT, video generation, OAuth, workspaces, BYOK, datasets, guardrails, analytics, and more).
This simplified PHP SDK, by design, covers only the subset most developers need. The architecture
(a Transportclass plus one resource class per endpoint group) makes it straightforward to add
more resources later if you need them. Contributions welcome!
This SDK leverages the Guzzle HTTP client, and produces PSR-7 compliant requests and responses. IMPORTANT: this is an Alpha release. If you need something more stable and production-ready, consider using eatzy/openrouter-php-sdk instead.
Requirements
- PHP 8.1+
- Composer
Installation
Quick start
Streaming
createStreamed() returns a ChatCompletionStream, an IteratorAggregate that lazily parses the
API's text/event-stream response and yields one ChatCompletionChunk per server-sent event,
stopping automatically at the [DONE] sentinel.
Request parameters
chat->create() / chat->createStreamed() accept the request body as a plain associative array,
matching the OpenRouter Chat Completions API
directly (model, messages, temperature, max_tokens, tools, tool_choice,
provider, reasoning, response_format, etc.) — nothing is hidden behind a rigid DTO, so any
parameter the API supports can be passed through as-is. messages entries may be plain arrays or
OpenRouter\DTO\ChatMessage instances (ChatMessage::system(), ::user(), ::assistant(), ::tool()).
Resources
See examples/ for complete runnable scripts.
Configuration
You can also inject your own Guzzle client (e.g. with custom middleware or a mock handler for
testing) via the httpClient constructor argument.
Error handling
Requests that receive an HTTP error status throw a subclass of OpenRouter\Exceptions\ApiException,
mapped by status code (BadRequestException, UnauthorizedException, PaymentRequiredException,
ForbiddenException, NotFoundException, TooManyRequestsException, InternalServerException, etc.):
Connection-level failures (DNS, timeouts, refused connections) that persist after retries are
exhausted throw OpenRouter\Exceptions\TransportException instead.
5xx responses are retried automatically with exponential backoff (defaults: up to 4 attempts, starting at 500ms, capped at 60s, 1.5x multiplier) before an exception is raised.
Development
License
MIT. Not affiliated with or endorsed by OpenRouter.
All versions of simplified-openrouter-php-sdk with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.5
psr/http-message Version ^1.1 || ^2.0