execute_template
Generate content by running a pre-built AI workflow with your text prompt, optional image, and template-specific inputs.
Instructions
Execute a ComfyUI template to generate content.
Runs a pre-built AI workflow with your inputs. Each template has different capabilities — use get_template_detail() first to see what inputs are accepted. Credits are deducted based on the template.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| slug | Yes | Template slug (e.g., "flux-logo-generator", "product-photo-enhancer") | |
| prompt | Yes | Main text prompt for the template | |
| image_url | No | Input image URL (required for image-based templates) | |
| width | No | Output width in pixels (64-2048) | |
| height | No | Output height in pixels (64-2048) | |
| extra_inputs | No | Additional template-specific inputs (see get_template_detail). e.g., {"brand_color": "#FF0000", "logo_text": "ACME Corp"} |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/yaparai/tools/templates.py:67-119 (handler)The main tool handler: async function execute_template that builds a payload, calls the client, and optionally polls for results.
async def execute_template( slug: str, prompt: str, image_url: str | None = None, width: int = 512, height: int = 512, extra_inputs: dict | None = None, ) -> dict: """ Execute a ComfyUI template to generate content. Runs a pre-built AI workflow with your inputs. Each template has different capabilities — use get_template_detail() first to see what inputs are accepted. Credits are deducted based on the template. Args: slug: Template slug (e.g., "flux-logo-generator", "product-photo-enhancer") prompt: Main text prompt for the template image_url: Input image URL (required for image-based templates) width: Output width in pixels (64-2048) height: Output height in pixels (64-2048) extra_inputs: Additional template-specific inputs (see get_template_detail). e.g., {"brand_color": "#FF0000", "logo_text": "ACME Corp"} Returns: Dict with job_id, status, and result info. """ client = YaparAIClient() payload: dict = { "prompt": prompt, "width": width, "height": height, } if image_url: payload["image_url"] = image_url if extra_inputs: payload.update(extra_inputs) result = await client.execute_template(slug, payload) # If the template returns a job_id, poll for result job_id = result.get("job_id") if job_id: final = await client.wait_for_result(job_id, timeout=120) return { "status": "success", "result_url": final.get("result_url"), "job_id": job_id, "credits_used": result.get("credits_used"), "balance_remaining": result.get("balance_remaining"), } return result - src/yaparai/tools/templates.py:74-93 (schema)The docstring serves as the tool's schema/description, defining inputs (slug, prompt, image_url, width, height, extra_inputs) and return type.
) -> dict: """ Execute a ComfyUI template to generate content. Runs a pre-built AI workflow with your inputs. Each template has different capabilities — use get_template_detail() first to see what inputs are accepted. Credits are deducted based on the template. Args: slug: Template slug (e.g., "flux-logo-generator", "product-photo-enhancer") prompt: Main text prompt for the template image_url: Input image URL (required for image-based templates) width: Output width in pixels (64-2048) height: Output height in pixels (64-2048) extra_inputs: Additional template-specific inputs (see get_template_detail). e.g., {"brand_color": "#FF0000", "logo_text": "ACME Corp"} Returns: Dict with job_id, status, and result info. """ - src/yaparai/server.py:143-143 (registration)Registration of the execute_template function as an MCP tool via mcp.tool(execute_template).
mcp.tool(execute_template) - src/yaparai/server.py:51-52 (registration)Import of execute_template from yaparai.tools.templates into the server module.
execute_template, ) - src/yaparai/client.py:175-177 (helper)The HTTP client method that sends the POST request to /v1/comfy-templates/{slug}/execute with the payload.
async def execute_template(self, slug: str, payload: dict) -> dict: """Execute a ComfyUI template.""" return await self._request("POST", f"/v1/comfy-templates/{slug}/execute", json=payload)