imagegen
v0.1.0 · compiled with katari 0.1.0
Overview
from the package READMEimagegen — edit images with the Gemini image model, as a Katari tool
A single module, imagegen, plus its FFI sidecar src/imagegen.ts: hand it an image file and an
instruction, get an edited image file back. The API call lives in the sidecar because the response
image must become a blob — the sidecar uploads it over the blob side channel and returns the handle,
which lifts into a file for the caller.
imagegen.edit_image(image, instruction)— the tool: e.g. "make the sky a sunset", "remove the text". Returns a new imagefilethe caller can view or post.imagegen.provider(api_key = ..., model? = "gemini-2.5-flash-image")— provides the image-model API key (and model id) for the extent of a continuation.
Secrets / env
GEMINI_API_KEY— a Google Generative Language API key (the image model is served there). Store it in the runtime:katari env set GEMINI_API_KEY --secret. It is astring of private, passed to the sidecar and never surfaced elsewhere. (The same key theai.geminiprovider uses.)
Sidecar dependencies
src/imagegen.ts imports @katari-lang/port (the image API is called with the built-in fetch).
It is declared in package.json; run pnpm install (or npm install) in this package so
katari apply can bundle the sidecar. (A pure-Katari consumer that never applies this package does
not need it.)
Usage
import imagegen
agent recolor(image: file) -> file with io {
use imagegen.provider(api_key = env.get_secret(key = "GEMINI_API_KEY"))
imagegen.edit_image(image = image, instruction = "make the sky a sunset")
}Hand imagegen.edit_image to an AI loop's tool list to let the model edit images on its own.
imagegen
5 declarationsget_imagegen_key#
requestrequest get_imagegen_key() -> string of privateThe image-model API key capability (provided once at the root by use imagegen.provider(...)).
Returns
Wire view (JSON Schema)
provider#
agentagent provider[R, effect E](api_key: string of private, model: string ?= "gemini-2.5-flash-image", continuation: agent(value: null) -> R with {...E, get_imagegen_key, get_imagegen_model}) -> R with EProvide the image-model API key (and model id) for the extent of the continuation.
Generics
Parameters
Returns
Effects
Inferred type
agent(api_key: string of private, continuation: agent(value: null) -> T0 with get_imagegen_key | get_imagegen_model | E1, model?: string) -> T0 with E1
Wire view — the wire shape is fixed at the call site, where the generic parameters are instantiated.
get_imagegen_model#
requestrequest get_imagegen_model() -> stringThe image model id capability (defaulted by the provider; override via its model).
Returns
Wire view (JSON Schema)
gemini_image_edit#
external agentexternal agent gemini_image_edit(image: file, instruction: string, model: string, api_key: string of private) -> fileRun one image edit in the sidecar: POST the image + instruction to the Gemini image model, upload the returned image as a blob, hand back its file.
Parameters
Returns
Wire view (JSON Schema)
edit_image#
agentagent edit_image(image: file, instruction: string) -> fileTool: edit an image with an instruction (e.g. "make the sky a sunset", "remove the text"). Pass the image's handle object — a bare {"$katari_ref": "<id>"} suffices; the result is a new image file you can view (view_image) or post (send_files).
Parameters
Returns
Inferred type
agent(image: file, instruction: string) -> file with get_imagegen_key | get_imagegen_model | io