Skip to main content
Glama

generate_image

Create images from text descriptions using AI, with options for aspect ratios, style references, and image modifications.

Instructions

Generates an image from a text prompt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
modelNophoton-1
aspect_ratioNo
callback_urlNo
image_refNo
style_refNo
character_refNo
modify_image_refNo

Implementation Reference

  • The main handler function for the 'generate_image' tool. It validates input using GenerateImageInput schema, makes a POST request to Luma API's /generations/image endpoint, and returns the generated image URL along with details.
    async def generate_image(params: dict) -> str: """Generate an image using the Luma API.""" try: input_data = GenerateImageInput(**params) except Exception as e: error_msg = str(e) if "model" in error_msg: raise ValueError(f"Invalid model: {params.get('model')}") from e elif "aspect_ratio" in error_msg: raise ValueError(f"Invalid aspect ratio: {params.get('aspect_ratio')}") from e raise model_value = input_data.model.value aspect_ratio_value = input_data.aspect_ratio.value if input_data.aspect_ratio else None request_data = input_data.model_dump(exclude_none=True) response = await _make_luma_request("POST", "/generations/image", request_data) if "assets" not in response or "image" not in response["assets"]: raise ValueError("No image URL in API response") output = ["Image generation completed"] output.append(f"Prompt: {input_data.prompt}") output.append(f"Model: {model_value}") if aspect_ratio_value: output.append(f"Aspect ratio: {aspect_ratio_value}") output.append(f"Image URL: {response['assets']['image']}") return "\n".join(output)
  • Pydantic BaseModel defining the input schema for the generate_image tool, including prompt, model, aspect_ratio, and optional references.
    class GenerateImageInput(BaseModel): """ Input parameters for image generation. """ prompt: str model: ImageModel = ImageModel.PHOTON_1 aspect_ratio: Optional[AspectRatio] = None callback_url: Optional[str] = None image_ref: Optional[list[ImageRef]] = None style_ref: Optional[list[ImageRef]] = None character_ref: Optional[dict[str, ImageIdentity]] = None modify_image_ref: Optional[ModifyImageRef] = None
  • Registration of the 'generate_image' tool in the MCP server's list_tools() function, providing name, description, and input schema.
    Tool( name=LumaTools.GENERATE_IMAGE, description="Generates an image from a text prompt", inputSchema=GenerateImageInput.model_json_schema(), ),
  • Dispatch logic in the MCP server's call_tool() function that invokes the generate_image handler when the tool is called.
    case LumaTools.GENERATE_IMAGE: result = await generate_image(arguments) return [TextContent(type="text", text=result)]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bobtista/luma-ai-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server