Using JavaScript Agent SDK.
Calling the agent, with stream to true, so I can send tool steps back to client. This works great, but if I add support for image generation via imageGenerationTool, I get the following error when trying to generate an image:
BadRequestError: 400 Streaming must have non-zero partial images.
at APIError.generate (file:///Users/mesh/src/psda/node_modules/@openai/agents-openai/node_modules/openai/core/error.mjs:41:20)
at OpenAI.makeStatusError (file:///Users/mesh/src/psda/node_modules/@openai/agents-openai/node_modules/openai/client.mjs:148:32)
at OpenAI.makeRequest (file:///Users/mesh/src/psda/node_modules/@openai/agents-openai/node_modules/openai/client.mjs:290:30)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async #fetchResponse (file:///Users/mesh/src/psda/node_modules/@openai/agents-openai/dist/openaiResponsesModel.mjs:664:26)
at async OpenAIResponsesModel.getStreamedResponse (file:///Users/mesh/src/psda/node_modules/@openai/agents-openai/dist/openaiResponsesModel.mjs:720:30)
at async #runStreamLoop (file:///Users/mesh/src/psda/node_modules/@openai/agents-core/dist/run.mjs:354:38) {
status: 400,
headers: Headers {
//...
},
error: {
message: 'Streaming must have non-zero partial images.',
type: 'image_generation_user_error',
param: 'tools',
code: null
},
code: null,
param: 'tools',
type: 'image_generation_user_error'
}
If I disable streaming, things work, but then I dont have access to tool updates in realtime.
Is it possible to have an agent generate an image when streaming the response?
Here is the code:
agent = new Agent({
name: "Assistant",
instructions:
"You are a helpful assistant. Remember our conversation history and maintain context about the user's current project.",
model: "gpt-4.1",
mcpServers: [genericMCPServer],
tools:[imageGenerationTool()]
});
//...
const result = await run(agent, thread, {
stream: true,
});
for await (const chunk of result) {
if (chunk.type === "run_item_stream_event") {
let item = chunk.item;
let toolPacket = null;
//...