PHPackages                             cloud-dark/openrouter - 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. cloud-dark/openrouter

ActiveLibrary

cloud-dark/openrouter
=====================

Your project description

018↓100%PHP

Since Jul 10Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Cloud-Dark/openrouter-php-library)[ Packagist](https://packagist.org/packages/cloud-dark/openrouter)[ RSS](/packages/cloud-dark-openrouter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CloudDark OpenRouter PHP Library
================================

[](#clouddark-openrouter-php-library)

This is a simple PHP wrapper to interact with the [OpenRouter API](https://openrouter.ai). The wrapper allows you to send messages to the OpenRouter AI model and get responses in both **streaming** and **non-streaming** modes.

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

[](#requirements)

- PHP 7.4 or higher
- Composer

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

[](#installation)

To get started, you can install the package via Composer.

### 1. Clone the repository or initialize it in your project:

[](#1-clone-the-repository-or-initialize-it-in-your-project)

```
composer require cloud-dark/openrouter:dev-main
```

### 2. Upgrade dependencies using Composer:

[](#2-upgrade-dependencies-using-composer)

```
composer upgrade && composer update
```

This will install the necessary dependencies and set up the autoloader.

Usage
-----

[](#usage)

Once installed, you can use the `OpenRouter` class to send requests to the OpenRouter API.

### Example PHP Code

[](#example-php-code)

#### 1. **Non-Streaming (Standard Request)**

[](#1-non-streaming-standard-request)

```

```

#### 2. **Streaming (Real-time Request)**

[](#2-streaming-real-time-request)

```

```

### Expected Response

[](#expected-response)

The expected response from the OpenRouter API can vary based on the mode.

#### Non-Streaming Response:

[](#non-streaming-response)

The response for non-streaming will be a complete JSON object, similar to:

```
stdClass Object
(
    [id] => gen-1738686490-prk4jkf3l7In1GdYKoAI
    [provider] => DeepInfra
    [model] => mistralai/mixtral-8x7b-instruct
    [object] => chat.completion
    [created] => 1738686490
    [choices] => Array
        (
            [0] => stdClass Object
                (
                    [logprobs] =>
                    [finish_reason] => stop
                    [native_finish_reason] => stop
                    [index] => 0
                    [message] => stdClass Object
                        (
                            [role] => assistant
                            [content] =>  Hello! How can I assist you today? I'm here to help answer your questions, provide information, and facilitate any tasks you need help with. Let me know what you need.
                            [refusal] =>
                        )

                )

        )

    [usage] => stdClass Object
        (
            [prompt_tokens] => 19
            [completion_tokens] => 38
            [total_tokens] => 57
        )

)

```

#### Streaming Response:

[](#streaming-response)

In the case of streaming, the data will be received and output in real-time. The response will be directly displayed as it is processed, which could look like:

```
: OPENROUTER PROCESSING

data: {"id":"gen-1752162887-d4GeVQ1Wdg06gaa0YgwE","provider":"Google AI Studio","model":"google/gemini-2.0-flash-exp:free","object":"chat.completion.chunk","created":1752162887,"choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: {"id":"gen-1752162887-d4GeVQ1Wdg06gaa0YgwE","provider":"Google AI Studio","model":"google/gemini-2.0-flash-exp:free","object":"chat.completion.chunk","created":1752162887,"choices":[{"index":0,"delta":{"role":"assistant","content":" there! How"},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: {"id":"gen-1752162887-d4GeVQ1Wdg06gaa0YgwE","provider":"Google AI Studio","model":"google/gemini-2.0-flash-exp:free","object":"chat.completion.chunk","created":1752162887,"choices":[{"index":0,"delta":{"role":"assistant","content":" can I help you today?\n"},"finish_reason":"stop","native_finish_reason":"STOP","logprobs":null}]}

data: {"id":"gen-1752162887-d4GeVQ1Wdg06gaa0YgwE","provider":"Google AI Studio","model":"google/gemini-2.0-flash-exp:free","object":"chat.completion.chunk","created":1752162887,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null,"native_finish_reason":null,"logprobs":null}],"usage":{"prompt_tokens":10,"completion_tokens":11,"total_tokens":21}}

data: [DONE]
```

The output will be displayed as chunks of data in the browser as they are received from the API.

Customization
-------------

[](#customization)

You can customize the `OpenRouter` class by adjusting the URL, token, or model that you're using to interact with the OpenRouter API.

- **Set Token:** `setToken('your-api-token')`
- **Set Model:** `setModel('your-model-id')`
- **Enable/Disable Streaming:** `chat($messages, true)` for streaming or `chat($messages, false)` for non-streaming.

License
-------

[](#license)

This project is open-source and available under the [MIT License](LICENSE).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance40

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c0106141a074a85e83bf91039cd19e07f1c2adae184a92b014b70e6099e7d9c?d=identicon)[Cloud-Dark](/maintainers/Cloud-Dark)

---

Top Contributors

[![Cloud-Dark](https://avatars.githubusercontent.com/u/28920412?v=4)](https://github.com/Cloud-Dark "Cloud-Dark (7 commits)")

### Embed Badge

![Health badge](/badges/cloud-dark-openrouter/health.svg)

```
[![Health](https://phpackages.com/badges/cloud-dark-openrouter/health.svg)](https://phpackages.com/packages/cloud-dark-openrouter)
```

PHPackages © 2026

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