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

ActiveLibrary

oscarweijman/ai-client
======================

Een moderne PHP AI Client

v1.1.0(1y ago)04MITPHPPHP ^8.1CI passing

Since Mar 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/OscarWeijman/AIClient)[ Packagist](https://packagist.org/packages/oscarweijman/ai-client)[ RSS](/packages/oscarweijman-ai-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

AI Client
=========

[](#ai-client)

Een moderne PHP client voor AI API's zoals OpenAI en DeepSeek.

[![Tests](https://github.com/OscarWeijman/AIClient/actions/workflows/tests.yml/badge.svg)](https://github.com/OscarWeijman/AIClient/actions/workflows/tests.yml)[![Static Analysis](https://github.com/OscarWeijman/AIClient/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/OscarWeijman/AIClient/actions/workflows/static-analysis.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Installatie
-----------

[](#installatie)

```
composer require oscarweijman/ai-client
```

Gebruik
-------

[](#gebruik)

### Client initialiseren

[](#client-initialiseren)

```
use OscarWeijman\AIClient\AIClientFactory;

// Maak een OpenAI client
$openaiClient = AIClientFactory::create('openai', 'jouw-api-key');

// Maak een DeepSeek client
$deepseekClient = AIClientFactory::create('deepseek', 'jouw-api-key');
```

### Text Completion

[](#text-completion)

```
$result = $openaiClient->completion('Wat is de hoofdstad van Nederland?', [
    'max_tokens' => 100,
    'temperature' => 0.7,
]);

echo $result['content'];
```

### Chat Completion

[](#chat-completion)

```
$result = $openaiClient->chatCompletion([
    ['role' => 'system', 'content' => 'Je bent een behulpzame assistent.'],
    ['role' => 'user', 'content' => 'Wat is de hoofdstad van Nederland?'],
], [
    'max_tokens' => 100,
    'temperature' => 0.7,
]);

echo $result['content'];
```

### Streaming Chat Completion (v1.1.0+)

[](#streaming-chat-completion-v110)

```
$messages = [
    ['role' => 'system', 'content' => 'Je bent een behulpzame assistent.'],
    ['role' => 'user', 'content' => 'Schrijf een kort verhaal over een robot die leert programmeren.'],
];

// Callback functie die wordt aangeroepen voor elk stukje van de streaming response
$callback = function ($chunk) {
    echo $chunk['content'];
    flush(); // Zorg ervoor dat de output direct wordt weergegeven
};

// Voer de streaming chat completion uit
$openaiClient->streamingChatCompletion($messages, $callback, [
    'model' => 'gpt-3.5-turbo',
    'temperature' => 0.7,
]);
```

Response formaat
----------------

[](#response-formaat)

Alle API responses worden gestandaardiseerd naar het volgende formaat:

```
[
    'provider' => 'openai', // of 'deepseek'
    'content' => 'De inhoud van het antwoord',
    'raw_response' => [], // De originele API response
    'finish_reason' => 'stop', // De reden waarom de generatie is gestopt
    'model' => 'gpt-3.5-turbo', // Het gebruikte model
    'usage' => [
        'prompt_tokens' => 10,
        'completion_tokens' => 20,
        'total_tokens' => 30,
    ],
]
```

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

[](#error-handling)

De bibliotheek gooit `AIClientException` bij fouten:

```
use OscarWeijman\AIClient\Exceptions\AIClientException;

try {
    $result = $client->chatCompletion($messages);
} catch (AIClientException $e) {
    echo "Error: " . $e->getMessage();
}
```

Tests uitvoeren
---------------

[](#tests-uitvoeren)

### Unit en Feature tests

[](#unit-en-feature-tests)

```
composer test
```

Of met de Pest CLI:

```
./vendor/bin/pest --exclude-group=integration
```

### Integratie tests met echte API's

[](#integratie-tests-met-echte-apis)

1. Kopieer het `.env.example` bestand naar `.env`
2. Vul je API keys in
3. Zet `ENABLE_API_TESTS=true`
4. Voer de tests uit:

```
composer test-integration
```

Of met de Pest CLI:

```
./vendor/bin/pest tests/Integration
```

Statische analyse
-----------------

[](#statische-analyse)

```
composer analyse
```

GitHub Actions
--------------

[](#github-actions)

Dit project gebruikt GitHub Actions voor automatische tests en statische analyse:

- **tests.yml**: Voert unit en feature tests uit op verschillende PHP versies
- **integration-tests.yml**: Voert integratie tests uit met echte API's (handmatig te triggeren)
- **static-analysis.yml**: Voert PHPStan analyse uit

Licentie
--------

[](#licentie)

Dit project is gelicenseerd onder de MIT licentie - zie het [LICENSE](LICENSE) bestand voor details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance46

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Every ~0 days

Total

2

Last Release

421d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ff8873bc406af8c3868c6f3bce1d214de3c2f3bd675e48951b592b25bd6021e?d=identicon)[OscarW](/maintainers/OscarW)

---

Top Contributors

[![OscarWeijman](https://avatars.githubusercontent.com/u/5451613?v=4)](https://github.com/OscarWeijman "OscarWeijman (10 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k20](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)

PHPackages © 2026

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