Wan2GP API Server

by magicmars35

Not rated
GitHub

About

Skill for AI Agents : wrapper to generate video for local wan2GP instance

Details

Author
magicmars35
Categories
Design, Other, AI

Method 1: let your agent install the skill from GitHub

The simplest method is to give your AI agent the URL of this GitHub repository and ask it to install the skill itself.

Example instruction to give to your agent:

Install the Wan2GP video generation skill from this GitHub repository. Read the README, copy the agent skill files into your skill workspace, and make the skill available for use.

This part must be done on the Linux machines running the agents.

Copy thewan2gp_video_agent_skillfolder into your agent skill workspace.

mkdir -p ~/.openclaw/workspace/skills/wan2gp_video cp wan2gp_video_agent_skill/* ~/.openclaw/workspace/skills/wan2gp_video/
export WAN2GP_URL="http://192.168.1.53:7861" export WAN2GP_TOKEN="YOUR_SECRET_TOKEN"

It is recommended to use environment variables instead of hardcoding the token in the Python file.

Add this to the system prompt or skill configuration of your agent:

You have access to a skill called Wan2GP Video. Use this skill whenever the user asks for video generation. Choose the mode automatically: - text only: t2v - image + prompt: i2v - start image + end image + prompt: i2v_end - audio + prompt: s2v - audio + image + prompt: s2v_i2v - audio + image + explicit LoRA request: s2v_i2v_lora After submitting the job, retrieve the job_id, monitor progress with get_job_status, wait until the job is complete, download the generated MP4, then return the video file to the user. When useful, provide the user with the built-in monitor URL so they can follow the queue visually.
from wan2gp_skill import generate_video result = generate_video( mode="t2v", prompt="A cinematic shot of a small robot walking under neon rain, realistic lighting", duration_seconds=3, output_path="/tmp/robot.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="i2v", prompt="A cinematic close-up portrait, subtle natural movement, warm daylight", image_path="/tmp/reference.png", duration_seconds=3, output_path="/tmp/i2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="i2v_end", prompt="The subject slowly turns toward the camera as the lighting shifts from warm daylight to blue evening light", image_start_path="/tmp/start.png", image_end_path="/tmp/end.png", duration_seconds=4, output_path="/tmp/i2v_end.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v", prompt="A cinematic dialogue scene with natural facial expression and perfect lip sync", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/s2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v_i2v", prompt="The woman speaks naturally in French in front of the camera, soft studio lighting, realistic facial motion, perfect lip sync", image_path="/tmp/reference.png", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/s2v_i2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v_i2v_lora", prompt="The woman speaks in French in front of the camera with perfect lip sync, calm studio ambiance, subtle cinematic camera movement", image_path="/tmp/reference.png", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/result.mp4", verbose=True, ) print(result["saved_file"])

This is useful when several agents submit jobs and the queue is monitored from the built-in dashboard.

from wan2gp_skill import generate_video result = generate_video( mode="t2v", prompt="A futuristic hospital corridor, cinematic lighting, slow dolly forward", duration_seconds=4, wait=False, ) print(result["job_id"]) print(result["monitor_url"])
GET /health GET /model GET /jobs GET /jobs/{job_id} GET /download/{job_id}/{filename} GET /monitor?token=YOUR_SECRET_TOKEN GET /ui?token=YOUR_SECRET_TOKEN GET /monitor/download/{job_id}/{filename}?token=YOUR_SECRET_TOKEN POST /generate/t2v POST /generate/i2v POST /generate/i2v_end POST /generate/s2v POST /generate/s2v_i2v POST /generate/s2v_i2v_lora

Protected API endpoints require a Bearer token:

The browser monitoring endpoints accept the token as a query parameter:

Returns basic API status and available modes.

Returns the fixed model information, default generation settings, template file path, and supported mode controls.

Returns all jobs currently known by the API server.

Jobs are stored in memory. If the server restarts, the job history is cleared.

Returns a single job with runtime fields such asqueue_positionandshort_status.

Downloads a generated MP4 using Bearer token authentication.

Displays the built-in HTML queue dashboard.

Wan2GP Agentic Skill allows Linux AI agents such as OpenClaw, Hermes, or any Python-based agent to generate videos through a Windows PC running Wan2GP on the local network.

Linux AI Agent | | HTTP API v Windows PC with Wan2GP + GPU | | FastAPI server | - video generation API | - built-in queue monitor | - MP4 download endpoint v Generated MP4 video | v Returned to the agent

- a FastAPI server to install on the Wan2GP Windows machine
- a Python skill to install on the AI agent machines

The monitoring interface is directly served by the FastAPI server. No separate web server is required.

- text to video generation
- image to video generation
- start image + end image to video generation
- audio to video generation
- audio + reference image to video generation
- audio + reference image + LoRA generation
- single universal Wan2GP template file
- server-side mode routing
- job queue tracking
- job status monitoring
- built-in HTML monitoring dashboard
- automatic MP4 download after generation
- requester IP tracking
- requester user-agent tracking
- fixed Wan2GP model on the server side
- optional non-blocking job submission for agents

t2v text to video i2v image to video i2v_end start image + end image to video s2v sound/audio to video s2v_i2v sound/audio + reference image to video s2v_i2v_lora sound/audio + reference image + LoRA

This version uses one universal Wan2GP JSON template instead of one template per generation mode.

Then it applies the correct mode controls automatically:

- image prompt type
- audio prompt type
- start image
- end image
- audio guide
- LoRA activation
- prompt enhancer
- multimodal generation type

This keeps the configuration cleaner and avoids maintaining several nearly identical JSON files.

The server also includes a built-in monitoring dashboard:

http://SERVER_IP:7861/monitor?token=YOUR_SECRET_TOKEN
http://SERVER_IP:7861/ui?token=YOUR_SECRET_TOKEN

The server is designed to use one fixed model:

The model is intentionally locked on the server side to prevent agents from switching models or launching unexpected heavy generations.

wan2gp_agentic_skill/ │ ├── README.md │ ├── wan2gp_server/ │ ├── wan2gp_api_server.py │ └── ltx2_template_universal.json │ └── wan2gp_video_agent_skill/ ├── wan2gp_skill.py └── SKILL.md

- wan2gp_servergoes on the Windows PC running Wan2GP
- wan2gp_video_agent_skillgoes on the Linux AI agent machines
- the monitoring dashboard is directly included in the FastAPI server

This part must be done on the Windows PC where Wan2GP is installed.

Copy these files fromwan2gp_serverinto the Wan2GP installation folder:

wan2gp_api_server.py ltx2_template_universal.json

The JSON file is a template exported from the Wan2GP Web UI.

The API server uses this universal template and automatically adapts it depending on the requested mode.

Install the API dependencies inside the same Python environment used by Wan2GP:

pip install fastapi uvicorn python-multipart pydantic requests

[!CAUTION] Donotrun the Wan2GP main program at the same time as the API web server.

Both may try to use the same Wan2GP resources, which can cause conflicts, failed jobs, or unstable behavior.

Only run this API server script. It is not necessary to run the Wan2GP legacy program separately.

Example startup with a virtual environment:

Set-Location "G:\APPS\Wan2GP" .\venv\Scripts\activate python wan2gp_api_server.py

Depending on your Wan2GP installation, the virtual environment path may be different.

If your agents are on the LAN, open the Windows firewall port:

New-NetFirewallRule  -DisplayName "Wan2GP API 7861"  -Direction Inbound  -Protocol TCP  -LocalPort 7861  -Action Allow

The FastAPI server includes its own monitoring dashboard.

http://192.168.1.53:7861/monitor?token=YOUR_SECRET_TOKEN
http://192.168.1.53:7861/ui?token=YOUR_SECRET_TOKEN

- API status
- loaded model
- total jobs
- active jobs
- completed jobs
- failed jobs
- job status
- queue position
- generation mode
- progress
- current phase
- current step
- requester IP
- requester user-agent
- prompt excerpt
- input files
- LoRA information
- generation duration
- MP4 download link

The dashboard uses a browser token parameter because browsers do not easily send anAuthorization: Bearer ...header when opening a page directly.

Method 1: let your agent install the skill from GitHub

The simplest method is to give your AI agent the URL of this GitHub repository and ask it to install the skill itself.

Example instruction to give to your agent:

Install the Wan2GP video generation skill from this GitHub repository. Read the README, copy the agent skill files into your skill workspace, and make the skill available for use.

This part must be done on the Linux machines running the agents.

Copy thewan2gp_video_agent_skillfolder into your agent skill workspace.

mkdir -p ~/.openclaw/workspace/skills/wan2gp_video cp wan2gp_video_agent_skill/* ~/.openclaw/workspace/skills/wan2gp_video/
export WAN2GP_URL="http://192.168.1.53:7861" export WAN2GP_TOKEN="YOUR_SECRET_TOKEN"

It is recommended to use environment variables instead of hardcoding the token in the Python file.

Add this to the system prompt or skill configuration of your agent:

You have access to a skill called Wan2GP Video. Use this skill whenever the user asks for video generation. Choose the mode automatically: - text only: t2v - image + prompt: i2v - start image + end image + prompt: i2v_end - audio + prompt: s2v - audio + image + prompt: s2v_i2v - audio + image + explicit LoRA request: s2v_i2v_lora After submitting the job, retrieve the job_id, monitor progress with get_job_status, wait until the job is complete, download the generated MP4, then return the video file to the user. When useful, provide the user with the built-in monitor URL so they can follow the queue visually.
from wan2gp_skill import generate_video result = generate_video( mode="t2v", prompt="A cinematic shot of a small robot walking under neon rain, realistic lighting", duration_seconds=3, output_path="/tmp/robot.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="i2v", prompt="A cinematic close-up portrait, subtle natural movement, warm daylight", image_path="/tmp/reference.png", duration_seconds=3, output_path="/tmp/i2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="i2v_end", prompt="The subject slowly turns toward the camera as the lighting shifts from warm daylight to blue evening light", image_start_path="/tmp/start.png", image_end_path="/tmp/end.png", duration_seconds=4, output_path="/tmp/i2v_end.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v", prompt="A cinematic dialogue scene with natural facial expression and perfect lip sync", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/s2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v_i2v", prompt="The woman speaks naturally in French in front of the camera, soft studio lighting, realistic facial motion, perfect lip sync", image_path="/tmp/reference.png", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/s2v_i2v.mp4", verbose=True, ) print(result["saved_file"])
from wan2gp_skill import generate_video result = generate_video( mode="s2v_i2v_lora", prompt="The woman speaks in French in front of the camera with perfect lip sync, calm studio ambiance, subtle cinematic camera movement", image_path="/tmp/reference.png", audio_path="/tmp/voice.mp3", duration_seconds=6, output_path="/tmp/result.mp4", verbose=True, ) print(result["saved_file"])

This is useful when several agents submit jobs and the queue is monitored from the built-in dashboard.

from wan2gp_skill import generate_video result = generate_video( mode="t2v", prompt="A futuristic hospital corridor, cinematic lighting, slow dolly forward", duration_seconds=4, wait=False, ) print(result["job_id"]) print(result["monitor_url"])
GET /health GET /model GET /jobs GET /jobs/{job_id} GET /download/{job_id}/{filename} GET /monitor?token=YOUR_SECRET_TOKEN GET /ui?token=YOUR_SECRET_TOKEN GET /monitor/download/{job_id}/{filename}?token=YOUR_SECRET_TOKEN POST /generate/t2v POST /generate/i2v POST /generate/i2v_end POST /generate/s2v POST /generate/s2v_i2v POST /generate/s2v_i2v_lora

Protected API endpoints require a Bearer token:

The browser monitoring endpoints accept the token as a query parameter:

Returns basic API status and available modes.

Returns the fixed model information, default generation settings, template file path, and supported mode controls.

Returns all jobs currently known by the API server.

Jobs are stored in memory. If the server restarts, the job history is cleared.

Returns a single job with runtime fields such asqueue_positionandshort_status.

Downloads a generated MP4 using Bearer token authentication.

Displays the built-in HTML queue dashboard.

GET /monitor/download/{job_id}/{filename}

Downloads a generated MP4 from the browser dashboard using thetokenquery parameter.

For LTX 2.3 video generation, write the prompt as a clear cinematic direction, not as a list of keywords.
- shot type
- camera movement
- environment
- lighting
- subject
- visible action
- mood expressed through physical details
- audio or dialogue when needed

The camera starts in a tight cinematic close-up, then slowly pushes forward as the woman raises her eyes toward the lens. Warm studio light reflects softly on her face. She breathes in, pauses, and says in French, "Je crois que j'ai enfin compris." Her voice is quiet and sincere. After the line, she gives a small uncertain smile while the background remains softly blurred.

For Image-to-Video, do not redescribe what is already visible in the reference image. Describe only:

- camera movement
- subject movement
- environmental changes
- lighting changes
- facial expression changes
- dialogue or sound timing

If the video contains dialogue, include the dialogue directly inside the prompt exactly where it happens in the scene.

The Wan2GP API server must be running before agents can generate videos.

The first generation after startup may be slower if the model has to be loaded into VRAM.

Jobs are stored in memory on the API server.

If the API server is restarted, previousjob_id`values will no longer be available.

Use the built-in monitor to follow the queue visually while agents submit generation jobs.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.