tools.generate_image module

Generate images on the active GPT/Gemini origin and send them to the channel.

async tools.generate_image.run(prompt, aspect_ratio='16:9', model=None, ctx=None)

Generate an image from a prompt and post it to the current channel.

Entry point for the generate_image tool. A GPT-origin turn first uses native Codex image generation on the beneficiary’s own linked account; a Gemini-origin turn, a sponsored GPT route, or a failed GPT image call uses the existing Gemini path. Shared Gemini-key quota is enforced only when that fallback is actually used. The result is normalised to PNG, uploaded through ctx.adapter.send_file, and recorded in ctx.sent_files.

Dispatched by tool_loader.py, which imports this module and resolves run via getattr(module, "run") to register it under TOOL_NAME (“generate_image”).

Parameters:
  • prompt (str) – Text description of the image to generate.

  • aspect_ratio (str) – Requested aspect ratio (default "16:9"), passed through to _call_gemini_native.

  • model (str | None) – Optional Gemini image model id; defaults are applied downstream.

  • ctx (ToolContext | None) – The current ToolContext; its adapter is required to send the image and its user_id / redis drive quota enforcement. When ctx or ctx.adapter is missing the call returns an error.

Return type:

str

Returns:

A JSON string with success: True plus filename, a result message, and (when available) file_url on success; otherwise a JSON object with an error describing a quota block, an empty result, or a raised exception.