Image generation fails with custom OpenAI-compatible baseUrl: response_format is never sent, so the endpoint returns url and the app only accepts b64_json

Author: entergamezCreated Sep 30, 2026Updated Sep 30, 2026

Summary

generateOpenAIImage() never sends response_format, so an OpenAI-compatible endpoint returns the default { data: [{ url }] } payload — which the same function then rejects, because it only accepts b64_json or a url starting with data:.

Result: image generation always fails against any relay/compatible provider that follows the OpenAI Images API default, even though the image was produced successfully server-side.

Environment

  • Open CoDesign 0.2.2 (latest release), macOS / Electron 39.8.10
  • Image generation: provider openai + custom baseUrl (OpenAI-compatible relay), model gpt-image-2, quality high
  • Source: packages/providers/src/images.ts, generateOpenAIImage() (~L107–L162)

Steps to reproduce

  1. Settings → Image generation → provider openai, custom base URL https://<openai-compatible-relay>/v1, model gpt-image-2.
  2. Ask the agent to generate an image.

Expected

Image is generated and returned.

Actual

After ~40 s the tool fails with:

OpenAI image response did not include base64 image data

Log:

[image-generation] provider.request { provider: 'openai', model: 'gpt-image-2', ... }
[image-generation] provider.fail   { message: 'OpenAI image response did not include base64 image data' }

Root cause

The request body is built without response_format:

typescript
const body: Record<string, unknown> = { model, prompt: options.prompt, n: 1 };
if (options.size !== undefined) body['size'] = options.size;
if (options.quality !== undefined) body['quality'] = options.quality;
if (options.outputFormat !== undefined) body['output_format'] = options.outputFormat;
if (options.background !== undefined) body['background'] = options.background;

response_format defaults to url on the Images API, and the response handling only has two valid branches:

typescript
if (typeof first.b64_json === 'string' && first.b64_json.length > 0) { /* ok */ }
if (typeof first.url === 'string' && first.url.trim().startsWith('data:')) { /* ok */ }
throw new CodesignError('OpenAI image response did not include base64 image data', ...);

So plain https://… URLs (the documented OpenAI default) and relative URLs such as /v1/images/<id>/download both fall through to the error.

Evidence

Same endpoint, same key, same model — only difference is the missing parameter:

Without response_format (exactly what the app sends) → HTTP 200 in 90 s, unusable payload:

json
{ "created": 1790000000,
  "data": [ { "revised_prompt": "",
              "url": "/v1/images/01a0f07a-354e-75f4-a78f-d0bddec035ec/download" } ] }

(The url is relative; GET on it returns 404, so this payload is unusable even by a URL-aware client.)

With "response_format": "b64_json" → HTTP 200 in 22 s, usable payload:

json
{ "created": 1790000000,
  "data": [ { "revised_prompt": "", "b64_json": "<1.6 MB base64>" } ] }

Decodes to a valid 1.2 MB PNG (\x89PNG\r\n\x1a\n).

Suggested fix

Send the parameter when talking to a non-default endpoint:

typescript
if (options.baseUrl !== undefined && options.baseUrl !== DEFAULT_OPENAI_BASE_URL) {
  body['response_format'] = 'b64_json';
}

The baseUrl guard matters: real gpt-image-* on api.openai.com rejects response_format (HTTP 400 Unknown parameter: 'response_format'), so it must not be sent on the default path. See nexu-io/open-design#5727 and iOfficeAI/AionUi@84adb54.

Complementary/alternative fix: accept http(s):// URLs in the url branch (joining relative URLs against options.baseUrl) and fetch them — that would also cover relays that ignore response_format entirely.

Local workaround applied

Since 0.2.2 ships the bug, I unpacked app.asar and applied the guard above; image generation now succeeds end-to-end (provider.ok, mimeType: image/png, ~116 s). Obviously reverted by any app update — hence this issue.


Related (not fixed by the above): generateOpenRouterImage() posts to joinEndpoint(baseUrl, 'chat/completions'), which makes OpenRouter return:

HTTP 404 openai/gpt-image-2 is an image generation model and cannot be used
with the chat/completions endpoint. Use the /api/v1/images endpoint instead.

Worth a separate issue/PR if it is still unfixed — happy to file it.

Source: OpenCoworkAI/open-codesign