PHPackages                             devbx/ai-hub-client - 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. devbx/ai-hub-client

ActiveLibrary[API Development](/categories/api)

devbx/ai-hub-client
===================

API client for Grok and OpenRouter AI services. Independent Composer library.

v1.0.0(3mo ago)00PHPPHP &gt;=8.2CI passing

Since Apr 4Pushed 3mo agoCompare

[ Source](https://github.com/dev-bx/devbx-ai-hub-client)[ Packagist](https://packagist.org/packages/devbx/ai-hub-client)[ RSS](/packages/devbx-ai-hub-client/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (2)Used By (0)

DevBX AI Hub Client
===================

[](#devbx-ai-hub-client)

[![PHPUnit Tests](https://github.com/dev-bx/devbx-ai-hub-client/actions/workflows/tests.yml/badge.svg)](https://github.com/dev-bx/devbx-ai-hub-client/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/41ae76be2654ec09672728b0919c07733bc326a1d5f68c527183963429b38b4f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657662782f61692d6875622d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devbx/ai-hub-client)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/12b5a8201a1f7981535d3a6842b41d285937391467cc33e1643745d31aa2dba4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533452533445f382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)

API client for Grok and OpenRouter AI services. Independent Composer library built with robust DTOs for seamless integration.

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

[](#installation)

You can install the package via composer:

```
composer require devbx/ai-hub-client
```

*Note: This library requires a PSR-18 compliant HTTP client. If you don't have one, you can install Guzzle:*

```
composer require guzzlehttp/guzzle
```

Usage
-----

[](#usage)

### OpenRouter API

[](#openrouter-api)

```
use GuzzleHttp\Client;
use DevBX\AIHub\Services\OpenRouterApiClient;
use DevBX\AIHub\Http\Adapters\GuzzleHttpClientAdapter;
use DevBX\AIHub\DTO\OpenRouter\ChatCompletionRequestDTO;
use DevBX\AIHub\DTO\OpenRouter\MessageDTO;

// 1. Initialize HTTP Adapter
$guzzleClient = new Client();
$adapter = new GuzzleHttpClientAdapter($guzzleClient);

// 2. Initialize API Client
$apiKey = 'your-openrouter-api-key';
$siteUrl = 'https://your-site.com'; // Optional
$siteName = 'YourSiteName'; // Optional
$apiClient = new OpenRouterApiClient($apiKey, $adapter, $siteUrl, $siteName);

// 3. Prepare Request via DTO
$requestDto = new ChatCompletionRequestDTO();
$requestDto->model = 'google/gemini-2.5-flash';

$messageDto = new MessageDTO();
$messageDto->role = 'user';
$messageDto->content = 'Hello, AI!';
$requestDto->messages = [$messageDto];

// 4. Send Request
try {
    $response = $apiClient->chatCompletion($requestDto);
    echo $response->choices[0]->message->content;
} catch (\DevBX\AIHub\Exceptions\OpenRouterApiException $e) {
    // Handle API/Network errors
    $errors = $e->getErrors();
    foreach ($errors as $error) {
        echo "Error [{$error->code}]: {$error->message}\n";
    }
}
```

### Grok Batch API

[](#grok-batch-api)

The library includes convenient factories to build batch requests for Grok.

```
use GuzzleHttp\Client;
use DevBX\AIHub\Services\GrokBatchApiClient;
use DevBX\AIHub\Http\Adapters\GuzzleHttpClientAdapter;
use DevBX\AIHub\DTO\Grok\Request\AddBatchRequestsDTO;
use DevBX\AIHub\Helpers\GrokBatchRequestFactory;

$adapter = new GuzzleHttpClientAdapter(new Client());
$grokClient = new GrokBatchApiClient('your-grok-api-key', $adapter);

// Create a new batch
$batch = $grokClient->createBatch('My Translation Batch');

// Add requests to the batch
$requestsDto = new AddBatchRequestsDTO();
$requestsDto->batchRequests = [
    GrokBatchRequestFactory::createChatCompletion(
        'request-1',
        [['role' => 'user', 'content' => 'Translate to French: Hello World']],
        'grok-4'
    )
];

$grokClient->addBatchRequests($batch->batchId, $requestsDto);
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance82

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

92d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/032f35591d5a547274640e9007b2373a45483646e04f8746c1f608f5343fb72e?d=identicon)[dev-bx](/maintainers/dev-bx)

---

Top Contributors

[![dev-bx](https://avatars.githubusercontent.com/u/9969001?v=4)](https://github.com/dev-bx "dev-bx (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devbx-ai-hub-client/health.svg)

```
[![Health](https://phpackages.com/badges/devbx-ai-hub-client/health.svg)](https://phpackages.com/packages/devbx-ai-hub-client)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k16](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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