PHPackages                             taecontrol/openrouter-laravel-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. taecontrol/openrouter-laravel-sdk

ActiveLibrary[API Development](/categories/api)

taecontrol/openrouter-laravel-sdk
=================================

An OpenRouter SDK for Laravel

0.0.7(5mo ago)2626[4 PRs](https://github.com/taecontrol/openrouter-laravel-sdk/pulls)MITPHPPHP ^8.4CI passing

Since Sep 18Pushed 1mo agoCompare

[ Source](https://github.com/taecontrol/openrouter-laravel-sdk)[ Packagist](https://packagist.org/packages/taecontrol/openrouter-laravel-sdk)[ Docs](https://github.com/taecontrol/openrouter-laravel-sdk)[ GitHub Sponsors](https://github.com/Taecontrol)[ RSS](/packages/taecontrol-openrouter-laravel-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (14)Versions (12)Used By (0)

An OpenRouter SDK for Laravel
=============================

[](#an-openrouter-sdk-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/91a00fdd488d940e618fb37ea09e237f7e624d44b7bed2a3a9b1fa9105cd44eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746165636f6e74726f6c2f6f70656e726f757465722d6c61726176656c2d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/taecontrol/openrouter-laravel-sdk)[![GitHub Tests Action Status](https://camo.githubusercontent.com/09ffc5492e62fe0cd132e919ddb35d34aed24ccbfa82323baccccf833c16428f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746165636f6e74726f6c2f6f70656e726f757465722d6c61726176656c2d73646b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/taecontrol/openrouter-laravel-sdk/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f6ba98bc0c483beafc408088cac61672696b41027fd11a6ae59a1af91eeebff0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746165636f6e74726f6c2f6f70656e726f757465722d6c61726176656c2d73646b2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/taecontrol/openrouter-laravel-sdk/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/55d996199ace38409bd67595a5dc85673cbef0727de07b0c4db9f883b58956ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746165636f6e74726f6c2f6f70656e726f757465722d6c61726176656c2d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/taecontrol/openrouter-laravel-sdk)

A lightweight, expressive Laravel wrapper around the [OpenRouter](https://openrouter.ai) API built on top of the excellent [Saloon](https://docs.saloon.dev/) HTTP client. It provides:

- Simple methods for text completions and chat completions (with optional streaming)
- Typed Data Objects for building requests and parsing responses
- Configurable base URI, API token and timeouts
- Support for reasoning &amp; usage reporting parameters

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10 or 11

Installation
------------

[](#installation)

Install via Composer:

```
composer require taecontrol/openrouter-laravel-sdk
```

Publish the config (optional – only if you want to override defaults):

```
php artisan vendor:publish --tag="openrouter-laravel-sdk-config"
```

The published config file (`config/openrouter-laravel-sdk.php`):

```
return [
    'base_uri' => 'https://openrouter.ai/api/v1',
    'token' => env('OPENROUTER_API_KEY', ''),
    'connect_timeout' => 10,
    'request_timeout' => 120,
];
```

Add your API key to `.env`:

```
OPENROUTER_API_KEY=sk-or-xxxxx
```

That's it. No migrations or views are shipped.

Quick Start
-----------

[](#quick-start)

Use the facade:

```
use Taecontrol\OpenRouter\Facades\OpenRouter;
use Taecontrol\OpenRouter\DataObjects\CompletionsData;

$response = OpenRouter::completions(
    new CompletionsData(
        model: 'openai/gpt-3.5-turbo-instruct',
        prompt: 'Write a haiku about Laravel.'
    )
);

$text = $response->choices[0]->text; // string
```

Or resolve the class (easier to swap or test):

```
use Taecontrol\OpenRouter\OpenRouter as OpenRouterClient;
use Taecontrol\OpenRouter\DataObjects\CompletionsData;

$client = app(OpenRouterClient::class);
$response = $client->completions(new CompletionsData(
    model: 'openai/gpt-3.5-turbo-instruct',
    prompt: 'Explain SOLID principles briefly.'
));
```

Chat Completions
----------------

[](#chat-completions)

```
use Taecontrol\OpenRouter\Facades\OpenRouter;
use Taecontrol\OpenRouter\DataObjects\ChatCompletionsData;
use Taecontrol\OpenRouter\DataObjects\ChatCompletionsMessageData;
use Taecontrol\OpenRouter\Enums\Role;

$data = new ChatCompletionsData(
    model: 'openai/gpt-4o-mini',
    messages: [
        ChatCompletionsMessageData::from([
            'role' => Role::User,
            'content' => 'Give me three Laravel testing tips.'
        ]),
    ],
    temperature: 0.7,
);

$response = OpenRouter::chatCompletions($data);

foreach ($response->choices as $choice) {
    $message = $choice->message; // ChatCompletionsMessageData
    echo $message->content . PHP_EOL;
}
```

Streaming Chat Completions
--------------------------

[](#streaming-chat-completions)

Streams are returned as a PSR-7 StreamInterface. You can iterate chunks as they arrive (framework/event broadcasting omitted for brevity):

```
use Taecontrol\OpenRouter\Facades\OpenRouter;
use Taecontrol\OpenRouter\DataObjects\ChatCompletionsData;
use Taecontrol\OpenRouter\DataObjects\ChatCompletionsMessageData;
use Taecontrol\OpenRouter\Enums\Role;

$stream = OpenRouter::chatCompletionsStream(
    new ChatCompletionsData(
        model: 'openai/gpt-4o-mini',
        messages: [
            ChatCompletionsMessageData::from([
                'role' => Role::User,
                'content' => 'Stream a short motivational quote word by word.'
            ]),
        ],
    )
);

while (!$stream->eof()) {
    $chunk = $stream->read(1024);
    if ($chunk !== '') {
        echo $chunk; // Each SSE/data chunk from OpenRouter
    }
}
```

Embeddings
----------

[](#embeddings)

You can generate embeddings for text using the `embeddings` method:

```
use Taecontrol\OpenRouter\Facades\OpenRouter;
use Taecontrol\OpenRouter\DataObjects\EmbeddingsData;
use Taecontrol\OpenRouter\Enums\EmbeddingEncodingFormat;

$data = new EmbeddingsData(
    input: 'The quick brown fox jumps over the lazy dog',
    model: 'text-embedding-ada-002',
    encodingFormat: EmbeddingEncodingFormat::Float, // Optional: Float or Base64
);

$response = OpenRouter::embeddings($data);

foreach ($response->data as $embeddingObject) {
    print_r($embeddingObject->embedding); // array of floats
    echo $embeddingObject->index; // int
}

// Usage statistics are also available
echo $response->usage->totalTokens;
```

Request Data Objects
--------------------

[](#request-data-objects)

You construct strongly-typed request DTOs:

- CompletionsData(model, prompt, reasoningData?, usageData?, maxTokens?, temperature?, seed?, topP?, topK?, user?)
- ChatCompletionsData(model, messages\[\], reasoningData?, usageData?, maxTokens?, temperature?, seed?, topP?, topK?, user?)
- ChatCompletionsMessageData(role, content, refusal?, reasoning?, reasoningDetails\[\]?)
- EmbeddingsData(input, model, encodingFormat?, dimensions?, user?, provider?, inputType?)
- ReasoningData(effort: Effort|null, maxTokens: string|null, exclude: bool|null)
- UsageData(include: bool = false)

### Optional Parameters

[](#optional-parameters)

ParameterPurposetemperatureControls randomness (float)max\_tokensLimit output tokens (int)top\_pNucleus sampling (float)top\_kLimits token selection to top K (int)seedDeterminism when supported (int)userEnd-user identifier stringreasoningStructured reasoning controls (ReasoningData)usageAsk API to include usage breakdown (UsageData)### Reasoning Effort Enum

[](#reasoning-effort-enum)

Effort values come from `Taecontrol\OpenRouter\Enums\Effort` (e.g. `Effort::Low`, `Effort::Medium`, `Effort::High`).

### Roles Enum

[](#roles-enum)

Use `Taecontrol\OpenRouter\Enums\Role` (e.g. `Role::User`, `Role::Assistant`, `Role::System`).

Responses
---------

[](#responses)

- CompletionsResponse(id, choices\[\] CompletionsChoicesData)
- ChatCompletionsResponse(id, choices\[\] ChatCompletionsChoiceData)
- EmbeddingsResponseData(object, data\[\] EmbeddingObjectData, model, usage?)

Each ChatCompletionsChoiceData wraps a ChatCompletionsMessageData (so you always look at `$choice->message->content`).

Dependency Injection / Custom Token
-----------------------------------

[](#dependency-injection--custom-token)

You can instantiate with a custom token (overrides config/env):

```
use Taecontrol\OpenRouter\OpenRouter;
use Taecontrol\OpenRouter\DataObjects\CompletionsData;

$client = new OpenRouter(token: 'sk-alt-token');
$response = $client->completions(new CompletionsData(
    model: 'openai/gpt-3.5-turbo-instruct',
    prompt: 'Custom token example.'
));
```

Timeouts
--------

[](#timeouts)

Configure in `config/openrouter-laravel-sdk.php`:

- connect\_timeout (default 10s)
- request\_timeout (default 120s)

Testing
-------

[](#testing)

A basic test suite is included (Pest). Run:

```
composer test
```

You can mock the underlying Saloon connector or stub methods on the OpenRouter class when testing your application.

Error Handling
--------------

[](#error-handling)

All request methods may throw:

- Saloon\\Exceptions\\Request\\RequestException (HTTP level problems)
- Saloon\\Exceptions\\Request\\FatalRequestException (network/transport issues)
- \\Throwable (in edge cases such as JSON decoding)

Wrap calls as needed:

```
try {
    $response = OpenRouter::completions(new CompletionsData(
        model: 'openai/gpt-3.5-turbo-instruct',
        prompt: 'Give me a tip.'
    ));
} catch (\Throwable $e) {
    report($e);
}
```

Roadmap / Ideas
---------------

[](#roadmap--ideas)

- Add image generation endpoints when exposed
- Add tools/function calling support if OpenRouter standardizes schema
- Add automatic pagination helpers if needed

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md).

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) for reporting guidelines.

License
-------

[](#license)

Released under the MIT License. See [LICENSE](LICENSE.md).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance82

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

7

Last Release

166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7451d38131171ca4b0ed598a872906b7c01643f7650e63e96769d3bc39477e6?d=identicon)[guetteluis](/maintainers/guetteluis)

---

Top Contributors

[![guetteman](https://avatars.githubusercontent.com/u/13571642?v=4)](https://github.com/guetteman "guetteman (33 commits)")[![rpereira-tae](https://avatars.githubusercontent.com/u/61505019?v=4)](https://github.com/rpereira-tae "rpereira-tae (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laraveltaecontrolopenrouter-laravel-sdk

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/taecontrol-openrouter-laravel-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/taecontrol-openrouter-laravel-sdk/health.svg)](https://phpackages.com/packages/taecontrol-openrouter-laravel-sdk)
```

###  Alternatives

[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[codebar-ag/laravel-docuware

DocuWare integration with Laravel

1221.1k](/packages/codebar-ag-laravel-docuware)[combindma/laravel-facebook-pixel

Meta pixel integration for Laravel

4956.9k](/packages/combindma-laravel-facebook-pixel)[stechstudio/laravel-hubspot

A Laravel SDK for the HubSpot CRM Api

2971.0k](/packages/stechstudio-laravel-hubspot)[codebar-ag/laravel-zammad

Zammad integration with Laravel

106.1k](/packages/codebar-ag-laravel-zammad)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
