fixik/openai-client

A PHP client for the OpenAI API with chat, embeddings, images, fine-tuning, Laravel support

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/fixik/openai-client

v1.0.0 2025-12-12 11:36 UTC

This package is auto-updated.

Last update: 2025-12-12 11:37:51 UTC


README

CI Packagist Version Total Downloads Coverage License

A powerful PHP client for the OpenAI API with support for:

  • Chat
  • Embeddings
  • Images
  • Fine-tuning

Installation

composer require fixik/openai-client

Publish config (Laravel):

php artisan vendor:publish --provider="Fixik\OpenAI\Laravel\OpenAIServiceProvider"

Add to .env:

OPENAI_API_KEY=your_key

Usage Example PHP

use Fixik\OpenAI\OpenAIClient;

$apiKey = 'YOUR_OPENAI_API_KEY_HERE';

$openaiClient = new OpenAIClient($apiKey);

$message = "Write a haiku about modern PHP development.";

$openaiClient->chat()->send('gpt-3.5-turbo', $message);
$openaiClient->embeddings()->create('gpt-3.5-turbo', $message);
$openaiClient->fineTune()->create([
    'model' => 'gpt-3.5-turbo',
    'training_file' => 'file-id',
]);
$openaiClient->fineTune()->retrieve($jobId);
$openaiClient->images()->generate($message);

Usage Example Laravel

$message = "Write a haiku about modern PHP development.";

OpenAI::chat()->send('gpt-3.5-turbo', $message);
OpenAI::embeddings()->create('gpt-3.5-turbo', $message);
OpenAI::fineTune()->create([
    'model' => 'gpt-3.5-turbo',
    'training_file' => 'file-id',
]);
OpenAI::fineTune()->retrieve($jobId);
OpenAI::images()->generate($message);

Testing

Run Pest:

./vendor/bin/pest

Static Analyzers

Run PHPStan:

./vendor/bin/phpstan analyse src --level=max

Run Psalm:

./vendor/bin/psalm --no-cache