Menu

OpenCode Experimental Image Generation Configuration: A Complete Setup Guide

OpenCode's experimental image generation feature lets AI coding agents create and edit images directly within your development workflow. As of version 2.2.2, released in late October 2026, the capability is enabled by default whenever a connected provider supports image models. Configuration centers on two primary settings: enabling the feature via experimental.imagegenerate in your opencode.json file, and specifying a preferred model through experimental.imagegenerate.model. Supported providers include OpenAI's GPT Image 2, MiniMax, Meta Muse, and any OpenAI-compatible image API endpoint.

How OpenCode Image Generation Works

The image generation system functions as a tool that agents can invoke during a session. When a user requests an image—whether a UI mockup, a diagram, or an illustration—the agent routes the prompt to the configured image model, generates the output in the background, and saves the result to the project's .opencode/generated-images/ directory. From there, the image becomes part of the session's media context and can be referenced in subsequent messages or fed back into the model for iterative refinement.

The feature progressed through several rapid iterations. In version 2.2.0, OpenCode introduced experimental image and decision generation API endpoints for plugins and the SDK. Version 2.2.1 added explicit opt-in for experimental.imagegenerate along with support for GPT Image 2, MiniMax, and Meta Muse. Version 2.2.2 then removed the opt-in requirement entirely: agents can now use experimental.imagegenerate without any additional configuration, provided an image-capable provider is connected.

Behind the scenes, image generation requests run as background jobs. OpenCode associates generation notices with the correct background job so that progress and completion are surfaced in the session timeline. If a session is forked or imported, generated media is preserved automatically, ensuring continuity across workflow branches.

Provider Configuration for Image Generation

The first step in setting up image generation is ensuring a compatible provider is connected and properly configured. OpenCode supports multiple provider types, each with its own configuration block inside opencode.json.

For OpenAI-based providers, the configuration follows a standard pattern. A minimal working example for an OpenAI-compatible image API looks like this:

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"options": {
"baseURL": "https://your-image-api.endpoint",
"apiKey": "your-api-key"
},
"models": {
"gpt-image-2": {
"limit": {
"context": 128000,
"input": 128000,
"output": 32000
},
"options": {
"imageApi": "openai-compatible",
"defaultForImageGeneration": true
}
}
}
}
}
}

The imageApi option instructs OpenCode to route image generation requests to that model. The defaultForImageGeneration marker designates which model should be used when the agent invokes image generation without specifying a particular model. According to the OpenCode documentation, the new provider model markers take precedence over the older top-level image_model field;if no marker is explicitly set to true, the system falls back to the legacy field.

For providers accessed through OpenCode Go—the $10/month subscription service for open-source coding models—image generation is available through supported Go models. The Go subscription includes models like MiniMax M3, MiniMax M2.7, and Muse Spark variants, some of which carry image generation capabilities. Usage limits and reset times are displayed directly in the TUI, with links to the account page for managing quotas.

Amazon Bedrock users can layer image generation onto their existing Bedrock configuration by specifying region, profile, and endpoint options alongside the standard provider block. The Bedrock endpoint field serves as an alias for the generic baseURL option.

Setting the Preferred Image Model

Once a provider is connected, OpenCode determines which model handles image generation through the experimental.image_generate.model setting. This top-level configuration key accepts a model identifier string that matches one of the models declared in your provider block.

{
"$schema": "https://opencode.ai/config.json",
"experimental": {
"image_generate": {
"model": "openai/gpt-image-2"
}
}
}

If this field is omitted, OpenCode scans connected providers for a model with defaultForImageGeneration set to true. In the absence of both a configured model and a default marker, the feature remains available but may produce unpredictable routing behavior. The official guidance recommends explicitly setting the model to avoid ambiguity, particularly in multi-provider environments where multiple image-capable models are connected simultaneously.

The experimental.image_generate block also accepts additional provider-specific options, though the documentation notes that these are subject to change as the feature moves toward stabilization. For now, the model selector is the primary knob most teams need to adjust.

Enabling Image Generation for Agents and Workflows

Image generation integrates with OpenCode's agent architecture. Any agent—whether the default build agent, a custom agent defined in opencode.json, or a markdown-based agent in .opencode/agents/—can invoke the image_generate tool if the feature is enabled globally.

Custom agents that should have access to image generation do not require per-agent configuration. However, agents with restricted tool sets need explicit permission. For example, a review-only agent that disables file modification tools like write and edit would still be able to generate images because image_generate operates through the background job system rather than the file system tool set.

For teams using the goal-driven workflow introduced in version 2.2.1, image generation can be triggered as part of a sustained task. The /goal command allows an agent to work continuously, self-review progress, and invoke tools including image generation without repeated user prompting. This proves especially useful for multi-step design workflows where an agent generates a series of UI mockups, evaluates each against a specification, and iterates.

The desktop application surfaces image generation results in the timeline alongside other agent actions. Generated images appear as media attachments that can be dragged into subsequent prompts for refinement. The TUI provides equivalent functionality through session history and media preview.

Image Attachment and Resolution Controls

Before any image reaches a model—whether as a generated output being fed back for iteration or as a user-provided reference—OpenCode normalizes the attachment. The default limits cap images at 2000 by 2000 pixels and 5,242,880 base64 bytes. Images exceeding these thresholds are resized automatically.

These limits are configurable through the attachment.image block:

{
"$schema": "https://opencode.ai/config.json",
"attachment": {
"image": {
"auto_resize": true,
"max_width": 2000,
"max_height": 2000,
"max_base64_bytes": 5242880
}
}
}

Setting autoresize to false causes OpenCode to reject oversized images outright rather than scaling them down. The maxbase64_bytes value refers to the encoded payload size, not the raw file size on disk. If an image still exceeds limits after resizing, OpenCode either omits oversized tool-result images from the context or surfaces an image size error for user-provided files.

These controls are relevant to image generation workflows because outputs are often large by default. A generated image that exceeds the attachment limits will be silently resized when fed back into the model, potentially losing detail. Teams working with high-resolution outputs should adjust the attachment limits upward to preserve fidelity, provided their provider supports the larger payloads.

SDK and Plugin Integration

The image generation capability extends beyond the TUI and desktop interfaces. OpenCode's SDK exposes experimental image generation APIs that plugin authors and custom tooling can consume. Version 2.2.0 added image and decision generation entrypoints for catalog providers, and version 2.2.1 extended the SDK with scheduling interfaces for timed prompts.

Plugins built on the OpenCode plugin system—powered by OpenTUI 0.7 or later—can integrate image generation into custom renderables and workflows. The SDK's Promise API, accessible through @opencode/ai, provides the primary interface for programmatic image generation. Developers using the Effect API should import from @opencode/ai/effect instead, following the package restructuring introduced in version 2.2.0.

The unofficial OpenCode UI extension for VS Code also surfaces image generation within the IDE. When the underlying OpenCode backend is configured with a compatible provider, the extension allows users to generate images from the chat interface, iterate on existing outputs, and save results directly to the project. The extension reads the same opencode.json configuration, meaning no separate setup is required beyond what has already been described.

FAQ

Does image generation require a paid subscription?

Not necessarily. If you connect a provider with image capabilities using your own API key—such as an OpenAI account with GPT Image 2 access—you pay that provider directly. OpenCode Go subscribers at $10/month also gain access to select image-capable models like MiniMax and Muse Spark variants, subject to Go usage limits. The OpenCode tool itself does not charge for the feature.

Can I use a self-hosted or local image model?

Yes, provided the model exposes an OpenAI-compatible API endpoint. Configure it as a custom provider in opencode.json with imageApi set to "openai-compatible" and defaultForImageGeneration set to true. Performance and output quality will depend on the local model's capabilities.

Where are generated images saved?

All generated images land in the .opencode/generated-images/ directory within the current project. This path is not currently configurable. Images persist across session forks and imports, and they can be referenced in subsequent prompts or committed to version control like any other project asset.

What happens if my provider hits a rate limit during generation?

OpenCode v2.2.1 introduced improved rate-limit handling that correctly retries provider throttling without misreporting it as a context overflow error. In the TUI, usage-limit messages now display the reset time and a link to the account page. The desktop interface provides equivalent feedback through the error UI and activity tray.