adachsoft / ai-image-openai
Requires
- adachsoft/ai-image-contract: ^0.3
- 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
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-07 08:03:00 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
Plugin
This package declares the openai plugin for automatic discovery by intermediary libraries that inspect Composer plugin declarations.
- Plugin ID:
openai - Plugin class:
AdachSoft\AiImageOpenai\OpenAiImagePlugin - Required parameter:
api_key
use AdachSoft\AiImageContract\Plugins\PluginParametersDto;
use AdachSoft\AiImageOpenai\OpenAiImagePlugin;
$generator = (new OpenAiImagePlugin())->create(
new PluginParametersDto(['api_key' => 'your-openai-api-key']),
);
Usage
use AdachSoft\AiImageContract\Collections\ImageInputVoCollection;
use AdachSoft\AiImageContract\Models\GenerationRequestDto;
use AdachSoft\AiImageContract\ValueObjects\ImageSizeVo;
use AdachSoft\AiImageContract\ValueObjects\PromptVo;
use AdachSoft\AiImageOpenai\OpenAiImageGenerator;
use GuzzleHttp\Client;
$generator = new OpenAiImageGenerator(
new Client(),
'your-openai-api-key',
);
$response = $generator->generate(new GenerationRequestDto(
prompt: new PromptVo('A simple red square on a white background'),
imageInputs: new ImageInputVoCollection([]),
size: new ImageSizeVo(1024, 1024),
options: [
'model' => 'gpt-image-2.5-sunburst',
'quality' => 'high',
],
));
Supported contract features
- Text-to-image generation through
ImageGeneratorInterface - Contract-compatible
GenerationRequestDtoinput - Contract-compatible
ImageResponseDtooutput withGeneratedImageCollection - OpenAI options passed through
GenerationRequestDto::options:model(defaults togpt-image-2.5-sunburst)quality(low,medium,high,xhigh,max, orauto; legacystandardandhdvalues map tomediumandhigh)
Current limitations
The OpenAI Images API integration used by this adapter does not support all contract capabilities.
imageInputsare not supported by this adapter and result inFeatureNotSupportedException- The adapter currently requests a single output image
- GPT Image responses are base64-encoded and exposed as
GeneratedImageDto::b64Json; URL responses are also preserved when returned by the API
Image-to-image generation 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