Enable, prove, and call the Forge API
Start with one local request you can inspect end to end: confirm the route exists, ask the running instance for valid names, generate a small image, then decode and verify the response.
VERIFIED Core API inspected at Original Forge commit dfdcbab. No fork routes or third-party API wrapper are attributed to Forge.
The API is present, but the normal launch does not enable its core routes
Add --api to keep the UI and expose the core /sdapi/v1/* routes on the same server. Use --nowebui only when you intentionally want the API without the normal interface.
ENABLED BY DEFAULT IN API MODE
CORE PATHS
BEHIND --api-server-stop
/docs is a discovery surface, not the success condition. Without --api, the UI server can still show Gradio and extension routes there. Search for POST /sdapi/v1/txt2img; if it is absent, the core API was not attached to that running server.
Choose the smallest access boundary that fits the client
Loopback is the clean baseline. Move to browser CORS or another machine only after the same local request passes.
UI + API
Best first proof. Forge keeps its normal interface and adds the core /sdapi routes to the same server. Select and prove the model in the UI, then repeat it through the API.
--apiProof: Open /docs and find POST /sdapi/v1/txt2img.
API only
Starts a FastAPI service without the normal Gradio UI. The inspected code uses port 7861 when --port is absent. Record the model-loading arguments because there is no UI state to inspect.
--nowebuiProof: Open port 7861 /docs, unless you supplied --port.
Browser client
Use an exact browser-app origin. CORS only permits that browser origin to read responses; it neither starts the API nor authenticates a caller.
--api --cors-allow-origins=http://127.0.0.1:3000Proof: The preflight succeeds only for the named scheme, host, and port.
Another machine
The code can bind beyond loopback and add HTTP Basic auth to core API routes. This page does not certify a public-internet deployment, extension routes, firewall, proxy, or TLS design.
--api --listen --api-auth=user:REPLACE_MEProof: First prove authenticated LAN access; keep direct public exposure out of scope.
Add the argument to the launcher your installation actually runs, then close and restart the full Forge process. Windows Git installs normally use webui-user.bat; Linux/macOS Git installs use webui-user.sh. Package managers and old archives can wrap those files.
Do not debug generation before the route and runtime state pass
Each gate answers one question. Stop at the first failed gate and preserve its response.
- 01PROCESS
Argument reached the process
The console launch line contains
--apior--nowebui. A browser refresh cannot apply it. - 02SCHEMA
Core route exists
Open
/docsand findPOST /sdapi/v1/txt2img. Its absence is an enablement problem. - 03DISCOVERY
Read-only call works
curl -sS http://127.0.0.1:7860/sdapi/v1/samplersreturns a JSON array. Use port 7861 for default API-only mode. - 04INFERENCE
Generation returns an image
A small
txt2imgrequest returns HTTP 200 and a non-emptyimages[0]. - 05RESULT
Response proves the intended state
The base64 decodes to a valid image and returned
inforeflects the model, seed and generation controls you intended.
Build one small txt2img request
The builder deliberately omits Hires. fix, scripts, LoRAs and model switching. Prove transport and decoding before adding state.
images[0]- Base64-encoded result when
send_imagesis true. parameters- The API request fields returned as an object.
info- A JSON-formatted string containing generation details.
Turn images[0] into a file, then open the file
Save the API body as response.json, run this Python standard-library script, and confirm the output is a readable image—not merely a non-empty string.
import base64, json
from pathlib import Path
data = json.loads(Path("response.json").read_text(encoding="utf-8"))
if not data.get("images"):
raise SystemExit(f"No image returned: {data}")
encoded = data["images"][0].split(",", 1)[-1]
Path("forge-api-result.png").write_bytes(base64.b64decode(encoded, validate=True))
print("Wrote forge-api-result.png")Example verification boundary: request JSON is parsed during site QA, every named field exists in the inspected request model, and the decoder is exercised against a fixture matching the response model. Live image generation was not run in this web project environment because no Forge model/GPU runtime is attached.
Inspect the route before you build against it
This is the Api class at commit dfdcbab, not every Gradio, built-in, or third-party extension route on a running server.
Showing all 37 method and path records
Generate & transform
4 RECORDS/sdapi/v1/txt2imgGenerate from a prompt; returns base64 images, submitted parameters, and an info string.
/sdapi/v1/img2imgGenerate from base64 init_images; a missing init image returns an error.
/sdapi/v1/extra-single-imageApply the Extras post-processing path to one base64 image.
/sdapi/v1/extra-batch-imagesApply Extras to a named list of base64 images.
Inspect images
2 RECORDS/sdapi/v1/png-infoRead generation text and parsed parameters from a base64 PNG.
/sdapi/v1/interrogateCaption one base64 image with CLIP or DeepDanbooru.
Control the active job
3 RECORDS/sdapi/v1/progressRead current global progress; optionally omit the preview image.
/sdapi/v1/interruptInterrupt the current generation.
/sdapi/v1/skipSkip the current item in the active job.
Discover runtime state
18 RECORDS/sdapi/v1/optionsRead the current settings object.
/sdapi/v1/optionsSet named settings; treat this as shared mutable state.
/sdapi/v1/cmd-flagsRead parsed launch arguments.
/sdapi/v1/samplersList the sampler names accepted by this running instance.
/sdapi/v1/schedulersList schedulers from this running instance.
/sdapi/v1/upscalersList available upscalers and their runtime metadata.
/sdapi/v1/latent-upscale-modesList latent upscale modes.
/sdapi/v1/sd-modelsList discovered checkpoints and hashes.
/sdapi/v1/sd-modulesList discovered VAE and text-encoder module files.
/sdapi/v1/hypernetworksList discovered hypernetworks.
/sdapi/v1/face-restorersList registered face restorers.
/sdapi/v1/realesrgan-modelsList registered Real-ESRGAN models.
/sdapi/v1/prompt-stylesList saved prompt styles.
/sdapi/v1/embeddingsList loaded and skipped embeddings.
/sdapi/v1/memoryRead RAM and CUDA memory figures reported by Forge.
/sdapi/v1/scriptsList txt2img and img2img script names.
/sdapi/v1/script-infoRead API metadata exposed by registered scripts.
/sdapi/v1/extensionsList registered extensions and Git identity fields.
Change runtime state
7 RECORDS/sdapi/v1/refresh-embeddingsRescan embeddings.
/sdapi/v1/refresh-checkpointsRescan checkpoint files.
/sdapi/v1/refresh-vaeRefresh VAE/module state.
/sdapi/v1/create/embeddingCreate an embedding record through the inherited API path.
/sdapi/v1/create/hypernetworkCreate a hypernetwork record through the inherited API path.
/sdapi/v1/unload-checkpointUnload model weights.
/sdapi/v1/reload-checkpointSend the current model back to the selected device.
Gated server control
3 RECORDS/sdapi/v1/server-killAvailable only with --api-server-stop. Stops the process.
/sdapi/v1/server-restartAvailable only with --api-server-stop; restart support is environment-dependent.
/sdapi/v1/server-stopAvailable only with --api-server-stop. Requests server stop.
Clear the filters, check your spelling, or inspect /openapi.json on the running instance. The route may belong to Gradio, ControlNet, another extension, or another project.
Model state and the GPU queue belong to the process, not one caller
That distinction matters as soon as more than one script, person, or browser uses the instance.
Generation is serialized
The inspected txt2img, img2img and Extras handlers enter a shared queue lock. A second request may wait; it is not a separate worker with isolated model state.
Options are shared
POST /sdapi/v1/options changes process settings. Do not let concurrent clients switch checkpoints or companion modules without their own coordination.
FLUX needs an exact-state proof
Users report module-selection and black-image failures across older commits. Current code lists SD modules, but that does not certify one universal FLUX payload.
UI parity is a receipt problem
A minimal API body intentionally uses many defaults. Compare the response info with a known-good UI PNG and add only the missing, attributable field.
Four flags solve four different problems
Combining them in one copied launch line hides which boundary is actually working.
--apiAttach core routes
Adds the inspected /sdapi/v1/* API to the normal UI server.
--listenChange the bind address
The helper returns 0.0.0.0, allowing network requests to reach the server when the surrounding network permits it.
--api-authProtect core API routes
Adds HTTP Basic authentication to routes registered by the core Api helper.
--cors-allow-originsAllow one browser origin
Configures which web origin may read cross-origin responses. The origin includes scheme, host, and port.
DOES NOT BLOCK NON-BROWSER CLIENTS- Loopback API
- Exact local client
- Authenticated LAN
- Independently reviewed gateway
UNKNOWN Direct public-internet exposure is outside this guide’s verified boundary.
Read the first failed gate, not the last symptom
Remove optional fields and return to a read-only route before changing Python, Torch, models, or extensions.
/docs opens, but txt2img is missing
The server is alive, but the core API was not attached. Confirm the console launch line contains --api, restart the full process, and search again. For --nowebui, use port 7861 unless --port changed it.
Connection refused or the request never reaches Forge
Check the exact address printed by the running process. Verify UI+API versus API-only port, scheme, host and custom subpath. Test from the Forge machine before adding --listen, CORS, a proxy, or another client.
HTTP 401 Unauthorized
The core route expects HTTP Basic credentials from --api-auth. With curl, add -u user:password. Avoid real credentials in copied commands, screenshots, shell history, logs, or repository files.
HTTP 404 Not Found
Compare the method and path with your runtime /docs. A GET to a POST-only route, the wrong port, a reverse-proxy subpath, or a missing --api can all produce a 404-shaped symptom.
HTTP 422 validation error
Read the returned detail array and use your running /docs schema. Remove scripts, alwayson_scripts, overrides and optional fields until the minimal body passes, then restore one field at a time.
HTTP 500, black image, or no image to decode
Preserve the first Forge console traceback. Confirm send_images is true, the selected checkpoint generates in the UI, required VAE/text encoders are loaded, and the small baseline works without LoRAs, Hires. fix or scripts. Route model failures to the dedicated guides.
Browser fetch fails while curl succeeds
Transport and inference already work. Compare the browser page’s exact origin with --cors-allow-origins; http://localhost:3000 and http://127.0.0.1:3000 are different origins. Do not replace an exact origin with a broad pattern merely to silence the browser.
API image differs from a UI image with the same prompt
A prompt is not the complete generation state. Compare model and modules, seed, dimensions, sampler, scheduler, steps, guidance, styles, scripts, Hires. fix, LoRAs and extension state. Use the returned info and a known-good UI PNG as the two receipts.
Answers for the next integration decision
These questions cover enablement, ports, response decoding, runtime discovery, model state, concurrency, CORS, authentication and exposure.
How do I enable the API in Stable Diffusion WebUI Forge?
Add --api to the active launcher arguments and fully restart Forge. Then open /docs on the running address and confirm that POST /sdapi/v1/txt2img appears. The presence of /docs alone is not proof because the Gradio server exposes other routes without the core API.
What is the default Forge API URL?
With the normal UI plus --api, use the same local server, normally http://127.0.0.1:7860. With --nowebui and no explicit --port, the inspected code uses http://127.0.0.1:7861. A custom --port replaces those defaults.
Why is /sdapi/v1/txt2img missing from /docs?
The usual cause is that the running process did not receive --api. Confirm the printed launch arguments, close the full process, restart through the launcher you edited, then search /docs again. If --nowebui is active, check port 7861 unless you set --port.
Can I use curl with the Forge API?
Yes. Send JSON to POST /sdapi/v1/txt2img with Content-Type: application/json. Start with a small request, save the JSON response, verify that images[0] exists, and decode that base64 value to a file.
Why does the API return JSON instead of a PNG file?
The txt2img response model contains an images array of base64 strings plus parameters and info. Decode the first string before opening it as an image. Setting send_images to false intentionally returns no encoded images.
Does save_images control the API response?
No. In the inspected request model, send_images controls whether image strings are returned, while save_images controls whether Forge writes samples and grids through its own output path. They are separate switches.
How do I choose a sampler or scheduler safely?
Query /sdapi/v1/samplers and /sdapi/v1/schedulers on the running instance and send an exact returned name. Do not copy a name from a different build or fork. An unknown sampler is rejected by the core API.
How do I select a model through the Forge API?
For the first proof, select and test the model in the UI before calling txt2img. The API exposes /sdapi/v1/sd-models, /sdapi/v1/sd-modules and mutable settings, but checkpoint and companion-module changes affect shared process state and need an exact-build test before concurrent use.
Can the Forge API use FLUX?
Current code exposes the same txt2img processing model and module inventory used by Forge, but a universal FLUX payload is not verified here. Community reports show commit- and module-dependent behavior around checkpoint, VAE and text-encoder selection. Prove one working FLUX setup in the UI, record every module, then test the same commit through the API.
Why does API output differ from the Forge UI?
A shorter API payload leaves many fields at code defaults and may omit scripts, always-on extensions, model/module state, Hires. fix controls, styles, or other UI values. Compare the returned info and parameters with the PNG metadata from a UI baseline before adding fields.
Can several clients generate at the same time?
Generation paths use a shared queue lock in the inspected core API, so requests can wait rather than execute as independent GPU jobs. Options and model state are also shared. Serialize model-changing operations in your client and treat progress as global process state.
What does HTTP 422 mean in Forge API?
FastAPI rejected the request shape or a script name/argument failed validation. Read the response detail, compare the body with the schema shown by your own /docs page, and remove optional fields until the minimal payload passes.
What causes HTTP 401 from the Forge API?
The process was started with --api-auth and the request did not supply a matching HTTP Basic username and password. Add curl -u user:password or the equivalent client setting. Do not place real credentials in screenshots, shell history, or source control.
Is --cors-allow-origins the same as authentication?
No. CORS tells browsers which web origins may read a response. It does not stop curl, Python, another server, or a non-browser client. Use it only for a browser integration and keep access control as a separate boundary.
Is it safe to expose the Forge API to the public internet?
This guide does not certify direct public exposure. The core API can change settings, inspect paths and extensions, generate costly work, and optionally stop the server. Keep the first deployment on loopback; any network deployment needs an independently reviewed access, TLS, firewall, logging, and extension-route design.
Does --api-auth protect extension API routes?
The inspected helper adds HTTP Basic auth to the 37 routes registered through the core Api class. Built-in and third-party extensions can register routes separately, so this page does not claim that --api-auth protects every route on the server. Inspect the actual /openapi.json and extension code.
How do I see every endpoint in my installed Forge build?
Open /docs for interactive Swagger documentation or fetch /openapi.json from the running server. Treat that runtime schema as the inventory for your exact commit and enabled extensions; the ledger on this page covers only the inspected core Api class.
Code defines the route; reports define what users trip over
Secondary pages and user reports were used to find integration questions. Every route, flag, default port, request field and response claim was checked against the original repository snapshot.
Routes, auth, locking, handlers and responses.
↗ORIGINAL FORGEAPI request modelsDynamic request fields and response contracts.
↗ORIGINAL FORGELaunch argumentsAPI, network, CORS, auth and server-control flags.
↗ORIGINAL FORGEServer launch branchesUI+API versus API-only lifecycle and default ports.
↗Research reviewed: 9 relevant source records
Original repository: API implementation and request models
Used for the exact core routes, auth wrapper, queue lock, response shape and image decoding contract.
Original repository: launch arguments and server branches
Used for --api, --nowebui, --listen, --port, CORS, TLS, logging and server-control flags.
Issue #2040: /docs without generation routes
Identified the real user failure; the resolution path was verified against webui.py.
Issue #1151: API/UI output mismatch
Used to frame parity as a full-state comparison, not a generic quality promise.
Issue #1532: VAE and text-encoder operations
Used to identify companion-module intent; current endpoint existence was checked in code.
Discussion #2769: FLUX payload and modules
Used only to document unresolved FLUX integration questions, never as a guaranteed recipe.
DeepWiki code-derived documentation hub
Endpoint categories and headless intent were checked; broad enhancement claims were not adopted.
DeepWiki installation and setup
Launch-mode wording was checked; its API-only port and /api path claims were rejected against current code.
HammerAI Forge integration guide
Confirmed third-party demand for local API detection; its bundled launch and tuning advice was not generalized.
37 core method/path records, 3 gated server-control records, flags, default API-only port, auth wrapper, queue lock, request and response shape.
Historical UI/API mismatch and FLUX companion-module problems. They identify tests, not universal outcomes.
Public deployment, every extension route, a universal FLUX payload, every client library, and live generation on untested hardware.