FastAPI is a modern, fast (high-performance) web framework for building APIs. This project builds the Rest interface of Fooocus based on Fastapi.
For a partial description of Fooocus, please refer to the Fooocus documentation, which mainly introduces the interface section.
Compared to the previous API project Fooocus-API, there are major changes:
You can get a guide here if you use the previous API project.
advantage:
Based on Fooocus, there are several dependencies, so you can install it in the same way as Fooocus.
Same as Fooocus, use --apikey
to specify the API authentication key.
Default API port is WebUI port plus 1, that is 7866, use --port
to modify WebUI port
Environment variable API_PORT is used to specify the API port. It takes precedence over the default setting.
example for WebUI and API:
python launch.py --listen 0.0.0.0 --port 7865
Only API example:
python launch.py --listen 0.0.0.0 --port 7865 --nowebui
X-API-KEY
.Use --apikey
to specify the API authentication key on startup.
POST /v1/engine/generate/
CommonRequest
model.Explain:
Request parameter model CommonRequest
contains all parameters of WebUI, but some parameters you need to pay attention to when using them, including the following categories:
Invalid parameters in the API, this part of the parameter contains:
input_image_checkbox
, This parameter always set to Trueinpaint_mask_upload_checkbox
, This parameter always set to Trueinvert_mask_checkbox
, This parameter always set to Falsecurrent_tab
, This parameter checks the image information in the parameter and is automatically set. The check order is 'ip' -> 'uov' -> 'inpaint'Parameters that are not recommended:
generate_image_grid
, It is not clear what this parameter does. It is recommended to leave it false.The following parameters need to be set according to the usage scenario:
mixing_image_prompt_and_vary_upscale
mixing_image_prompt_and_inpaint
In addition, some API-specific parameters are also included:
preset
, You can use this parameter to specify a preset that takes precedence over the global default and below the passed parameter, but if the passed parameter is equal to the default value, the preset parameter is usedstream_output
, true for streaming output, default falserequire_base64
, not usedasync_process
, async task, default false, a synchronous task will be returned when stream_output
is false at the same timewebhook_url
, Webhook addr, if set, the task will be sent to the address after the task is completed.
stream_output
has a higher priority thanasync_process
, that is, when both aretrue
, return streaming output. When all are false, task will be synchronously returned. when you setAccept: image/xxx
in the request header, the response will be a binary image
POST /v1/engine/control/
action
(string): action type, can be "stop" or "skip".{"message": "{message}"}
GET /tasks
query
(string, default: "all"): task type, one of "all", "history", "current".page
(integer, default: 0): page number, used for history and pending tasks.page_size
(integer, default: 10): page size of each pagestart_at
(string): filter tasks start time, only valid for history. format by ISO8601 example: "2024-06-30T17:57:07.045812"end_at
(string): default to current time format by ISO8601, example: "2024-06-30T17:57:07.045812", filter tasks end time, only valid for history.action
(string): used for delete operation, only valid for history, will delete database record and generated images.Although all models are based on
RecordResponse
, thecurrent
one will have a preview field
GET /tasks/{task_id}
task_id
(string): task idGET /v1/engines/all-models
GET /v1/engines/styles
GET /outputs/{date}/{file_name}
date
(string): date, the generated image is created in the day folder for classification, the part is the generation date. file_name
(string): file nameif you set
Accept: image/xxx
in the request header, server will convert the output to the specified format and return it.image/png
image/jpeg
image/webp
image/jpg
are supported.
POST /v1/tools/describe-image
image_type
(string): default: "Photo", image typemultipart/form-data
format, include image file.DescribeImageResponse
model.GET /
/docs
prompt
(string): prompt for generation image.negative_prompt
(string): negative prompt for filtering unwanted content.style_selections
(array): style selections.performance_selection
(Performance): performance, default Speed
, one of Quality
Speed
Extreme Speed
Lightning
Hyper-SD
aspect_ratios_selection
(string): aspect radios selection, default 1152*896image_number
(int): number of images to generate, default 1, range 1-32output_format
(string): out image format, default png
, one of jpg
webp
png
image_seed
(int): seed, -1 for randomread_wildcards_in_order
(bool): read wildcards in order, default falsesharpness
(float): sharpness, default 2.0, range 0.0-30.0guidance_scale
(float): guidance scale, default 4, range 1.0-30.0base_model_name
(string): base model name, default juggernautXL_v8Rundiffusion.safetensors
for nowrefiner_model_name
(string): refiner model name, default Nonerefiner_switch
(float): refiner switch, default 0.5, range 0.1-1.0loras
(Lora): lora list to use, default sd_xl_offset_example-lora_1.0.safetensors
, format: Lorainput_image_checkbox
(bool): this will always to be truecurrent_tab
(string): current tab, default uov
one of uov
inpaint
outpaint
, you don't need to pass this parameter.uov_method
(string): uov method, default disable
, all choice UpscaleOrVaryMethoduov_input_image
(string): URL or Base64 image for Upscale or vary, default "None"outpaint_selections
(array): Outpaint selection, example ["Left", "Right", "Top", "Bottom"]inpaint_input_image
(string): URL or Base64 image for inpaintinpaint_additional_prompt
(string): Inpaint additional prompt, default "None"inpaint_mask_image_upload
(string): URL or Base64 image for inpaint maskinpaint_mask_upload_checkbox
(bool): this will always truedisable_preview
(bool): disable preview, default falsedisable_intermediate_results
(bool): disable intermediate, default falsedisable_seed_increment
(bool): disable seed increment, default falseblack_out_nsfw
(bool): black out nsfw result, default falseadm_scaler_positive
(float): The scaler multiplied to positive ADM (use 1.0 to disable). default 1.5, range 0.0-3.0adm_scaler_negative
(float): The scaler multiplied to negative ADM (use 1.0 to disable). default 1.5, range 0.0-3.0adm_scaler_end
(float): ADM Guidance End At Step, default 0.8, range 0.0-1.0adaptive_cfg
(float): Adaptive cfg, default 7, range 1.0-30.0clip_skip
(float): clip skip, default 2, range 1-12sampler_name
(string): sampler name, default dpmpp_2m_sde_gpuscheduler_name
(string): scheduler name, default karrasvae_name
(string): VAE name, default Default (model)overwrite_step
(int): overwrite steps in Performance, default -1overwrite_switch
(float): overwrite refiner_switch, default -1overwrite_width
(int): overwrite width in aspect_ratios_selection, default -1, range -1-2048overwrite_height
(int): overwrite height in aspect_ratios_selection, default -1, range -1-2048overwrite_vary_strength
(float): overwrite vary_strength, default -1, range 0.0-1.0overwrite_upscale_strength
(float): overwrite upscale_strength, default -1, range 0.0-1.0mixing_image_prompt_and_vary_upscale
(bool): mixing image prompt and vary_upscale, default falsemixing_image_prompt_and_inpaint
(bool): mixing image prompt and inpaint, default falsedebugging_cn_preprocessor
(bool): debugging cn preprocessor, default falseskipping_cn_preprocessor
(bool): skipping cn preprocessor, default falsecanny_low_threshold
(int): default 64, range 1-255canny_high_threshold
(int): default 128, range 1-255refiner_swap_method
(string): default jointcontrolnet_softness
(float): default 0.25, range 0.0-1.0freeu_enabled
(bool): enable freeu, default falsefreeu_b1
(float): default 1.01freeu_b2
(float): default 1.02freeu_s1
(float): default 0.99freeu_s2
(float): default 0.95debugging_inpaint_preprocessor
(bool): debugging inpaint preprocessor, default falseinpaint_disable_initial_latent
(bool): default falseinpaint_engine
(string): default v2.6inpaint_strength
(float): default 1.0, range 0.0-1.0inpaint_respective_field
(float): default0.618, range 0.0-1.0invert_mask_checkbox
(bool): default false, this always falseinpaint_erode_or_dilate
(int): default 0, range -64-64save_metadata_to_images
(bool): save metadata to images, default truemetadata_scheme
(string): default foocus, one of fooocus, a111controlnet_image
(ImagePrompt): ImagePromptgenerate_image_grid
(bool): default false, suggested to falseoutpaint_distance
(List[int]): outpaint distance, default [0, 0, 0, 0], left, top, right, bottom, this params must with outpaint_selections at the same timeupscale_multiple
(float): default 1.0, range 1.0-5.0, work only upscale method is Upscale (Custom)
preset
(string): preset, default initialstream_output
(bool): stream output, default falserequire_base64
(bool): not usedasync_process
(bool): async process, default falsewebhook_url
(string): Webhook URL, default ""enabled
(bool): enable Lora, default falsemodel_name
(string): Lora file name, default Noneweight
(float): Lora weight, default 0.5, range -2-2cn_img
(str): ImageUrl or base64 imagecn_stop
(float): default 0.6, range 0-1cn_weight
(float): default 0.5, range 0-2cn_type
(string): default ImagePrompt, one of ImagePrompt FaceSwap, PyraCanny, CPDSdescribe
(string): Image prompt.id
(int): id in sqlite, no use for user.task_id
(str): task ID, generate by uuid.uuid4().hex
.req_params
(CommonRequest): required parameters, convert to url for input imagein_queue_mills
(int): in queue time in millis.start_mills
(int): start task time in millis.finish_mills
(int): finish task time in millis.task_status
(str): task status.progress
(float): task progress.preview
(str): previewwebhook_url
(str): Webhook URL.result
(List): result for generateThis project is based on Fooocus-API, thanks all the developers who participated in this project.