opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Avoid implicit model/provider fallback for image generation

Open sukirman1901 opened this issue 1 week ago • 1 comments

Feature hasn't been suggested before.

  • [x] I searched existing issues and did not find the same image-generation model selection request.

Describe the enhancement you want to request

Please avoid automatically switching image generation to a different model or provider without an explicit user choice.

In OpenCode v2.4.1 (installed using curl on macOS), I selected an OpenAI chat model and asked the agent to generate an image. The generate_image call did not specify a model. It selected opencode/minimax-h3-image and failed with:

Insufficient balance. This request is pay-as-you-go, billed to OpenCode Models credits.

The job reported its selected model after starting, but I had not explicitly selected that separate provider for image generation. This was one observed request; I am not claiming a charge occurred.

Steps to reproduce the selection behavior:

  1. Select a chat model whose provider has no available image model.
  2. Have another provider with an image model available.
  3. Invoke generate_image without its model parameter or a configured image model.
  4. Observe that it selects a different provider automatically.

In packages/core/src/tool/plugin/image-generate.ts, defaultModel prefers the session provider and otherwise returns the first available image model. Invalid configured image defaults can also fall back to another model.

Proposed behavior:

  • Honor an explicitly selected image model or configured image default.
  • Otherwise use the selected session model only if the image-generation integration supports it.
  • If the selection is unsupported or unavailable, explain that and ask the user to choose an image model rather than switching automatically.
  • Do not imply that a chat model necessarily supports the separate image-generation API.

A local patch based on tag v2.4.1 implements strict selection, with 15 focused tests passing. The repository check also passed, with lint warnings. I am requesting maintainer feedback on the intended behavior before opening an implementation PR, as required by the contribution guide.

sukirman1901 avatar Nov 24 '26 03:11 sukirman1901

Thanks for the clear write-up, and for asking before opening a PR.

You're asking for generate_image to stop switching to another model or provider on its own. It would use only an explicitly chosen image model, the configured experimental.image_generate model, or the session's provider if that provider has an image model. Otherwise it would fail and ask you to choose one.

The current fallback is intended and documented. The config docs say that when the configured model isn't available or can't handle a request, OpenCode picks another image model automatically. As you found, defaultModel uses the newest image model from the session's provider, otherwise the newest available one. So I've filed this as a feature request to change that design. Maintainers will consider it, and they can give feedback on the behaviour you propose.

Related issues:

  • #64499: opencode/minimax-h3-image failing with "Model is unavailable"
  • #60410: a project config's experimental block hides global experimental options, which can stop a globally configured image model from being used

opencodejr[bot] avatar Nov 24 '26 03:11 opencodejr[bot]