Skip to main content
RunPod Serverless Backend for SwarmUI
Tool

RunPod Serverless Backend for SwarmUI

Hartsy 2.0
comments, jump to the thread 61 views

Features

  • On-demand worker management, waking and shutting down to minimize cost
  • Works like any native SwarmUI backend with full parameter support
  • User level API keys with backend level fallback
  • Automatic remote model enumeration and registration
  • Status monitoring and manual refresh endpoints
  • Permission system integration
  • Configurable startup, generation and polling timeouts

System requirements

RunPod
An account with a serverless endpoint configured
Worker
A SwarmUI instance deployed on that endpoint
SwarmUI
0.9.7 or newer tested, 0.9.0 minimum
Worker minimum
1 vCPU, 4GB RAM, a GPU with enough VRAM for your models

Links

License

License
MIT

A production ready SwarmUI backend extension that enables serverless GPU inference through RunPod's on demand infrastructure. It manages worker lifecycle automatically, provides cost effective scaling, and integrates with SwarmUI's generation pipeline the same way a local backend does.

It is designed to work with the custom RunPod SwarmUI worker. Install that first and confirm it is running on RunPod before you continue. If you would rather build your own worker, make sure your handler functions are named and behave the same way, and that SwarmUI is reachable on the worker.

Features

  • On-demand worker management. Wakes and shuts down GPU workers automatically to minimize cost.
  • Seamless integration. Works like any native SwarmUI backend, with full parameter support.
  • Flexible API key management. User level keys, with a backend level key as fallback.
  • Model discovery. Automatic remote model enumeration and registration.
  • API endpoints. SwarmUI routes for status monitoring and manual refresh.
  • Permission system. Granular access control through SwarmUI's permission framework.
  • Configurable timeouts. Adjustable startup, generation and polling intervals.
  • Error handling. Handles worker errors and timeouts gracefully.

Installing

Install from Server > Extensions: find RunPod Serverless in the list, press Install, and restart SwarmUI when prompted. To install by hand, clone the repository into SwarmUI/src/Extensions/, stop Swarm, and use the update or dev scripts to rebuild with the new extension. Confirm it appears under Server > Extensions afterwards.

Configuration

Open Server > Backends, turn on Show Advanced, and select RunPod Serverless from the type dropdown.

Setting Type Default Description
EndpointId string required Your RunPod serverless endpoint ID
UseAsync bool true Use the async /run endpoint, recommended
MaxConcurrent int 10 Maximum parallel generation requests
PollIntervalMs int 2000 Worker ready status polling interval
StartupTimeoutSec int 120 Maximum wait for worker startup
GenerationTimeoutSec int 300 Maximum time for generation completion
RunPodApiKey string optional Backend-level key, falls back to the user key if empty
AutoRefresh bool false Refresh models on backend init, requires a backend API key

For a shared backend, set RunPodApiKey in the backend settings so all users share one key; that is also what AutoRefresh needs. For a multi-user install, leave it empty and have each user add their own RunPod key under User Settings > API Keys. The backend falls back from backend-level to user-level automatically.

Usage and the generation flow

Once configured, the backend works like any other: select a model, set your parameters, and press Generate. Behind that, the backend wakes the RunPod worker, waits for ready state, sends the generation request, returns the images, and shuts the worker down.

1. User submits generation request
2. Backend wakes RunPod worker      (POST /run, keepalive started)
3. Poll for worker ready state      (every PollIntervalMs, until StartupTimeoutSec)
4. Worker ready, get public URL and session ID
5. Forward generation request       (T2IParamInput serialized to the worker's /API/GenerateText2Image)
6. Receive and process response     (base64 images extracted and converted)
7. Shutdown worker                  (worker scales to zero)
8. Return images to user

Two REST routes come with it. POST /API/RunPod/RefreshModels refreshes the model list from every running RunPod backend, and GET /API/RunPod/GetStatus returns status for all of them: id, title, status, endpoint id, model count, auto refresh and max concurrent. Both require the use_runpod_serverless permission.

Cost and latency

Cold start is typically 60 to 90 seconds, covering container start, SwarmUI init and model discovery. A warm generation, where the worker is still running from a previous job, starts near instantly with no cold start penalty.

Keepalive is sized to the job: 180 seconds for a single generation covering cold start, generation and a buffer, longer for batches, and 300 seconds for a model refresh, which is enough for model listing across all types.

MaxConcurrent controls parallelism. 1 is serial and cheapest, 5 is moderate, and 10 is the default for high throughput. Each concurrent request wakes a separate worker instance, so higher is not free.

Security

Backend keys are stored in the backend configuration, encrypted at rest by SwarmUI, and visible only to administrators. User keys are stored in the user profile, isolated per user, and not visible to other users.

One permission gates the extension: use_runpod_serverless, granted to Admin and PowerUser by default and withheld from User.

Outbound connections go to api.runpod.ai for the RunPod API and to individual worker instances at [worker-id].runpod.io. No inbound connections are required, because RunPod workers never connect back.

Model and version support

Supports every model type available in the remote SwarmUI instance: Stable Diffusion 1.5, 2.x and XL, Flux, LoRA models, ControlNet models, and any other SwarmUI-compatible architecture.

The worker needs at minimum 1 vCPU, 4GB RAM and a GPU with enough VRAM for the models you intend to load, and must expose the SwarmUI API on the standard port.

Troubleshooting

No RunPod API key found

Set a backend API key in the backend settings, or configure a user API key under User Settings > API Keys > RunPod.

Worker did not become ready within timeout

Increase StartupTimeoutSec, check the RunPod dashboard for worker errors, verify the endpoint ID, and check the account balance and worker availability.

No images returned from generation

Check the worker logs in the RunPod dashboard, verify the model exists on the remote worker, confirm the generation parameters are valid, and raise GenerationTimeoutSec if generation is slow.

Workers fail to start consistently

Check RunPod service status, verify the endpoint configuration, review the worker Docker image configuration, and check available GPU capacity in your RunPod region.

How do I see what the backend is doing

Logs appear in the SwarmUI console output under the tags RunPodServerless for backend operations and RunPodApiClient for API communication.

Comments

Your avatar