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)]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It only states the basic function without mentioning any behavioral traits: no information about rate limits, authentication requirements, whether it's a synchronous or asynchronous operation, what happens on failure, or what the output format looks like. For a complex tool with 8 parameters, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just 6 words: 'Generates an image from a text prompt'. It's front-loaded with the core purpose and contains no unnecessary words. However, this conciseness comes at the cost of completeness for such a complex tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (8 parameters, 0% schema coverage, no annotations, no output schema), the description is completely inadequate. It doesn't explain what the tool returns, how to interpret results, error conditions, or the purpose of most parameters. For an image generation tool with multiple advanced features like style references and character references, this minimal description fails to provide necessary context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning none of the 8 parameters have descriptions in the schema. The tool description provides no information about any parameters beyond the required 'prompt' field. It doesn't explain what 'model', 'aspect_ratio', 'callback_url', 'image_ref', 'style_ref', 'character_ref', or 'modify_image_ref' do or when to use them. This leaves most parameters completely undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generates an image from a text prompt'. It specifies the verb ('generates'), resource ('image'), and input source ('text prompt'). However, it doesn't differentiate from sibling tools like 'create_generation' or 'upscale_generation', which might have overlapping functionality in image generation workflows.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'create_generation' (which might be for video) or 'upscale_generation' (which might enhance existing images). There's no context about prerequisites, limitations, or typical use cases for this specific image generation tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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