imagen_generate tool crashes with validation error: expected string, received object
Environment
- OpenCode Version: 1.0.125
- Platform: macOS (Darwin)
- Installation Method: Homebrew
Bug Description
The imagen_generate tool consistently crashes with a validation error whenever it is invoked, making image generation functionality completely unusable.
Error Message
Tool execution aborted
[
{
"code": "invalid_union",
"errors": [
[
{
"expected": "string",
"code": "invalid_type",
"path": ["state", "output"],
"message": "Invalid input: expected string, received object"
}
],
[
{
"expected": "object",
"code": "invalid_type",
"path": ["part"],
"message": "Invalid input: expected object, received undefined"
},
{
"expected": "string",
"code": "invalid_type",
"path": ["delta"],
"message": "Invalid input: expected string, received undefined"
}
]
],
"path": [],
"message": "Invalid input"
}
]
Steps to Reproduce
- Call the
imagen_generatetool with any parameters - Example:
imagen_generate [prompt=A simple red apple on a white background, quality=flash, num_images=1, auto_preview=false] - Observe the validation error and OpenCode crash
Root Cause
The imagen_generate tool is returning a structured object (containing image metadata, cost tracking, etc.) when OpenCode's tool validation layer expects a simple string message in the state.output field.
Evidence That Generation Works
Despite the error, images ARE successfully generated and saved to:
-
~/.config/opencode/nano-banana/images/YYYY-MM-DD/ - Cost tracking is functional and updates
config.json - Image files (PNG/JPG) are created correctly
This indicates the underlying nano-banana functionality works correctly, but the tool wrapper's output format is incompatible with OpenCode's validation schema.
Attempted Workarounds (All Failed)
- Removed all config files
- Created minimal/empty config
- Disabled
auto_preview - Disabled
confirm_before_generate - Disabled
show_cost_in_summary - Disabled
save_json_sidecar - Set
terminal_protocolto "none" - Separated cost tracking to external file
- Made config read-only
- Removed entire nano-banana directory
None of these configuration changes resolved the issue.
Expected Behavior
The imagen_generate tool should return a simple string message (e.g., "Image generated successfully at /path/to/image.png") instead of a structured object.
Actual Behavior
The tool returns a complex object structure that fails OpenCode's output validation, causing the entire tool execution to abort.
Impact
- The
imagen_generatetool is completely unusable in OpenCode v1.0.125 - Users cannot generate images through the OpenCode interface
- This breaks the nano-banana subagent functionality
Suggested Fix
The imagen_generate tool wrapper should either:
- Convert its output to a simple string message before returning
- Update OpenCode's tool validation schema to accept object outputs
- Separate the metadata/tracking from the user-facing output message
Additional Context
The config file at ~/.config/opencode/nano-banana/config.json gets auto-generated and updated with cost tracking data, suggesting the tool is executing but failing at the output validation stage.
This issue might be a duplicate of or related to existing issues. Please check:
- #4357: Tool argument descriptions lost in schema conversion (related to tool schema issues)
Additionally, this appears to be a unique issue specific to the imagen_generate tool wrapper and its output format validation. If you haven't already, please check:
- The nano-banana tool's output format compliance with OpenCode's validation schema
- Whether other custom tools with structured outputs experience similar validation errors
Feel free to ignore if none of these address your specific case.
What is this imagen_generate tool?
google's image generation tool