swap_face
Replace a face in any image with a face from another image using AI. Provide target and source image URLs to perform the swap while preserving the background.
Instructions
Swap a face in an image using AI.
Provide a target image and a source face image. The AI replaces the face in the target image with the face from the source image while keeping the rest of the image intact. Cost: ~6 credits.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_url | Yes | Target image URL (the image where the face will be replaced) | |
| face_url | Yes | Source face image URL (the face to use for swapping) | |
| prompt | No | Optional additional instructions for the face swap |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/yaparai/tools/edit.py:97-135 (handler)The core handler function `swap_face` that executes the face swap tool. It accepts image_url, face_url, and optional prompt, sends a request to the AI API with mode 'editor_face_swap', waits for the result, and returns the result URL along with job metadata.
async def swap_face( image_url: str, face_url: str, prompt: str = "", ) -> dict: """ Swap a face in an image using AI. Provide a target image and a source face image. The AI replaces the face in the target image with the face from the source image while keeping the rest of the image intact. Cost: ~6 credits. Args: image_url: Target image URL (the image where the face will be replaced) face_url: Source face image URL (the face to use for swapping) prompt: Optional additional instructions for the face swap Returns: Dict with image_url (result image), job_id, credits_used, and balance_remaining. """ client = YaparAIClient() job = await client.generate({ "type": "image", "mode": "editor_face_swap", "prompt": prompt, "image_url": image_url, "face_url": face_url, }) result = await client.wait_for_result(job["job_id"], timeout=60) return { "status": "success", "image_url": result.get("result_url"), "job_id": result.get("job_id"), "credits_used": job.get("credits_used"), "balance_remaining": job.get("balance_remaining"), } - src/yaparai/server.py:131-131 (registration)Registration of swap_face as an MCP tool via `mcp.tool(swap_face)`. This makes the face swap function available as an MCP tool in the server.
mcp.tool(swap_face) - src/yaparai/server.py:32-36 (registration)Import of swap_face from yaparai.tools.edit into the server module, enabling its registration as an MCP tool.
from yaparai.tools.edit import ( transform_image, remove_background, swap_face, ) - src/yaparai/tools/edit.py:97-101 (schema)Function signature and docstring define the input schema: image_url (str, required), face_url (str, required), prompt (str, optional, default ''). Return dict schema includes status, image_url, job_id, credits_used, balance_remaining.
async def swap_face( image_url: str, face_url: str, prompt: str = "", ) -> dict: - src/yaparai/tools/edit.py:7-7 (helper)The YaparAIClient import that swap_face depends on for making API calls. Used to create a client instance that handles API communication.
from yaparai.client import YaparAIClient