adachsoft / ai-image-openai
v0.2.0
2026-03-19 06:16 UTC
Requires
- adachsoft/ai-image-contract: ^0.2
- adachsoft/collection: ^3.0
- guzzlehttp/guzzle: ^7.10
Requires (Dev)
- adachsoft/php-code-style: ^0.4.2
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.0
- rector/rector: ^2.3
- vlucas/phpdotenv: ^5.6
This package is not auto-updated.
Last update: 2026-03-20 03:46:44 UTC
README
OpenAI adapter for the adachsoft/ai-image-contract package.
Overview
This package provides an ImageGeneratorInterface implementation backed by the OpenAI Images API.
It maps the generic AI image contract to OpenAI image generation requests and returns contract-compatible responses.
Installation
composer require adachsoft/ai-image-openai
Usage
use AdachSoft\AiImageContract\Collections\ImageInputCollection;
use AdachSoft\AiImageContract\Models\GenerationRequest;
use AdachSoft\AiImageContract\ValueObjects\ImageSize;
use AdachSoft\AiImageContract\ValueObjects\Prompt;
use AdachSoft\AiImageOpenai\OpenAiImageGenerator;
use GuzzleHttp\Client;
$generator = new OpenAiImageGenerator(
new Client(),
'your-openai-api-key',
);
$response = $generator->generate(new GenerationRequest(
prompt: new Prompt('A simple red square on a white background'),
imageInputs: new ImageInputCollection([]),
size: new ImageSize(1024, 1024),
options: [
'model' => 'dall-e-3',
'quality' => 'hd',
'style' => 'natural',
],
));
Supported contract features
- Text-to-image generation through
ImageGeneratorInterface - Contract-compatible
GenerationRequestinput - Contract-compatible
ImageResponseoutput withGeneratedImageCollection - OpenAI options passed through
GenerationRequest::options:modelqualitystyle
Current limitations
The underlying OpenAI DALL-E integration used by this adapter does not support all contract capabilities.
imageInputsare not supported and result inFeatureNotSupportedException- The adapter currently requests a single output image
- The response format is URL-based
This means newer contract concepts such as image-to-image and typed image inputs are recognized by the contract, but are intentionally rejected by this adapter.
Testing
vendor/bin/phpunit
vendor/bin/phpstan analyse src
vendor/bin/phpstan analyse tests
vendor/bin/rector process src --dry-run
vendor/bin/rector process tests --dry-run