0
# Configuration
1
2
WebUI configuration management, option retrieval and modification, system status monitoring, and utility functions for managing the API client and server settings.
3
4
## Capabilities
5
6
### Options Management
7
8
Retrieve and modify WebUI configuration settings and options.
9
10
```python { .api }
11
def get_options() -> Dict:
12
"""
13
Get all current WebUI configuration options.
14
15
Returns:
16
Dictionary containing all WebUI settings including:
17
- Model settings (default model, VAE, etc.)
18
- Generation defaults (sampler, steps, CFG scale)
19
- UI preferences and behavior
20
- Extension settings
21
- System configuration
22
"""
23
24
def set_options(options: Dict) -> None:
25
"""
26
Update WebUI configuration options.
27
28
Parameters:
29
- options: Dictionary of option names and values to update
30
31
Example options:
32
- "sd_model_checkpoint": Model to load
33
- "CLIP_stop_at_last_layers": CLIP skip value
34
- "eta_noise_seed_delta": Noise seed delta
35
- "samples_save": Save generated images
36
- "grid_save": Save image grids
37
"""
38
39
def get_cmd_flags() -> Dict:
40
"""
41
Get command line flags used to start WebUI.
42
43
Returns:
44
Dictionary containing startup flags and their values
45
"""
46
```
47
48
### System Status and Control
49
50
Monitor system status and control generation processes.
51
52
```python { .api }
53
def get_progress() -> Dict:
54
"""
55
Get current generation progress information.
56
57
Returns:
58
Dictionary containing:
59
- progress: Progress percentage (0.0-1.0)
60
- eta_relative: Estimated time remaining (seconds)
61
- state: Current processing state
62
- job_count: Number of jobs in queue
63
- job_no: Current job number
64
- sampling_step: Current sampling step
65
- sampling_steps: Total sampling steps
66
"""
67
68
def interrupt() -> None:
69
"""
70
Interrupt the current generation process.
71
72
Stops the currently running txt2img, img2img, or processing task.
73
"""
74
75
def skip() -> None:
76
"""
77
Skip the current generation and move to next in queue.
78
79
Completes current step but skips remaining steps in generation.
80
"""
81
82
def get_memory() -> Dict:
83
"""
84
Get system memory usage information.
85
86
Returns:
87
Dictionary containing GPU and system memory statistics
88
"""
89
```
90
91
### Authentication
92
93
Configure API authentication for secured WebUI instances.
94
95
```python { .api }
96
def set_auth(username: str, password: str) -> None:
97
"""
98
Set HTTP Basic Authentication credentials.
99
100
Parameters:
101
- username: Authentication username
102
- password: Authentication password
103
104
Used when WebUI is started with --api-auth option.
105
Note: Credentials are sent in cleartext over HTTP.
106
Use HTTPS for secure transmission.
107
"""
108
```
109
110
### Utility and Status Functions
111
112
Helper functions for API management and status checking.
113
114
```python { .api }
115
def util_wait_for_ready(check_interval: float = 5.0) -> bool:
116
"""
117
Wait for WebUI to be ready and responsive.
118
119
Parameters:
120
- check_interval: Interval between readiness checks in seconds
121
122
Returns:
123
True if WebUI becomes ready, False on error
124
125
Note: This function polls continuously until WebUI is ready.
126
Use with caution in production environments.
127
"""
128
129
def custom_get(endpoint: str, **kwargs) -> requests.Response:
130
"""
131
Perform custom GET request to WebUI API.
132
133
Parameters:
134
- endpoint: API endpoint path (without base URL)
135
- **kwargs: Additional parameters for requests.get()
136
137
Returns:
138
Raw requests.Response object
139
"""
140
141
def custom_post(endpoint: str, **kwargs) -> requests.Response:
142
"""
143
Perform custom POST request to WebUI API.
144
145
Parameters:
146
- endpoint: API endpoint path (without base URL)
147
- **kwargs: Additional parameters for requests.post()
148
149
Returns:
150
Raw requests.Response object
151
"""
152
```
153
154
**Usage Examples:**
155
156
```python
157
import webuiapi
158
import time
159
160
# Initialize API with custom configuration
161
api = webuiapi.WebUIApi(
162
host='192.168.1.100',
163
port=7860,
164
use_https=True,
165
username='admin',
166
password='secret'
167
)
168
169
# Wait for WebUI to be ready
170
if api.util_wait_for_ready(check_interval=2.0):
171
print("WebUI is ready!")
172
else:
173
print("WebUI failed to start within timeout")
174
exit(1)
175
176
# Get current configuration
177
current_options = api.get_options()
178
print(f"Current model: {current_options.get('sd_model_checkpoint')}")
179
print(f"Default sampler: {current_options.get('sampler_index')}")
180
print(f"CLIP skip: {current_options.get('CLIP_stop_at_last_layers')}")
181
182
# Update configuration
183
new_options = {
184
"sd_model_checkpoint": "realisticVisionV40_v40VAE.safetensors",
185
"CLIP_stop_at_last_layers": 2,
186
"samples_save": True,
187
"samples_format": "png"
188
}
189
190
api.set_options(new_options)
191
print("Configuration updated!")
192
193
# Monitor generation progress
194
result_future = api.txt2img(
195
prompt="detailed landscape painting",
196
steps=50,
197
width=1024,
198
height=768
199
)
200
201
# Poll progress while generating
202
while True:
203
progress = api.get_progress()
204
205
if progress.get('progress', 0) == 0:
206
break
207
208
current_step = progress.get('sampling_step', 0)
209
total_steps = progress.get('sampling_steps', 1)
210
eta = progress.get('eta_relative', 0)
211
212
print(f"Progress: {current_step}/{total_steps} steps, ETA: {eta:.1f}s")
213
time.sleep(1)
214
215
print("Generation completed!")
216
217
# Check system memory
218
memory_info = api.get_memory()
219
print(f"GPU Memory: {memory_info}")
220
221
# Get command line flags
222
cmd_flags = api.get_cmd_flags()
223
print(f"WebUI started with flags: {cmd_flags}")
224
225
# Custom API calls for advanced usage
226
# Get available scripts
227
scripts_response = api.custom_get("/sdapi/v1/scripts")
228
scripts = scripts_response.json()
229
print(f"Available scripts: {list(scripts.keys())}")
230
231
# Custom endpoint access
232
custom_response = api.custom_post("/sdapi/v1/extra-single-image", json={
233
"image": "base64_image_data",
234
"upscaler_1": "R-ESRGAN 4x+",
235
"upscaling_resize": 2.0
236
})
237
238
# Emergency controls
239
# Interrupt current generation if taking too long
240
api.interrupt()
241
242
# Or skip to next in queue
243
api.skip()
244
245
# Authentication examples
246
# Set auth after initialization
247
api.set_auth("newuser", "newpassword")
248
249
# Or provide during initialization
250
secure_api = webuiapi.WebUIApi(
251
host='secure.example.com',
252
port=443,
253
use_https=True,
254
username='admin',
255
password='secretkey'
256
)
257
258
# Configuration backup and restore
259
# Backup current settings
260
backup_options = api.get_options()
261
262
# Make temporary changes
263
temp_options = {
264
"samples_save": False,
265
"save_images_before_face_restoration": False
266
}
267
api.set_options(temp_options)
268
269
# Do some work...
270
result = api.txt2img(prompt="test image")
271
272
# Restore original settings
273
api.set_options(backup_options)
274
```
275
276
## Advanced Configuration
277
278
### Batch Processing Configuration
279
280
```python
281
import webuiapi
282
283
api = webuiapi.WebUIApi()
284
285
# Configure for batch processing
286
batch_options = {
287
"samples_save": True,
288
"save_images_before_face_restoration": True,
289
"save_images_before_highres_fix": True,
290
"save_init_img": True,
291
"outdir_samples": "/output/samples",
292
"outdir_txt2img_samples": "/output/txt2img",
293
"outdir_img2img_samples": "/output/img2img"
294
}
295
296
api.set_options(batch_options)
297
298
# Batch generate with automatic saving
299
for i in range(10):
300
result = api.txt2img(
301
prompt=f"landscape variation {i}",
302
seed=1000 + i,
303
save_images=True
304
)
305
```
306
307
### Performance Optimization
308
309
```python
310
# Optimize for speed
311
speed_options = {
312
"do_not_show_images": True,
313
"show_progress_every_n_steps": 10,
314
"samples_save": False,
315
"grid_save": False
316
}
317
318
api.set_options(speed_options)
319
320
# Optimize for quality
321
quality_options = {
322
"do_not_show_images": False,
323
"show_progress_every_n_steps": 1,
324
"samples_save": True,
325
"jpeg_quality": 95
326
}
327
328
api.set_options(quality_options)
329
```
330
331
## Types
332
333
```python { .api }
334
# Configuration and status types are primarily dictionaries
335
# returned by the WebUI API with varying structures
336
337
class WebUIApi:
338
"""Main API class with configuration attributes."""
339
has_controlnet: bool # ControlNet extension availability
340
has_adetailer: bool # ADetailer extension availability
341
has_animatediff: bool # AnimateDiff extension availability
342
```