Image Generation
Use this skill to create an image from a text description with AI image
generation, then save it locally and display it to the user.
Setup
Before the first use, ensure the agent-gw Python SDK (version 0.2.6 or newer) is installed. This checks the current environment and installs or upgrades it only when needed:
python3 scripts/image_generation_tool.py ensure-deps
The SDK needs an API key from api_key=..., KIMI_API_KEY, or
~/.kimi/agent-gw.json.
Parameters
description (required): detailed text description of the image to generate.
ratio: one of 1:1, 3:2, 2:3, 16:9, 9:16. Default 1:1.
resolution: one of 1K, 2K, 4K. Default 1K.
Opaque background supports only these combinations:
1K: 1:1 (1024x1024), 3:2 (1536x1024), 2:3 (1024x1536);
2K: 1:1 (2048x2048), 16:9 (2048x1152);
4K: 16:9 (3840x2160), 9:16 (2160x3840).
Transparent background only supports 1K with 1:1, 3:2, 2:3.
background: opaque (default) or transparent.
reference_image: public URL(s) that guide the generation. Repeat
--reference-image for multiple. The gateway only accepts public URLs, so a
local image must be converted with image-to-url first (see "Reference
images" below); passing a local path to generate is rejected.
output (required): local output path ending in .jpg, .jpeg, or .png.
Transparent background must use .png.
Workflow
- Build a detailed, descriptive
description from the user's request: include
subject, style, composition, lighting, colors, and mood.
- Choose
ratio, resolution, and background. Enforce the supported
combinations. For opaque images: 1K allows 1:1 / 3:2 / 2:3; 2K
allows 1:1 / 16:9; 4K allows 16:9 / 9:16. Transparent only allows
1:1 / 3:2 / 2:3 ratios, 1K resolution, and PNG output.
- Pick an
output file path with a matching extension.
- If the user supplies reference images, they must be public URLs. For any
local image (a file on the execution environment, whether that is a sandbox
or the client's local machine), first run the
image-to-url command to
upload it and get a public URL, then pass that URL with --reference-image.
The gateway only accepts public reference URLs; passing a local path to
generate is rejected.
- Run the
generate command (see "Script"). It calls generate_image on the
gateway, reads media.url / media.mime_type from the response, and
downloads the image to your output path with curl (the extension is
corrected to match mime_type).
- If the call fails, explain the failure reason from the printed error. Do not
invent an image or a local path.
- On success, the script prints the saved file path. Then display the image
to the user by calling the
readFile tool on that path. Reading the image
to show it is the model's job, not this plugin's work.
Reference images
The plugin runs in an execution environment that may be a sandbox or the
client's local machine. Either way, the gateway's reference_image_urls must be
public URLs, so any local reference image has to be converted first. This is an
explicit, separate step — generate does not accept local paths.
Convert each local image to a public URL with image-to-url (it uploads the
file via the agent-gw upload_storage API and returns the public signed_url),
then pass the printed public URL to generate with --reference-image:
python3 scripts/image_generation_tool.py image-to-url --image-path /path/to/local.png
Script
Use the bundled script from the plugin directory.
Generate an image:
python3 scripts/image_generation_tool.py generate \
--description "A serene mountain lake at sunrise, soft golden light, mirror reflection, ultra detailed" \
--ratio "16:9" \
--resolution "2K" \
--background "opaque" \
--output "/path/to/output.png"
Convert a local reference image to a public URL first, then pass that URL:
# Step 1: upload the local image, capture the printed public URL
python3 scripts/image_generation_tool.py image-to-url --image-path /path/to/local_ref.png
# Step 2: pass public URLs (only) to generate
python3 scripts/image_generation_tool.py generate \
--description "Same character in a snowy forest, cinematic" \
--ratio "3:2" \
--reference-image "https://example.com/ref1.jpg" \
--reference-image "https://<public-url-from-step-1>" \
--output "/path/to/output.jpg"
The script:
generate accepts only public --reference-image URLs and sends them as
reference_image_urls; a local path is rejected with a hint to use
image-to-url
image-to-url uploads a local image via the agent-gw upload_storage API and
prints the resulting public signed_url
- sends
{"description", "ratio", "resolution", "background", "reference_image_urls"} to the gateway generate_image API
- reads the generated
media.url and media.mime_type from the response
- downloads the image to the
--output path with curl, naming the file by
mime_type (png/jpg)
- prints the saved path and a reminder to display it with
readFile
generate_image response shape (resp.json()):
{
"media": {
"url": str, # public URL of the generated image
"mime_type": str, # e.g. "image/png" or "image/jpeg"
}
}
This skill uses the agent-gw Python SDK: client.tools.generate_image(...)
for generation and client.upload_storage(...) (which returns a public
signed_url) to turn a local reference image into a public URL.
1---2name: image-generation3description: Create an image based on a text description using AI image generation. ### Features: - Generate high-quality images from text prompts - Support conditional opaque image size combinations: 1K supports 1:1, 3:2, 2:3; 2K supports 1:1, 16:9; 4K supports 16:9, 9:16. - Support multiple resolutions: 1K, 2K, 4K. Default is 1K. - If the background is transparent, only supports 1:1, 3:2, 2:3 ratios and 1K resolution. - Support background color: opaque (default) or transparent - Support JPG, JPEG, PNG format output with high resolution (only support png for transparent) ### Usage Guidelines: - Provide detailed, descriptive prompts for better results - Include specific details about style, composition, colors, and mood - Use clear, descriptive language for best image quality - Specify output file path with .jpg, .jpeg, .png extension (only support png for transparent) ### Best Practices: - Be specific about visual elements (lighting, perspective, style) - Include artistic style references when desired - Describe composit4---56# Image Generation78Use this skill to create an image from a text description with AI image9generation, then save it locally and display it to the user.1011## Setup1213Before the first use, ensure the agent-gw Python SDK (version 0.2.6 or newer) is installed. This checks the current environment and installs or upgrades it only when needed:1415```bash16python3 scripts/image_generation_tool.py ensure-deps17```1819The SDK needs an API key from `api_key=...`, `KIMI_API_KEY`, or20`~/.kimi/agent-gw.json`.2122## Parameters2324- `description` (required): detailed text description of the image to generate.25- `ratio`: one of `1:1, 3:2, 2:3, 16:9, 9:16`. Default `1:1`.26- `resolution`: one of `1K, 2K, 4K`. Default `1K`.27 Opaque background supports only these combinations:28 `1K`: `1:1` (`1024x1024`), `3:2` (`1536x1024`), `2:3` (`1024x1536`);29 `2K`: `1:1` (`2048x2048`), `16:9` (`2048x1152`);30 `4K`: `16:9` (`3840x2160`), `9:16` (`2160x3840`).31 Transparent background only supports `1K` with `1:1, 3:2, 2:3`.32- `background`: `opaque` (default) or `transparent`.33- `reference_image`: public URL(s) that guide the generation. Repeat34 `--reference-image` for multiple. The gateway only accepts public URLs, so a35 local image must be converted with `image-to-url` first (see "Reference36 images" below); passing a local path to `generate` is rejected.37- `output` (required): local output path ending in `.jpg`, `.jpeg`, or `.png`.38 Transparent background must use `.png`.3940## Workflow41421. Build a detailed, descriptive `description` from the user's request: include43 subject, style, composition, lighting, colors, and mood.442. Choose `ratio`, `resolution`, and `background`. Enforce the supported45 combinations. For opaque images: `1K` allows `1:1 / 3:2 / 2:3`; `2K`46 allows `1:1 / 16:9`; `4K` allows `16:9 / 9:16`. Transparent only allows47 `1:1 / 3:2 / 2:3` ratios, `1K` resolution, and PNG output.483. Pick an `output` file path with a matching extension.494. If the user supplies reference images, they must be public URLs. For any50 local image (a file on the execution environment, whether that is a sandbox51 or the client's local machine), first run the `image-to-url` command to52 upload it and get a public URL, then pass that URL with `--reference-image`.53 The gateway only accepts public reference URLs; passing a local path to54 `generate` is rejected.555. Run the `generate` command (see "Script"). It calls `generate_image` on the56 gateway, reads `media.url` / `media.mime_type` from the response, and57 downloads the image to your `output` path with `curl` (the extension is58 corrected to match `mime_type`).596. If the call fails, explain the failure reason from the printed error. Do not60 invent an image or a local path.617. On success, the script prints the saved file path. Then **display the image62 to the user by calling the `readFile` tool on that path**. Reading the image63 to show it is the model's job, not this plugin's work.6465## Reference images6667The plugin runs in an execution environment that may be a sandbox or the68client's local machine. Either way, the gateway's `reference_image_urls` must be69public URLs, so any local reference image has to be converted first. This is an70explicit, separate step — `generate` does **not** accept local paths.7172Convert each local image to a public URL with `image-to-url` (it uploads the73file via the agent-gw `upload_storage` API and returns the public `signed_url`),74then pass the printed public URL to `generate` with `--reference-image`:7576```bash77python3 scripts/image_generation_tool.py image-to-url --image-path /path/to/local.png78```7980## Script8182Use the bundled script from the plugin directory.8384Generate an image:8586```bash87python3 scripts/image_generation_tool.py generate \88 --description "A serene mountain lake at sunrise, soft golden light, mirror reflection, ultra detailed" \89 --ratio "16:9" \90 --resolution "2K" \91 --background "opaque" \92 --output "/path/to/output.png"93```9495Convert a local reference image to a public URL first, then pass that URL:9697```bash98# Step 1: upload the local image, capture the printed public URL99python3 scripts/image_generation_tool.py image-to-url --image-path /path/to/local_ref.png100101# Step 2: pass public URLs (only) to generate102python3 scripts/image_generation_tool.py generate \103 --description "Same character in a snowy forest, cinematic" \104 --ratio "3:2" \105 --reference-image "https://example.com/ref1.jpg" \106 --reference-image "https://<public-url-from-step-1>" \107 --output "/path/to/output.jpg"108```109110The script:111112- `generate` accepts only public `--reference-image` URLs and sends them as113 `reference_image_urls`; a local path is rejected with a hint to use114 `image-to-url`115- `image-to-url` uploads a local image via the agent-gw `upload_storage` API and116 prints the resulting public `signed_url`117- sends `{"description", "ratio", "resolution", "background",118 "reference_image_urls"}` to the gateway `generate_image` API119- reads the generated `media.url` and `media.mime_type` from the response120- downloads the image to the `--output` path with `curl`, naming the file by121 `mime_type` (png/jpg)122- prints the saved path and a reminder to display it with `readFile`123124`generate_image` response shape (`resp.json()`):125126```python127{128 "media": {129 "url": str, # public URL of the generated image130 "mime_type": str, # e.g. "image/png" or "image/jpeg"131 }132}133```134135> This skill uses the agent-gw Python SDK: `client.tools.generate_image(...)`136> for generation and `client.upload_storage(...)` (which returns a public137> `signed_url`) to turn a local reference image into a public URL.