(Advanced) Accessing Applications Using APIs
API access is disabled by default for the Stable Diffusion application deployed in the application center. You can enable API access by Configuring Function Environment Variables.
Accessing the Application Using an API
- Go to the Stable Diffusion application details page, find the function resource whose logic name is stable_diffusion in the Resource tab, and click the link to go to the function details page.
- Choose Configuration > Environment Variables, click Edit Environment Variable. In the dialog box that is displayed, click Add, add the information in the following table, and click OK.
Table 1 Environment variables for accessing applications using APIs Key
Value
Description
EXTRA_ARGS
--api --api-auth username1:password1,username2:password2 --nowebui
Enter the usernames in username1 and username2, and enter the passwords in password1 and password2. Use commas (,) to separate the usernames and passwords of multiple users.
- After the configuration is complete, you need to enter the username and password when accessing the application using APIs.
Configuring Concurrency Parameters
- WebUI mode
- Set the value of Max. Requests per Instance to 100 or higher. According to testing results, in single-user scenarios, you are advised to set the Max. Requests per Instance to around 15. For multi-user scenarios, the value should be configured to 100 or higher.
- Set the value of Max. Instances per Function to 1. In WebUI mode, the task progress is continuously monitored during image generation. If there are multiple instances, requests may be disordered, which may cause obstacles in progress display and final result display.
- API mode
- Set the value of Max. Requests per Instance between 1 and 5 to ensure that a single instance does not process too many requests. When the concurrent requests reach the upper limit, new instances are triggered to ensure image generation efficiency.
- Set the value of Max. Instances per Function to 400 (default). The value can be changed as needed.
Accessing an Application Using APIs and Enabling WebUI Authentication
To access an application using APIs and enable WebUI authentication, you can set environment variables by referring to Table 2.
Key |
Value |
Description |
---|---|---|
EXTRA_ARGS |
--api --api-auth user1:password1 --gradio-auth user1:password1 |
Enter the usernames in username1 and username2, and enter the passwords in password1 and password2. Use commas (,) to separate the usernames and passwords of multiple users. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot