2.Click on “Click here to deploy in a new tab", and copy the URL.This is your API endpoint link. Save it for later use.
Step 2: Access the API Documentation
The API provides detailed documentation for various image generation tasks. You can access the internal docs via the /docs endpoint : https://<API_ENDPOINT>/docs
Note: Replace <API_ENDPOINT> with the URL obtained in Step 1.
This enables you to review the API's capabilities and endpoints. The key endpoints to focus on are /sdapi/v1/txt2img and /sdapi/v1/img2img.
In this guide, we'll focus on /sdapi/v1/txt2img.
Step 3: Construct Your Payload
When you expand that tab /sdapi/v1/txt2img , it gives an example of a payload to send to the API.
You can include as few or as many parameters as needed in the payload. The API will use defaults for anything not specified.
The API's response contains three entries: images, parameters, and info. To retrieve the generated image, follow these steps:
r = response.json()
# 'images' is a list of base64-encoded generated images
image = Image.open(io.BytesIO(base64.b64decode(r['images'][0]))
image.save('output.png')
Sample Code
A sample code that should work can look like this:
Lagrange allows you to switch between different models for image generation. This section outlines how to check the available models and how to change models based on your preferences.
1. Checking Available Models
Before changing models, you should explore the models available. Use the following method to obtain a list of models:
import json
import requests
import base64
url = "https://fk5ge5uhhu.mars.nebulablock.com"
username = 'admin'
password = 'admin1234'
# Encode the username and password in Base64
credentials = f'{username}:{password}'
credentials = base64.b64encode(credentials.encode()).decode()
headers = {
'Authorization': f'Basic {credentials}',
'Content-Type': 'application/json' # Adjust content type if necessary
}
response = requests.get(url=f'{url}/sdapi/v1/sd-models', headers=headers)
print(json.dumps(response.json()))
The above code sends a GET request to the /sdapi/v1/sd-models endpoint, providing you with a list of available models.