[Responses] Support Image Generation Tool
- [ ] Support Image Generation Tool - https://platform.openai.com/docs/guides/image-generation?image-generation-model=gpt-image-1#generate-images
It looks like a normal responses request, but maybe the SDK doesn't support chasing down the image(s) via type "image_generation_call". Could it be worked around using the existing implementation? Looks like it.
Its more we don't yet support that tool type response so its missing from SDK as unparsed. Since the Responses API is pretty complex I want to support a more fluent setup as well. So instead of passing a large array you do with ->withImageGeneration()->asBackground(foo) etc
I noted that the Python SDK has a separate method altogether:
result = client.images.generate(
prompt = prompt,
model = "gpt-image-1",
size = image_size,
quality = image_quality,
output_format = "png"
)
image_base64 = result.data[0].b64_json
We do support that one through the images routes - https://github.com/openai-php/client/blob/199d23715ae9568307bbc2d68e24787cb78b3cca/src/Resources/Images.php#L25. This ticket is supporting that same level of behavior but through the Responses API - which has evolved to do basically do everything all the specialized endpoints used to do.
Understood. I thought only Dall-E used that one.
The image method works, but as GPT Image 1 takes so much time without a known way to take back control, I had to extend default_socket_timeout (now 240).
Maybe Responses has a queue approach to avoid this.
To be fair, it feels (judging from the OpenAI documentation) that this should be part of the CreateResponse.php from Responses:
openai-php/client/src/Responses/Responses/CreateResponse.php:120
$tools = array_map(
fn (array $tool): ComputerUseTool|FileSearchTool|FunctionTool|WebSearchTool => match ($tool['type']) {
'file_search' => FileSearchTool::from($tool),
'web_search_preview', 'web_search_preview_2025_03_11' => WebSearchTool::from($tool),
'function' => FunctionTool::from($tool),
'computer_use_preview' => ComputerUseTool::from($tool),
},
$attributes['tools'],
)
The error, at this time, is a simple unhandled match case:
Unhandled match case 'image_generatio...'
Called with the following:
[{"type":"image_generation","background":"auto","moderation":"auto","n":1,"output_compression":100,"output_format":"png","quality":"auto","size":"auto"}]
I am creating a Agent Swarm factory that has an Agent specialized in generation images. As such, I only call the endpoint with these mere attributes:
[
'model' => 'gpt-4.1-mini',
'tools' => [
[
'type' => 'image_generation',
]
]
]
That was my understanding. Responses API just gained a bunch of new tools (image gen, summary, mcp, etc). Those were all those tickets I seeded into backlog.
Excellent. Looks like they might be tweaking it after the release of the Responses API compatibility with gpt-image-1.
https://platform.openai.com/docs/guides/image-generation?image-generation-model=gpt-image-1#model-comparison