{"record":{"id":"0bf617690263ec81","repo":"chatboxai/chatbox","slug":"provider-doesnt-support-image-generation","errorCode":null,"errorMessage":"Provider doesnt support image generation","messagePattern":"Provider doesnt support image generation","errorType":"exception","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"src/shared/models/abstract-ai-sdk.ts","lineNumber":431,"sourceCode":"        () => {}\n      )\n      await streamIterator.return?.().catch(() => {})\n    }\n  }\n\n  public async paint(\n    params: {\n      prompt: string\n      images?: { imageUrl: string }[]\n      num: number\n      aspectRatio?: string\n    },\n    signal?: AbortSignal,\n    callback?: (picBase64: string) => void | Promise<void>\n  ): Promise<string[]> {\n    const imageModel = this.getImageModel()\n    if (!imageModel) {\n      throw new ApiError('Provider doesnt support image generation')\n    }\n    const result = await generateImage({\n      model: imageModel,\n      prompt: params.prompt,\n      // images 暂时不支持\n      n: params.num,\n      abortSignal: signal,\n      // Image generation is billable; network-error retries could double-charge.\n      maxRetries: 0,\n    })\n    const dataUrls = result.images.map((image) => `data:${image.mediaType};base64,${image.base64}`)\n    for (const dataUrl of dataUrls) {\n      await callback?.(dataUrl)\n    }\n    return dataUrls\n  }\n\n  /**","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/shared/models/abstract-ai-sdk.ts#L413-L449","documentation":"Thrown by AbstractAISDK.paint when this.getImageModel() returns a falsy value — the current provider configuration exposes no image-generation model to the AI SDK. The check happens before generateImage is called, so no provider request is attempted; this is a capability-mismatch error, not a network error.","triggerScenarios":"paint() is invoked (image generation requested) on a provider whose getImageModel() returns undefined — e.g. a chat-only provider, a provider whose config doesn't declare an image model, or a provider type for which image generation isn't implemented in this SDK subclass.","commonSituations":"User picked a text-only model (e.g. a generic OpenAI chat model) and clicked 'generate image'; provider config missing the imageModel field; model id resolves to a chat model but the UI offered the paint action; a custom provider that doesn't expose DALL·E/Imagen-style endpoints.","solutions":["Switch to a provider+model that supports image generation (e.g. OpenAI gpt-image, a DALL·E model, Google Imagen) before invoking paint.","If you control the provider config, populate the imageModel field / implement getImageModel() to return a valid SDK image model.","In the UI, gate the 'generate image' control on whether the active provider exposes an image model (call getImageModel() to enable/disable the button).","Catch this ApiError and show the user a targeted 'this model cannot generate images' message rather than a generic failure."],"exampleFix":"// before\nconst imageModel = this.getImageModel()\nif (!imageModel) {\n  throw new ApiError('Provider doesnt support image generation')\n}\n// after — include the provider/model id for actionable UX\nconst imageModel = this.getImageModel()\nif (!imageModel) {\n  throw new ApiError(`Provider ${this.name} (${this.options.model.modelId}) does not support image generation`)\n}","handlingStrategy":"type-guard","validationCode":"// Before calling paint(), confirm the provider exposes an image model.\nfunction providerCanPaint(sdk: AbstractAISDK): boolean {\n  return Boolean(sdk.getImageModel())\n}\nif (!providerCanPaint(sdk)) {\n  showUser('This model cannot generate images. Pick an image-capable model.')\n  return\n}","typeGuard":"function supportsImageGeneration(sdk: { getImageModel(): unknown }): boolean {\n  return Boolean(sdk.getImageModel())\n}","tryCatchPattern":"try {\n  await sdk.paint({ prompt, num })\n} catch (e) {\n  if (e instanceof ApiError && /doesn't support image generation/i.test(e.message)) {\n    promptUserToSelectImageModel()\n    return\n  }\n  throw e\n}","preventionTips":["Gate the 'generate image' UI action on getImageModel() truthiness so users never trigger this error.","When building a custom provider, populate imageModel or override getImageModel() if image gen is supported.","Show model capability badges in the model picker so users can tell which models support images."],"tags":["image-generation","provider-capability","config","ai-sdk"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}