Skip to main content
Glama

upscale_image

Enhance low-resolution images by increasing their resolution while maintaining quality. Supports 2x or 4x upscaling with different model options for quality or speed.

Instructions

Upscale an image to higher resolution while preserving quality. Use for enhancing low-resolution images.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYesURL of the image to upscale (use upload_file for local images)
scaleNoUpscale factor (2x or 4x)
modelNoUpscaling model. Options: fal-ai/clarity-upscaler (high quality), fal-ai/aura-sr (fast)fal-ai/clarity-upscaler

Implementation Reference

  • The primary handler function for the upscale_image tool. It resolves the model, prepares fal_args with image_url and scale, executes the model via queue_strategy, handles timeouts and errors, extracts the output image URL, and returns a formatted response with the result.
    async def handle_upscale_image( arguments: Dict[str, Any], registry: ModelRegistry, queue_strategy: QueueStrategy, ) -> List[TextContent]: """Handle the upscale_image tool.""" model_input = arguments.get("model", "fal-ai/clarity-upscaler") try: model_id = await registry.resolve_model_id(model_input) except ValueError as e: return [ TextContent( type="text", text=f"❌ {e}. Use list_models to see available options.", ) ] scale = arguments.get("scale", 2) fal_args: Dict[str, Any] = { "image_url": arguments["image_url"], "scale": scale, } logger.info("Starting %dx upscale with %s", scale, model_id) try: result = await asyncio.wait_for( queue_strategy.execute_fast(model_id, fal_args), timeout=120, # Upscaling can take longer ) except asyncio.TimeoutError: logger.error("Upscaling timed out for %s", model_id) return [ TextContent( type="text", text="❌ Upscaling timed out after 120 seconds. Please try again.", ) ] except Exception as e: logger.exception("Upscaling failed: %s", e) return [ TextContent( type="text", text=f"❌ Upscaling failed: {e}", ) ] # Check for error in response if "error" in result: error_msg = result.get("error", "Unknown error") logger.error("Upscaling failed for %s: %s", model_id, error_msg) return [ TextContent( type="text", text=f"❌ Upscaling failed: {error_msg}", ) ] # Extract the result image URL # Clarity upscaler returns {"image": {"url": "..."}} image_data = result.get("image", {}) if isinstance(image_data, dict): output_url = image_data.get("url") else: output_url = result.get("image_url") if not output_url: logger.warning("Upscaling returned no image. Result: %s", result) return [ TextContent( type="text", text="❌ Upscaling completed but no image was returned.", ) ] response = f"🔍 Image upscaled {scale}x successfully!\n\n" response += f"**Result**: {output_url}\n\n" response += f"The image resolution has been increased by {scale}x." return [TextContent(type="text", text=response)]
  • The tool schema definition specifying the input parameters, descriptions, defaults, and requirements for the upscale_image tool.
    Tool( name="upscale_image", description="Upscale an image to higher resolution while preserving quality. Use for enhancing low-resolution images.", inputSchema={ "type": "object", "properties": { "image_url": { "type": "string", "description": "URL of the image to upscale (use upload_file for local images)", }, "scale": { "type": "integer", "default": 2, "enum": [2, 4], "description": "Upscale factor (2x or 4x)", }, "model": { "type": "string", "default": "fal-ai/clarity-upscaler", "description": "Upscaling model. Options: fal-ai/clarity-upscaler (high quality), fal-ai/aura-sr (fast)", }, }, "required": ["image_url"], }, ),
  • Registration of all tool handlers in the TOOL_HANDLERS dictionary, including the mapping of 'upscale_image' to handle_upscale_image. This dictionary is used in the call_tool method to route tool calls to their handlers.
    TOOL_HANDLERS = { # Utility tools (no queue needed) "list_models": handle_list_models, "recommend_model": handle_recommend_model, "get_pricing": handle_get_pricing, "get_usage": handle_get_usage, "upload_file": handle_upload_file, # Image generation tools "generate_image": handle_generate_image, "generate_image_structured": handle_generate_image_structured, "generate_image_from_image": handle_generate_image_from_image, # Image editing tools "remove_background": handle_remove_background, "upscale_image": handle_upscale_image, "edit_image": handle_edit_image, "inpaint_image": handle_inpaint_image, "resize_image": handle_resize_image, "compose_images": handle_compose_images, # Video tools "generate_video": handle_generate_video, "generate_video_from_image": handle_generate_video_from_image, "generate_video_from_video": handle_generate_video_from_video, # Audio tools "generate_music": handle_generate_music, }
  • Import of the handle_upscale_image function from handlers, making it available for registration in TOOL_HANDLERS.
    from fal_mcp_server.handlers import ( handle_compose_images, handle_edit_image, handle_generate_image, handle_generate_image_from_image, handle_generate_image_structured, handle_generate_music, handle_generate_video, handle_generate_video_from_image, handle_generate_video_from_video, handle_get_pricing, handle_get_usage, handle_inpaint_image, handle_list_models, handle_recommend_model, handle_remove_background, handle_resize_image, handle_upload_file, handle_upscale_image,

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/raveenb/fal-mcp-server'

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