├── examples ├── python │ ├── code │ │ ├── __init__.py │ │ ├── v1 │ │ │ ├── __init__.py │ │ │ ├── get_account.py │ │ │ ├── get_balance.py │ │ │ ├── list_engines.py │ │ │ ├── upscale_image.py │ │ │ ├── image_to_image.py │ │ │ ├── text_to_image.py │ │ │ └── masking.py │ │ ├── v1alpha │ │ │ ├── __init__.py │ │ │ ├── get_account.py │ │ │ ├── get_balance.py │ │ │ ├── list_engines.py │ │ │ ├── text_to_image.py │ │ │ ├── image_to_image.py │ │ │ └── masking.py │ │ └── v1beta │ │ │ ├── __init__.py │ │ │ ├── get_account.py │ │ │ ├── get_balance.py │ │ │ ├── list_engines.py │ │ │ ├── text_to_image.py │ │ │ ├── image_to_image.py │ │ │ └── masking.py │ ├── pyproject.toml │ ├── run-all.sh │ └── poetry.lock ├── init_image.png ├── mask_image.png ├── mask_image_black.png ├── mask_image_white.png ├── curl │ ├── code │ │ ├── v1 │ │ │ ├── list_engines.sh │ │ │ ├── get_account.sh │ │ │ ├── get_balance.sh │ │ │ ├── upscale_image.sh │ │ │ ├── image_to_image.sh │ │ │ ├── text_to_image.sh │ │ │ └── masking.sh │ │ ├── v1beta │ │ │ ├── list_engines.sh │ │ │ ├── get_account.sh │ │ │ ├── get_balance.sh │ │ │ ├── text_to_image.sh │ │ │ ├── image_to_image.sh │ │ │ └── masking.sh │ │ └── v1alpha │ │ │ ├── get_account.sh │ │ │ ├── list_engines.sh │ │ │ ├── get_balance.sh │ │ │ ├── text_to_image.sh │ │ │ ├── image_to_image.sh │ │ │ └── masking.sh │ └── run-all.sh ├── ts │ ├── package.json │ ├── tsconfig.json │ ├── run-all.sh │ ├── code │ │ ├── v1alpha │ │ │ ├── get_balance.ts │ │ │ ├── list_engines.ts │ │ │ ├── get_account.ts │ │ │ ├── text_to_image.ts │ │ │ ├── image_to_image.ts │ │ │ └── masking.ts │ │ ├── v1 │ │ │ ├── get_balance.ts │ │ │ ├── list_engines.ts │ │ │ ├── get_account.ts │ │ │ ├── upscale_image.ts │ │ │ ├── text_to_image.ts │ │ │ ├── image_to_image.ts │ │ │ └── masking.ts │ │ └── v1beta │ │ │ ├── get_balance.ts │ │ │ ├── list_engines.ts │ │ │ ├── get_account.ts │ │ │ ├── text_to_image.ts │ │ │ ├── image_to_image.ts │ │ │ └── masking.ts │ └── yarn.lock ├── run-all.sh └── go │ ├── run-all.sh │ └── code │ ├── v1 │ ├── get_account.go │ ├── get_balance.go │ ├── list_engines.go │ ├── upscale_image.go │ ├── text_to_image.go │ ├── image_to_image.go │ └── masking.go │ ├── v1alpha │ ├── get_account.go │ ├── get_balance.go │ ├── list_engines.go │ ├── text_to_image.go │ ├── image_to_image.go │ └── masking.go │ └── v1beta │ ├── get_account.go │ ├── get_balance.go │ ├── list_engines.go │ ├── text_to_image.go │ ├── image_to_image.go │ └── masking.go ├── .gitattributes ├── openapi-merge.json ├── .gitignore ├── .redocly.yaml ├── README.md ├── package.json ├── spec ├── info.yaml ├── v1alpha.yaml └── v1beta.yaml └── .github └── workflows └── validate-spec.yml /examples/python/code/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/python/code/v1/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | generated/spec/*.json -diff -merge 2 | generated/spec/*.json linguist-generated 3 | -------------------------------------------------------------------------------- /examples/init_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stability-AI/rest-api-support/HEAD/examples/init_image.png -------------------------------------------------------------------------------- /examples/mask_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stability-AI/rest-api-support/HEAD/examples/mask_image.png -------------------------------------------------------------------------------- /examples/mask_image_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stability-AI/rest-api-support/HEAD/examples/mask_image_black.png -------------------------------------------------------------------------------- /examples/mask_image_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stability-AI/rest-api-support/HEAD/examples/mask_image_white.png -------------------------------------------------------------------------------- /examples/curl/code/v1/list_engines.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | BASE_URL=${API_HOST:-https://api.stability.ai} 7 | URL="$BASE_URL/v1/engines/list" 8 | 9 | curl -f -sS "$URL" \ 10 | -H 'Accept: application/json' \ 11 | -H "Authorization: Bearer $STABILITY_API_KEY" 12 | -------------------------------------------------------------------------------- /openapi-merge.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "inputFile": "./spec/info.yaml" 5 | }, 6 | { 7 | "inputFile": "./generated/spec/v1.json", 8 | "dispute": { 9 | "prefix": "V1" 10 | }, 11 | "pathModification": { 12 | "prepend": "/v1" 13 | } 14 | } 15 | ], 16 | "output": "./generated/spec/merged.json" 17 | } 18 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/list_engines.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | BASE_URL=${API_HOST:-https://api.stability.ai} 7 | URL="$BASE_URL/v1beta/engines/list" 8 | 9 | curl -f -sS "$URL" \ 10 | -H 'Accept: application/json' \ 11 | -H "Authorization: Bearer $STABILITY_API_KEY" 12 | -------------------------------------------------------------------------------- /examples/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-examples", 3 | "version": "1.0.0", 4 | "license": "UNLICENSED", 5 | "type": "module", 6 | "scripts": {}, 7 | "dependencies": { 8 | "form-data": "^4.0.0", 9 | "node-fetch": "^3.3.0", 10 | "tsx": "^3.12.1" 11 | }, 12 | "devDependencies": { 13 | "@types/node": "^18.11.9" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["./code", "./out"], 3 | "compilerOptions": { 4 | "lib": ["esnext", "dom"], 5 | "module": "esnext", 6 | "target": "esnext", 7 | "strict": true, 8 | "esModuleInterop": true, 9 | "skipLibCheck": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "moduleResolution": "node" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/curl/code/v1/get_account.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1/user/account" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Accept: application/json' \ 12 | -H "Authorization: Bearer $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1/get_balance.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1/user/balance" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H "Authorization: Bearer $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/get_account.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1alpha/user/account" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Accept: application/json' \ 12 | -H "Authorization: $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/list_engines.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1alpha/engines/list" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Accept: application/json' \ 12 | -H "Authorization: $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/get_balance.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1alpha/user/balance" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H "Authorization: $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/get_account.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1beta/user/account" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Accept: application/json' \ 12 | -H "Authorization: Bearer $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/get_balance.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | # Determine the URL to use for the request 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1beta/user/balance" 9 | 10 | curl -f -sS "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H "Authorization: Bearer $STABILITY_API_KEY" 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## 2 | # VSCcode 3 | ## 4 | .vscode/* 5 | !.vscode/settings.json 6 | !.vscode/tasks.json 7 | !.vscode/launch.json 8 | !.vscode/extensions.json 9 | !.vscode/*.code-snippets 10 | 11 | # Local History for Visual Studio Code 12 | .history/ 13 | 14 | # Built Visual Studio Code Extensions 15 | *.vsix 16 | 17 | ## 18 | # Project specific 19 | ## 20 | out 21 | out/* 22 | **/out/* 23 | **/node_modules/ 24 | __pycache__/ 25 | .DS_Store 26 | -------------------------------------------------------------------------------- /examples/python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "python-examples" 3 | version = "0.1.0" 4 | description = "Examples of hitting the Stability REST API using Python" 5 | authors = ["Todd Elvers ", "John Sabath "] 6 | license = "UNLICENSED" 7 | packages = [{include = "code"}] 8 | 9 | [tool.poetry.dependencies] 10 | python = "^3.7" 11 | requests = "^2.28.1" 12 | 13 | [build-system] 14 | requires = ["poetry-core"] 15 | build-backend = "poetry.core.masonry.api" 16 | -------------------------------------------------------------------------------- /examples/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Exit on error 4 | set -e 5 | 6 | # Use the 'run-all.sh local' to run these examples against localhost 7 | if [ "$1" = "local" ]; then 8 | export API_HOST=http://localhost:8080 9 | fi 10 | 11 | CWD=$(pwd) 12 | 13 | # Go examples 14 | cd "$CWD/go" 15 | ./run-all.sh 16 | 17 | # Python examples 18 | cd "$CWD/python" 19 | ./run-all.sh 20 | 21 | # TypeScript examples 22 | cd "$CWD/ts" 23 | ./run-all.sh 24 | 25 | # cURL examples 26 | cd "$CWD/curl" 27 | ./run-all.sh 28 | -------------------------------------------------------------------------------- /.redocly.yaml: -------------------------------------------------------------------------------- 1 | # See https://redoc.ly/docs/cli/configuration/ for more information. 2 | extends: 3 | - recommended 4 | 5 | rules: 6 | no-unused-components: warn 7 | info-license: off 8 | # Circle back around and see if we can remove this rule. 9 | no-invalid-media-type-examples: off 10 | 11 | apis: 12 | main@v1: 13 | root: ./spec/v1.yaml 14 | main@v1beta: 15 | root: ./spec/v1beta.yaml 16 | main@v1alpha: 17 | root: ./spec/v1alpha.yaml 18 | 19 | theme: 20 | openapi: 21 | theme: 22 | colors: 23 | primary: 24 | main: "#32329f" 25 | -------------------------------------------------------------------------------- /examples/curl/code/v1/upscale_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1_upscaled_image.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1/generation/esrgan-v1-x2plus/image-to-image/upscale" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: multipart/form-data' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 14 | -F 'image=@"../init_image.png"' \ 15 | -F 'width=1024' \ 16 | -o "$OUTPUT_FILE" 17 | -------------------------------------------------------------------------------- /examples/go/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | echo "\033[0;34mGo examples:\033[0m" 6 | 7 | # Use the 'run-all.sh local' to run these examples against localhost 8 | if [ "$1" = "local" ]; then 9 | export API_HOST=http://localhost:8080 10 | fi 11 | 12 | # Clear output dir 13 | rm -rf out 14 | mkdir out 15 | 16 | # Customize the format that 'time' prints 17 | TIMEFORMAT="%3R seconds" 18 | 19 | # Execute every .go file in the code directory recursively 20 | for file in $(find code -name '*.go'); do 21 | printf "\t %s..." "${file#code/}" 22 | time go run "./$file" 23 | done 24 | -------------------------------------------------------------------------------- /examples/python/code/v1/get_account.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1/user/account" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1/get_balance.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1/user/balance" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/get_account.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1alpha/user/account" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": api_key 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/get_balance.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1alpha/user/balance" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": api_key 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/list_engines.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1alpha/engines/list" 6 | 7 | apiKey = os.getenv("STABILITY_API_KEY") 8 | if apiKey is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": apiKey 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1/list_engines.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1/engines/list" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/get_account.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1beta/user/account" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/get_balance.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1beta/user/balance" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/list_engines.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 5 | url = f"{api_host}/v1beta/engines/list" 6 | 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.get(url, headers={ 12 | "Authorization": f"Bearer {api_key}" 13 | }) 14 | 15 | if response.status_code != 200: 16 | raise Exception("Non-200 response: " + str(response.text)) 17 | 18 | # Do something with the payload... 19 | payload = response.json() 20 | 21 | -------------------------------------------------------------------------------- /examples/ts/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Exit on error 4 | set -e 5 | 6 | echo "\033[0;34mTypeScript examples:\033[0m" 7 | 8 | # Use the 'run-all.sh local' to run these examples against localhost 9 | if [ "$1" = "local" ]; then 10 | export API_HOST=http://localhost:8080 11 | fi 12 | 13 | # Clear output dir 14 | rm -rf out 15 | mkdir out 16 | 17 | # Customize the format that 'time' prints 18 | TIMEFORMAT="%3R seconds" 19 | 20 | # Execute every .ts file in the code directory recursively 21 | for file in $(find code -name '*.ts'); do 22 | printf "\t %s..." "${file#code/}" 23 | time yarn --silent tsx "./$file" 24 | done 25 | -------------------------------------------------------------------------------- /examples/curl/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | echo "\033[0;34mcURL examples:\033[0m" 6 | 7 | # Use the 'run-all.sh local' to run these examples against localhost 8 | if [ "$1" = "local" ]; then 9 | export API_HOST=http://localhost:8080 10 | fi 11 | 12 | # Clear output dir 13 | rm -rf out 14 | mkdir out 15 | 16 | # Customize the format that 'time' prints 17 | TIMEFORMAT="%3R seconds" 18 | 19 | # Execute every .sh file in the code directory recursively 20 | for file in $(find code -name '*.sh'); do 21 | printf "\t %s..." "${file#code/}" 22 | 23 | # Run the script and silence stdout but keep stderr 24 | time "./$file" 1> /dev/null 25 | done 26 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/get_balance.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1alpha/user/balance` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: apiKey, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Balance { 21 | credits: number 22 | } 23 | 24 | // Do something with the balance... 25 | const balance = (await response.json()) as Balance 26 | -------------------------------------------------------------------------------- /examples/ts/code/v1/get_balance.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1/user/balance` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Balance { 21 | credits: number 22 | } 23 | 24 | // Do something with the balance... 25 | const balance = (await response.json()) as Balance 26 | -------------------------------------------------------------------------------- /examples/python/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Exit on error 4 | set -e 5 | 6 | echo "\033[0;34mPython examples:\033[0m" 7 | 8 | # Use the 'run-all.sh local' to run these examples against localhost 9 | if [ "$1" = "local" ]; then 10 | export API_HOST=http://localhost:8080 11 | fi 12 | 13 | # Clear output dir 14 | rm -rf out 15 | mkdir out 16 | 17 | # Customize the format that 'time' prints 18 | TIMEFORMAT="%3R seconds" 19 | 20 | # Execute every .py file in the code directory recursively (ignoring files starting with _) 21 | for file in $(find code -name '*.py' | grep -v '/_'); do 22 | # Remove /code from $file 23 | printf "\t %s..." "${file#code/}" 24 | time poetry run python "./$file" 25 | done 26 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/get_balance.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1beta/user/balance` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Balance { 21 | credits: number 22 | } 23 | 24 | // Do something with the balance... 25 | const balance = (await response.json()) as Balance 26 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/list_engines.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1alpha/engines/list` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: apiKey, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Payload { 21 | engines: Array<{ 22 | id: string 23 | name: string 24 | description: string 25 | type: string 26 | }> 27 | } 28 | 29 | // Do something with the payload... 30 | const payload = (await response.json()) as Payload 31 | -------------------------------------------------------------------------------- /examples/curl/code/v1/image_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1_img2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1/generation/stable-diffusion-v1-5/image-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: multipart/form-data' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 14 | -F 'init_image=@"../init_image.png"' \ 15 | -F 'init_image_mode=IMAGE_STRENGTH' \ 16 | -F 'image_strength=0.35' \ 17 | -F 'text_prompts[0][text]=A galactic dog in space' \ 18 | -F 'cfg_scale=7' \ 19 | -F 'clip_guidance_preset=FAST_BLUE' \ 20 | -F 'samples=1' \ 21 | -F 'steps=30' \ 22 | -o "$OUTPUT_FILE" 23 | -------------------------------------------------------------------------------- /examples/curl/code/v1/text_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1_txt2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1/generation/stable-diffusion-v1-5/text-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 14 | --data-raw '{ 15 | "text_prompts": [ 16 | { 17 | "text": "A lighthouse on a cliff" 18 | } 19 | ], 20 | "cfg_scale": 7, 21 | "clip_guidance_preset": "FAST_BLUE", 22 | "height": 512, 23 | "width": 512, 24 | "samples": 1, 25 | "steps": 30 26 | }' \ 27 | -o "$OUTPUT_FILE" 28 | -------------------------------------------------------------------------------- /examples/ts/code/v1/list_engines.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1/engines/list` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Payload { 21 | engines: Array<{ 22 | id: string 23 | name: string 24 | description: string 25 | type: string 26 | }> 27 | } 28 | 29 | // Do something with the payload... 30 | const payload = (await response.json()) as Payload 31 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/list_engines.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1beta/engines/list` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface Payload { 21 | engines: Array<{ 22 | id: string 23 | name: string 24 | description: string 25 | type: string 26 | }> 27 | } 28 | 29 | // Do something with the payload... 30 | const payload = (await response.json()) as Payload 31 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/text_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1beta_txt2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1beta/generation/stable-diffusion-v1-5/text-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 14 | --data-raw '{ 15 | "text_prompts": [ 16 | { 17 | "text": "A lighthouse on a cliff" 18 | } 19 | ], 20 | "cfg_scale": 7, 21 | "clip_guidance_preset": "FAST_BLUE", 22 | "height": 512, 23 | "width": 512, 24 | "samples": 1, 25 | "steps": 50 26 | }' \ 27 | -o "$OUTPUT_FILE" 28 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/text_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1alpha_txt2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1alpha/generation/stable-diffusion-v1-5/text-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: application/json' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: $STABILITY_API_KEY" \ 14 | --data-raw '{ 15 | "cfg_scale": 7, 16 | "clip_guidance_preset": "FAST_BLUE", 17 | "height": 512, 18 | "width": 512, 19 | "samples": 1, 20 | "steps": 50, 21 | "text_prompts": [ 22 | { 23 | "text": "A lighthouse on a cliff", 24 | "weight": 1 25 | } 26 | ] 27 | }' \ 28 | -o "$OUTPUT_FILE" 29 | -------------------------------------------------------------------------------- /examples/python/code/v1/upscale_image.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | engine_id = "esrgan-v1-x2plus" 5 | api_host = os.getenv("API_HOST", "https://api.stability.ai") 6 | api_key = os.getenv("STABILITY_API_KEY") 7 | 8 | if api_key is None: 9 | raise Exception("Missing Stability API key.") 10 | 11 | response = requests.post( 12 | f"{api_host}/v1/generation/{engine_id}/image-to-image/upscale", 13 | headers={ 14 | "Accept": "image/png", 15 | "Authorization": f"Bearer {api_key}" 16 | }, 17 | files={ 18 | "image": open("../init_image.png", "rb") 19 | }, 20 | data={ 21 | "width": 1024, 22 | } 23 | ) 24 | 25 | if response.status_code != 200: 26 | raise Exception("Non-200 response: " + str(response.text)) 27 | 28 | with open(f"./out/v1_upscaled_image.png", "wb") as f: 29 | f.write(response.content) 30 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/get_account.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1alpha/user/account` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: apiKey, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface User { 21 | id: string 22 | profile_picture: string 23 | email: string 24 | organizations?: Array<{ 25 | id: string 26 | name: string 27 | role: string 28 | is_default: boolean 29 | }> 30 | } 31 | 32 | // Do something with the user... 33 | const user = (await response.json()) as User 34 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/image_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1beta_img2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1beta/generation/stable-diffusion-v1-5/image-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: multipart/form-data' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 14 | -F 'init_image=@"../init_image.png"' \ 15 | -F 'init_image_mode=IMAGE_STRENGTH' \ 16 | -F 'image_strength=0.35' \ 17 | -F 'text_prompts[0][text]=A galactic dog in space' \ 18 | -F 'cfg_scale=7' \ 19 | -F 'clip_guidance_preset=FAST_BLUE' \ 20 | -F 'height=512' \ 21 | -F 'width=512' \ 22 | -F 'samples=1' \ 23 | -F 'steps=50' \ 24 | -o "$OUTPUT_FILE" 25 | -------------------------------------------------------------------------------- /examples/ts/code/v1/get_account.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1/user/account` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface User { 21 | id: string 22 | profile_picture: string 23 | email: string 24 | organizations?: Array<{ 25 | id: string 26 | name: string 27 | role: string 28 | is_default: boolean 29 | }> 30 | } 31 | 32 | // Do something with the user... 33 | const user = (await response.json()) as User 34 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/get_account.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | 3 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 4 | const url = `${apiHost}/v1beta/user/account` 5 | 6 | const apiKey = process.env.STABILITY_API_KEY 7 | if (!apiKey) throw new Error('Missing Stability API key.') 8 | 9 | const response = await fetch(url, { 10 | method: 'GET', 11 | headers: { 12 | Authorization: `Bearer ${apiKey}`, 13 | }, 14 | }) 15 | 16 | if (!response.ok) { 17 | throw new Error(`Non-200 response: ${await response.text()}`) 18 | } 19 | 20 | interface User { 21 | id: string 22 | profile_picture: string 23 | email: string 24 | organizations?: Array<{ 25 | id: string 26 | name: string 27 | role: string 28 | is_default: boolean 29 | }> 30 | } 31 | 32 | // Do something with the user... 33 | const user = (await response.json()) as User 34 | -------------------------------------------------------------------------------- /examples/curl/code/v1/masking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ -z "$STABILITY_API_KEY" ]; then 6 | echo "STABILITY_API_KEY environment variable is not set" 7 | exit 1 8 | fi 9 | 10 | OUTPUT_FILE=./out/v1_img2img_masking.png 11 | BASE_URL=${API_HOST:-https://api.stability.ai} 12 | URL="$BASE_URL/v1/generation/stable-inpainting-512-v2-0/image-to-image/masking" 13 | 14 | curl -f -sS -X POST "$URL" \ 15 | -H 'Content-Type: multipart/form-data' \ 16 | -H 'Accept: image/png' \ 17 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 18 | -F 'init_image=@"../init_image.png"' \ 19 | -F 'mask_image=@"../mask_image_white.png"' \ 20 | -F 'mask_source=MASK_IMAGE_WHITE' \ 21 | -F 'text_prompts[0][text]=A large spiral galaxy with a bright central bulge and a ring of stars around it' \ 22 | -F 'cfg_scale=7' \ 23 | -F 'clip_guidance_preset=FAST_BLUE' \ 24 | -F 'samples=1' \ 25 | -F 'steps=30' \ 26 | -o "$OUTPUT_FILE" 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stability.ai REST API 2 | 3 | The purpose of this repo is to capture discussions, issues, and examples, regarding the Stability.ai REST API. 4 | 5 | --- 6 | 7 | ### Status: V1 (stable) 8 | 9 | - [API Documentation](https://api.stability.ai) 10 | 11 | Your DreamStudio API key will be required for authentication. You can learn more about API keys here: https://platform.stability.ai/docs/getting-started/authentication 12 | 13 | If you encounter bugs or have a suggestion for the API, please create an issue [here](https://github.com/Stability-AI/REST-API/issues/new/choose) for us to track. 14 | 15 | We also have a support discord channel: [#official-rest-api](https://discord.com/channels/1002292111942635562/1042896447311454361) in https://discord.gg/stablediffusion 16 | 17 | --- 18 | 19 | ### Other Links 20 | 21 | #### Stability.ai gRPC API 22 | 23 | - [API Definitions](https://github.com/Stability-AI/api-interfaces) 24 | - [Python SDK](https://github.com/Stability-AI/stability-sdk) 25 | -------------------------------------------------------------------------------- /examples/curl/code/v1beta/masking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ -z "$STABILITY_API_KEY" ]; then 6 | echo "STABILITY_API_KEY environment variable is not set" 7 | exit 1 8 | fi 9 | 10 | OUTPUT_FILE=./out/v1beta_img2img_masking.png 11 | BASE_URL=${API_HOST:-https://api.stability.ai} 12 | URL="$BASE_URL/v1beta/generation/stable-inpainting-512-v2-0/image-to-image/masking" 13 | 14 | curl -f -sS -X POST "$URL" \ 15 | -H 'Content-Type: multipart/form-data' \ 16 | -H 'Accept: image/png' \ 17 | -H "Authorization: Bearer $STABILITY_API_KEY" \ 18 | -F 'init_image=@"../init_image.png"' \ 19 | -F 'mask_image=@"../mask_image_white.png"' \ 20 | -F 'mask_source=MASK_IMAGE_WHITE' \ 21 | -F 'text_prompts[0][text]=A large spiral galaxy with a bright central bulge and a ring of stars around it' \ 22 | -F 'cfg_scale=7' \ 23 | -F 'clip_guidance_preset=FAST_BLUE' \ 24 | -F 'height=512' \ 25 | -F 'width=512' \ 26 | -F 'samples=1' \ 27 | -F 'steps=50' \ 28 | -o "$OUTPUT_FILE" 29 | -------------------------------------------------------------------------------- /examples/go/code/v1/get_account.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1/user/account" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1/get_balance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1/user/balance" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/get_account.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1alpha/user/account" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/get_balance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1alpha/user/balance" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1/list_engines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1/engines/list" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Execute the request & read all the bytes of the response 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | res, _ := http.DefaultClient.Do(req) 27 | defer res.Body.Close() 28 | body, _ := io.ReadAll(res.Body) 29 | 30 | if res.StatusCode != 200 { 31 | panic("Non-200 response: " + string(body)) 32 | } 33 | 34 | // Do something with the payload... 35 | // payload := string(body) 36 | } 37 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/list_engines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1alpha/engines/list" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Execute the request & read all the bytes of the response 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", apiKey) 26 | res, _ := http.DefaultClient.Do(req) 27 | defer res.Body.Close() 28 | body, _ := io.ReadAll(res.Body) 29 | 30 | if res.StatusCode != 200 { 31 | panic("Non-200 response: " + string(body)) 32 | } 33 | 34 | // Do something with the payload... 35 | // payload := string(body) 36 | } 37 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/get_account.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1beta/user/account" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/get_balance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1beta/user/balance" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Build the request 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | 27 | // Execute the request 28 | res, _ := http.DefaultClient.Do(req) 29 | defer res.Body.Close() 30 | body, _ := io.ReadAll(res.Body) 31 | 32 | if res.StatusCode != 200 { 33 | panic("Non-200 response: " + string(body)) 34 | } 35 | 36 | // Do something with the payload... 37 | // payload := string(body) 38 | } 39 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/list_engines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // Build REST endpoint URL 11 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 12 | if !hasApiHost { 13 | apiHost = "https://api.stability.ai" 14 | } 15 | reqUrl := apiHost + "/v1beta/engines/list" 16 | 17 | // Acquire an API key from the environment 18 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 19 | if !hasAPIKey { 20 | panic("Missing STABILITY_API_KEY environment variable") 21 | } 22 | 23 | // Execute the request & read all the bytes of the response 24 | req, _ := http.NewRequest("GET", reqUrl, nil) 25 | req.Header.Add("Authorization", "Bearer "+apiKey) 26 | res, _ := http.DefaultClient.Do(req) 27 | defer res.Body.Close() 28 | body, _ := io.ReadAll(res.Body) 29 | 30 | if res.StatusCode != 200 { 31 | panic("Non-200 response: " + string(body)) 32 | } 33 | 34 | // Do something with the payload... 35 | // payload := string(body) 36 | } 37 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/image_to_image.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$STABILITY_API_KEY" ]; then 2 | echo "STABILITY_API_KEY environment variable is not set" 3 | exit 1 4 | fi 5 | 6 | OUTPUT_FILE=./out/v1alpha_img2img.png 7 | BASE_URL=${API_HOST:-https://api.stability.ai} 8 | URL="$BASE_URL/v1alpha/generation/stable-diffusion-v1-5/image-to-image" 9 | 10 | curl -f -sS -X POST "$URL" \ 11 | -H 'Content-Type: multipart/form-data' \ 12 | -H 'Accept: image/png' \ 13 | -H "Authorization: $STABILITY_API_KEY" \ 14 | -F 'init_image=@"../init_image.png"' \ 15 | -F 'options="{ 16 | \"cfg_scale\": 7, 17 | \"clip_guidance_preset\": \"FAST_BLUE\", 18 | \"step_schedule_start\": 0.6, 19 | \"step_schedule_end\": 0.01, 20 | \"height\": 512, 21 | \"width\": 512, 22 | \"samples\": 1, 23 | \"steps\": 50, 24 | \"text_prompts\": [{ 25 | \"text\": \"A large spiral galaxy dog with a bright central bulge and a ring of stars around it\", 26 | \"weight\": 1 27 | }] 28 | }"' \ 29 | -o "$OUTPUT_FILE" 30 | -------------------------------------------------------------------------------- /examples/curl/code/v1alpha/masking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ -z "$STABILITY_API_KEY" ]; then 6 | echo "STABILITY_API_KEY environment variable is not set" 7 | exit 1 8 | fi 9 | 10 | OUTPUT_FILE=./out/v1alpha_img2img_masking.png 11 | BASE_URL=${API_HOST:-https://api.stability.ai} 12 | URL="$BASE_URL/v1alpha/generation/stable-inpainting-512-v2-0/image-to-image/masking" 13 | 14 | curl -f -sS -X POST "$URL" \ 15 | -H 'Content-Type: multipart/form-data' \ 16 | -H 'Accept: image/png' \ 17 | -H "Authorization: $STABILITY_API_KEY" \ 18 | -F 'init_image=@"../init_image.png"' \ 19 | -F 'mask_image=@"../mask_image_white.png"' \ 20 | -F 'options="{ 21 | \"mask_source\": \"MASK_IMAGE_WHITE\", 22 | \"cfg_scale\": 7, 23 | \"clip_guidance_preset\": \"FAST_BLUE\", 24 | \"height\": 512, 25 | \"width\": 512, 26 | \"samples\": 1, 27 | \"steps\": 50, 28 | \"text_prompts\": [{ 29 | \"text\": \"A large spiral galaxy dog with a bright central bulge and a ring of stars around it\", 30 | \"weight\": 1 31 | }] 32 | }"' \ 33 | -o "$OUTPUT_FILE" 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stability.ai-rest-api", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docs:merged": "yarn generate && redocly preview-docs -p 3000 ./generated/spec/merged.json", 7 | "docs:v1alpha": "redocly preview-docs -p 3000 main@v1alpha", 8 | "docs:v1beta": "redocly preview-docs -p 3000 main@v1beta", 9 | "docs:v1": "redocly preview-docs -p 3000 main@v1", 10 | "docs": "yarn docs:v1", 11 | "generate:bundle": "redocly bundle --ext json -o ./generated/spec", 12 | "generate:merge": "openapi-merge-cli", 13 | "generate": "yarn generate:bundle && yarn generate:merge", 14 | "lint:merged": "yarn generate && redocly lint ./generated/spec/merged.json", 15 | "lint:v1alpha": "redocly lint main@v1alpha", 16 | "lint:v1beta": "redocly lint main@v1beta", 17 | "lint:v1": "redocly lint main@v1", 18 | "lint": "yarn lint:v1alpha && yarn lint:v1beta && yarn lint:v1 && yarn lint:merged" 19 | }, 20 | "devDependencies": { 21 | "@redocly/cli": "^1.0.0-beta.122", 22 | "core-js": "^3.1.4", 23 | "openapi-merge-cli": "^1.3.1", 24 | "react-is": ">=16.8.0", 25 | "webpack": "^5.0.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/text_to_image.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | engine_id = "stable-diffusion-v1-5" 5 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 6 | url = f"{api_host}/v1alpha/generation/{engine_id}/text-to-image" 7 | output_file = "./out/v1alpha_txt2img.png" 8 | 9 | apiKey = os.getenv("STABILITY_API_KEY") 10 | if apiKey is None: 11 | raise Exception("Missing Stability API key.") 12 | 13 | payload = { 14 | "cfg_scale": 7, 15 | "clip_guidance_preset": "FAST_BLUE", 16 | "height": 512, 17 | "width": 512, 18 | "samples": 1, 19 | "steps": 50, 20 | "text_prompts": [ 21 | { 22 | "text": "A lighthouse on a cliff", 23 | "weight": 1 24 | } 25 | ], 26 | } 27 | 28 | headers = { 29 | "Content-Type": "application/json", 30 | "Accept": "image/png", 31 | "Authorization": apiKey 32 | } 33 | 34 | response = requests.post(url, json=payload, headers=headers) 35 | 36 | if response.status_code != 200: 37 | raise Exception("Non-200 response: " + str(response.text)) 38 | 39 | # Write the bytes from response.content to a file 40 | with open(output_file, "wb") as f: 41 | f.write(response.content) 42 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/text_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import fs from 'node:fs' 3 | 4 | const engineId = 'stable-diffusion-v1-5' 5 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 6 | const url = `${apiHost}/v1alpha/generation/${engineId}/text-to-image` 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | const response = await fetch(url, { 12 | method: 'POST', 13 | headers: { 14 | 'Content-Type': 'application/json', 15 | Accept: 'image/png', 16 | Authorization: apiKey, 17 | }, 18 | body: JSON.stringify({ 19 | cfg_scale: 7, 20 | clip_guidance_preset: 'FAST_BLUE', 21 | height: 512, 22 | width: 512, 23 | samples: 1, 24 | steps: 50, 25 | text_prompts: [ 26 | { 27 | text: 'A lighthouse on a cliff', 28 | weight: 1, 29 | }, 30 | ], 31 | }), 32 | }) 33 | 34 | if (!response.ok) { 35 | throw new Error(`Non-200 response: ${await response.text()}`) 36 | } 37 | 38 | try { 39 | const writeStream = fs.createWriteStream(`./out/v1alpha_txt2img.png`) 40 | response.body?.pipe(writeStream) 41 | } catch (e) { 42 | console.error(e) 43 | } 44 | -------------------------------------------------------------------------------- /examples/ts/code/v1/upscale_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'esrgan-v1-x2plus' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. 12 | // Browsers should use their native FormData class. 13 | // React Native apps should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('image', fs.readFileSync('../init_image.png')) 16 | formData.append('width', 1024) 17 | 18 | const response = await fetch( 19 | `${apiHost}/v1/generation/${engineId}/image-to-image/upscale`, 20 | { 21 | method: 'POST', 22 | headers: { 23 | ...formData.getHeaders(), 24 | Accept: 'image/png', 25 | Authorization: `Bearer ${apiKey}`, 26 | }, 27 | body: formData, 28 | } 29 | ) 30 | 31 | if (!response.ok) { 32 | throw new Error(`Non-200 response: ${await response.text()}`) 33 | } 34 | 35 | const image = await response.arrayBuffer() 36 | fs.writeFileSync('./out/v1_upscaled_image.png', Buffer.from(image)) 37 | -------------------------------------------------------------------------------- /examples/python/code/v1/image_to_image.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-diffusion-v1-5" 6 | api_host = os.getenv("API_HOST", "https://api.stability.ai") 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1/generation/{engine_id}/image-to-image", 14 | headers={ 15 | "Accept": "application/json", 16 | "Authorization": f"Bearer {api_key}" 17 | }, 18 | files={ 19 | "init_image": open("../init_image.png", "rb") 20 | }, 21 | data={ 22 | "image_strength": 0.35, 23 | "init_image_mode": "IMAGE_STRENGTH", 24 | "text_prompts[0][text]": "Galactic dog with a cape", 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "samples": 1, 28 | "steps": 30, 29 | } 30 | ) 31 | 32 | if response.status_code != 200: 33 | raise Exception("Non-200 response: " + str(response.text)) 34 | 35 | data = response.json() 36 | 37 | for i, image in enumerate(data["artifacts"]): 38 | with open(f"./out/v1_img2img_{i}.png", "wb") as f: 39 | f.write(base64.b64decode(image["base64"])) 40 | -------------------------------------------------------------------------------- /examples/python/code/v1/text_to_image.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-diffusion-v1-5" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1/generation/{engine_id}/text-to-image", 14 | headers={ 15 | "Content-Type": "application/json", 16 | "Accept": "application/json", 17 | "Authorization": f"Bearer {api_key}" 18 | }, 19 | json={ 20 | "text_prompts": [ 21 | { 22 | "text": "A lighthouse on a cliff" 23 | } 24 | ], 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "height": 512, 28 | "width": 512, 29 | "samples": 1, 30 | "steps": 30, 31 | }, 32 | ) 33 | 34 | if response.status_code != 200: 35 | raise Exception("Non-200 response: " + str(response.text)) 36 | 37 | data = response.json() 38 | 39 | for i, image in enumerate(data["artifacts"]): 40 | with open(f"./out/v1_txt2img_{i}.png", "wb") as f: 41 | f.write(base64.b64decode(image["base64"])) 42 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/text_to_image.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-diffusion-v1-5" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1beta/generation/{engine_id}/text-to-image", 14 | headers={ 15 | "Content-Type": "application/json", 16 | "Accept": "application/json", 17 | "Authorization": f"Bearer {api_key}" 18 | }, 19 | json={ 20 | "text_prompts": [ 21 | { 22 | "text": "A lighthouse on a cliff" 23 | } 24 | ], 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "height": 512, 28 | "width": 512, 29 | "samples": 1, 30 | "steps": 50, 31 | }, 32 | ) 33 | 34 | if response.status_code != 200: 35 | raise Exception("Non-200 response: " + str(response.text)) 36 | 37 | data = response.json() 38 | 39 | for i, image in enumerate(data["artifacts"]): 40 | with open(f"./out/v1beta_txt2img_{i}.png", "wb") as f: 41 | f.write(base64.b64decode(image["base64"])) 42 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/image_to_image.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-diffusion-v1-5" 6 | api_host = os.getenv("API_HOST", "https://api.stability.ai") 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1beta/generation/{engine_id}/image-to-image", 14 | headers={ 15 | "Accept": "application/json", 16 | "Authorization": f"Bearer {api_key}" 17 | }, 18 | files={ 19 | "init_image": open("../init_image.png", "rb") 20 | }, 21 | data={ 22 | "image_strength": 0.35, 23 | "init_image_mode": "IMAGE_STRENGTH", 24 | "text_prompts[0][text]": "Galactic dog with a cape", 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "height": 512, 28 | "width": 512, 29 | "samples": 1, 30 | "steps": 50, 31 | } 32 | ) 33 | 34 | if response.status_code != 200: 35 | raise Exception("Non-200 response: " + str(response.text)) 36 | 37 | data = response.json() 38 | 39 | for i, image in enumerate(data["artifacts"]): 40 | with open(f"./out/v1beta_img2img_{i}.png", "wb") as f: 41 | f.write(base64.b64decode(image["base64"])) 42 | -------------------------------------------------------------------------------- /spec/info.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | termsOfService: 'https://platform.stability.ai/docs/terms-of-service' 3 | description: | 4 | Welcome to the Stability.ai REST API! 5 | 6 | Your DreamStudio API key will be required for authentication: [How to find your API key](https://platform.stability.ai/docs/getting-started/authentication) 7 | 8 | API operations use the following versioning scheme: 9 | - `/v*` interface is stable and ready for production workloads 10 | - `/v*beta*`: interface is stable, preparing for production release 11 | - `/v*alpha*`: under development and the interface is subject to change 12 | 13 | NOTE: The v1alpha and v1beta endpoints from the developer preview are still available, but they 14 | will disabled on May 1st, 2023. Please migrate to the v1 endpoints as soon as possible. 15 | 16 | If you have feedback or encounter any issues with the API, please reach out: 17 | - [https://github.com/Stability-AI/REST-API](https://github.com/Stability-AI/REST-API) 18 | - [https://discord.gg/stablediffusion #API channel](https://discord.com/channels/1002292111942635562/1042896447311454361) 19 | title: Stability.ai REST API 20 | version: 'v1' 21 | x-logo: 22 | altText: Stability.ai REST API 23 | url: /docs/StabilityLogo.png 24 | servers: 25 | - url: https://api.stability.ai 26 | -------------------------------------------------------------------------------- /examples/python/code/v1/masking.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-inpainting-512-v2-0" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1/generation/{engine_id}/image-to-image/masking", 14 | headers={ 15 | "Accept": 'application/json', 16 | "Authorization": f"Bearer {api_key}" 17 | }, 18 | files={ 19 | 'init_image': open("../init_image.png", 'rb'), 20 | 'mask_image': open("../mask_image_white.png", 'rb'), 21 | }, 22 | data={ 23 | "mask_source": "MASK_IMAGE_WHITE", 24 | "text_prompts[0][text]": "A large spiral galaxy with a bright central bulge and a ring of stars around it", 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "samples": 1, 28 | "steps": 30, 29 | } 30 | ) 31 | 32 | if response.status_code != 200: 33 | raise Exception("Non-200 response: " + str(response.text)) 34 | 35 | data = response.json() 36 | 37 | for i, image in enumerate(data["artifacts"]): 38 | with open(f"./out/v1_img2img_masking_{i}.png", "wb") as f: 39 | f.write(base64.b64decode(image["base64"])) 40 | -------------------------------------------------------------------------------- /examples/python/code/v1beta/masking.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-inpainting-512-v2-0" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | api_key = os.getenv("STABILITY_API_KEY") 8 | 9 | if api_key is None: 10 | raise Exception("Missing Stability API key.") 11 | 12 | response = requests.post( 13 | f"{api_host}/v1beta/generation/{engine_id}/image-to-image/masking", 14 | headers={ 15 | "Accept": 'application/json', 16 | "Authorization": f"Bearer {api_key}" 17 | }, 18 | files={ 19 | 'init_image': open("../init_image.png", 'rb'), 20 | 'mask_image': open("../mask_image_white.png", 'rb'), 21 | }, 22 | data={ 23 | "mask_source": "MASK_IMAGE_WHITE", 24 | "text_prompts[0][text]": "A large spiral galaxy with a bright central bulge and a ring of stars around it", 25 | "cfg_scale": 7, 26 | "clip_guidance_preset": "FAST_BLUE", 27 | "height": 512, 28 | "width": 512, 29 | "samples": 1, 30 | "steps": 50, 31 | } 32 | ) 33 | 34 | if response.status_code != 200: 35 | raise Exception("Non-200 response: " + str(response.text)) 36 | 37 | data = response.json() 38 | 39 | for i, image in enumerate(data["artifacts"]): 40 | with open(f"./out/v1beta_img2img_masking_{i}.png", "wb") as f: 41 | f.write(base64.b64decode(image["base64"])) 42 | -------------------------------------------------------------------------------- /examples/ts/code/v1/text_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import fs from 'node:fs' 3 | 4 | const engineId = 'stable-diffusion-v1-5' 5 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 6 | const apiKey = process.env.STABILITY_API_KEY 7 | 8 | if (!apiKey) throw new Error('Missing Stability API key.') 9 | 10 | const response = await fetch( 11 | `${apiHost}/v1/generation/${engineId}/text-to-image`, 12 | { 13 | method: 'POST', 14 | headers: { 15 | 'Content-Type': 'application/json', 16 | Accept: 'application/json', 17 | Authorization: `Bearer ${apiKey}`, 18 | }, 19 | body: JSON.stringify({ 20 | text_prompts: [ 21 | { 22 | text: 'A lighthouse on a cliff', 23 | }, 24 | ], 25 | cfg_scale: 7, 26 | clip_guidance_preset: 'FAST_BLUE', 27 | height: 512, 28 | width: 512, 29 | samples: 1, 30 | steps: 30, 31 | }), 32 | } 33 | ) 34 | 35 | if (!response.ok) { 36 | throw new Error(`Non-200 response: ${await response.text()}`) 37 | } 38 | 39 | interface GenerationResponse { 40 | artifacts: Array<{ 41 | base64: string 42 | seed: number 43 | finishReason: string 44 | }> 45 | } 46 | 47 | const responseJSON = (await response.json()) as GenerationResponse 48 | 49 | responseJSON.artifacts.forEach((image, index) => { 50 | fs.writeFileSync( 51 | `./out/v1_txt2img_${index}.png`, 52 | Buffer.from(image.base64, 'base64') 53 | ) 54 | }) 55 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/text_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import fs from 'node:fs' 3 | 4 | const engineId = 'stable-diffusion-v1-5' 5 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 6 | const apiKey = process.env.STABILITY_API_KEY 7 | 8 | if (!apiKey) throw new Error('Missing Stability API key.') 9 | 10 | const response = await fetch( 11 | `${apiHost}/v1beta/generation/${engineId}/text-to-image`, 12 | { 13 | method: 'POST', 14 | headers: { 15 | 'Content-Type': 'application/json', 16 | Accept: 'application/json', 17 | Authorization: `Bearer ${apiKey}`, 18 | }, 19 | body: JSON.stringify({ 20 | text_prompts: [ 21 | { 22 | text: 'A lighthouse on a cliff', 23 | }, 24 | ], 25 | cfg_scale: 7, 26 | clip_guidance_preset: 'FAST_BLUE', 27 | height: 512, 28 | width: 512, 29 | samples: 1, 30 | steps: 50, 31 | }), 32 | } 33 | ) 34 | 35 | if (!response.ok) { 36 | throw new Error(`Non-200 response: ${await response.text()}`) 37 | } 38 | 39 | interface GenerationResponse { 40 | artifacts: Array<{ 41 | base64: string 42 | seed: number 43 | finishReason: string 44 | }> 45 | } 46 | 47 | const responseJSON = (await response.json()) as GenerationResponse 48 | 49 | responseJSON.artifacts.forEach((image, index) => { 50 | fs.writeFileSync( 51 | `./out/v1beta_txt2img_${index}.png`, 52 | Buffer.from(image.base64, 'base64') 53 | ) 54 | }) 55 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/image_to_image.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-diffusion-v1-5" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | url = f"{api_host}/v1alpha/generation/{engine_id}/image-to-image" 8 | 9 | init_image = "../init_image.png" 10 | output_file = "./out/v1alpha_img2img.png" 11 | 12 | api_key = os.getenv("STABILITY_API_KEY") 13 | if api_key is None: 14 | raise Exception("Missing Stability API key.") 15 | 16 | options = json.dumps( 17 | { 18 | "cfg_scale": 7, 19 | "clip_guidance_preset": "FAST_BLUE", 20 | "step_schedule_start": 0.6, 21 | "step_schedule_end": 0.01, 22 | "height": 512, 23 | "width": 512, 24 | "samples": 1, 25 | "steps": 50, 26 | "text_prompts": [ 27 | { 28 | "text": "A large spiral galaxy dog with a bright central bulge and a ring of stars around it", 29 | "weight": 1 30 | } 31 | ], 32 | } 33 | ) 34 | 35 | headers = { 36 | 'accept': 'image/png', 37 | 'Authorization': api_key, 38 | } 39 | 40 | files = { 41 | 'init_image': open(init_image, 'rb'), 42 | 'options': (None, options), 43 | } 44 | 45 | response = requests.post(url, headers=headers, files=files) 46 | 47 | if response.status_code != 200: 48 | raise Exception("Non-200 response: " + str(response.text)) 49 | 50 | # Write the bytes from response.content to a file 51 | with open(output_file, "wb") as f: 52 | f.write(response.content) 53 | -------------------------------------------------------------------------------- /examples/python/code/v1alpha/masking.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import requests 4 | 5 | engine_id = "stable-inpainting-512-v2-0" 6 | api_host = os.getenv('API_HOST', 'https://api.stability.ai') 7 | url = f"{api_host}/v1alpha/generation/{engine_id}/image-to-image/masking" 8 | 9 | init_image = "../init_image.png" 10 | mask_image = "../mask_image_white.png" 11 | output_file = "./out/v1alpha_img2img_masking.png" 12 | 13 | api_key = os.getenv("STABILITY_API_KEY") 14 | if api_key is None: 15 | raise Exception("Missing Stability API key.") 16 | 17 | options = json.dumps( 18 | { 19 | "mask_source": "MASK_IMAGE_WHITE", 20 | "cfg_scale": 7, 21 | "clip_guidance_preset": "FAST_BLUE", 22 | "height": 512, 23 | "width": 512, 24 | "samples": 1, 25 | "steps": 50, 26 | "text_prompts": [ 27 | { 28 | "text": "A large spiral galaxy dog with a bright central bulge and a ring of stars around it", 29 | "weight": 1 30 | } 31 | ], 32 | } 33 | ) 34 | 35 | headers = { 36 | 'accept': 'image/png', 37 | 'Authorization': api_key, 38 | } 39 | 40 | files = { 41 | 'init_image': open(init_image, 'rb'), 42 | 'mask_image': open(mask_image, 'rb'), 43 | 'options': (None, options), 44 | } 45 | 46 | response = requests.post(url, headers=headers, files=files) 47 | 48 | if response.status_code != 200: 49 | raise Exception("Non-200 response: " + str(response.text)) 50 | 51 | # Write the bytes from response.content to a file 52 | with open(output_file, "wb") as f: 53 | f.write(response.content) 54 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/text_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net/http" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | // Build REST endpoint URL w/ specified engine 12 | engineId := "stable-diffusion-v1-5" 13 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 14 | if !hasApiHost { 15 | apiHost = "https://api.stability.ai" 16 | } 17 | reqUrl := apiHost + "/v1alpha/generation/" + engineId + "/text-to-image" 18 | 19 | // Acquire an API key from the environment 20 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 21 | if !hasAPIKey { 22 | panic("Missing STABILITY_API_KEY environment variable") 23 | } 24 | 25 | var data = []byte(`{ 26 | "cfg_scale": 7, 27 | "clip_guidance_preset": "FAST_BLUE", 28 | "height": 512, 29 | "width": 512, 30 | "samples": 1, 31 | "steps": 50, 32 | "text_prompts": [ 33 | { 34 | "text": "A lighthouse on a cliff", 35 | "weight": 1 36 | } 37 | ] 38 | }`) 39 | 40 | req, _ := http.NewRequest("POST", reqUrl, bytes.NewBuffer(data)) 41 | req.Header.Add("Content-Type", "application/json") 42 | req.Header.Add("Accept", "image/png") 43 | req.Header.Add("Authorization", apiKey) 44 | 45 | // Execute the request & read all the bytes of the response 46 | res, _ := http.DefaultClient.Do(req) 47 | defer res.Body.Close() 48 | body, _ := io.ReadAll(res.Body) 49 | 50 | if res.StatusCode != 200 { 51 | panic("Non-200 response: " + string(body)) 52 | } 53 | 54 | // Write the bytes to a file 55 | file, _ := os.Create("./out/v1alpha_txt2img.png") 56 | defer file.Close() 57 | _, err := file.Write(body) 58 | if err != nil { 59 | panic(err) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/image_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-diffusion-v1-5' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. Browser 12 | // implementations should use their native FormData class. React Native 13 | // implementations should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('init_image', fs.readFileSync('../init_image.png')) 16 | formData.append( 17 | 'options', 18 | JSON.stringify({ 19 | cfg_scale: 7, 20 | clip_guidance_preset: 'FAST_BLUE', 21 | step_schedule_start: 0.6, 22 | step_schedule_end: 0.01, 23 | height: 512, 24 | width: 512, 25 | samples: 1, 26 | steps: 50, 27 | text_prompts: [ 28 | { 29 | text: 'Galactic dog', 30 | weight: 1, 31 | }, 32 | ], 33 | }) 34 | ) 35 | 36 | const response = await fetch( 37 | `${apiHost}/v1alpha/generation/${engineId}/image-to-image`, 38 | { 39 | method: 'POST', 40 | headers: { 41 | ...formData.getHeaders(), 42 | Accept: 'image/png', 43 | Authorization: apiKey, 44 | }, 45 | body: formData, 46 | } 47 | ) 48 | 49 | if (!response.ok) { 50 | throw new Error(`Non-200 response: ${await response.text()}`) 51 | } 52 | 53 | try { 54 | const writeStream = fs.createWriteStream(`./out/v1alpha_img2img.png`) 55 | response.body?.pipe(writeStream) 56 | } catch (e) { 57 | console.error(e) 58 | } 59 | -------------------------------------------------------------------------------- /examples/ts/code/v1alpha/masking.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-inpainting-512-v2-0' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. Browser 12 | // implementations should use their native FormData class. React Native 13 | // implementations should also use their native FormData class. 14 | const form = new FormData() 15 | form.append('init_image', fs.readFileSync('../init_image.png')) 16 | form.append('mask_image', fs.readFileSync('../mask_image_white.png')) 17 | form.append( 18 | 'options', 19 | JSON.stringify({ 20 | mask_source: 'MASK_IMAGE_WHITE', 21 | cfg_scale: 7, 22 | clip_guidance_preset: 'FAST_BLUE', 23 | height: 512, 24 | width: 512, 25 | samples: 1, 26 | steps: 50, 27 | text_prompts: [ 28 | { 29 | text: 'A large spiral galaxy with a bright central bulge and a ring of stars around it', 30 | weight: 1, 31 | }, 32 | ], 33 | }) 34 | ) 35 | 36 | const response = await fetch( 37 | `${apiHost}/v1alpha/generation/${engineId}/image-to-image/masking`, 38 | { 39 | method: 'POST', 40 | headers: { 41 | ...form.getHeaders(), 42 | Accept: 'image/png', 43 | Authorization: apiKey, 44 | }, 45 | body: form, 46 | } 47 | ) 48 | 49 | if (!response.ok) { 50 | throw new Error(`Non-200 response: ${await response.text()}`) 51 | } 52 | 53 | try { 54 | const writeStream = fs.createWriteStream(`./out/v1alpha_img2img_masking.png`) 55 | response.body?.pipe(writeStream) 56 | } catch (e) { 57 | console.error(e) 58 | } 59 | -------------------------------------------------------------------------------- /examples/ts/code/v1/image_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-diffusion-v1-5' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. 12 | // Browsers should use their native FormData class. 13 | // React Native apps should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('init_image', fs.readFileSync('../init_image.png')) 16 | formData.append('init_image_mode', 'IMAGE_STRENGTH') 17 | formData.append('image_strength', 0.35) 18 | formData.append('text_prompts[0][text]', 'Galactic dog wearing a cape') 19 | formData.append('cfg_scale', 7) 20 | formData.append('clip_guidance_preset', 'FAST_BLUE') 21 | formData.append('samples', 1) 22 | formData.append('steps', 30) 23 | 24 | const response = await fetch( 25 | `${apiHost}/v1/generation/${engineId}/image-to-image`, 26 | { 27 | method: 'POST', 28 | headers: { 29 | ...formData.getHeaders(), 30 | Accept: 'application/json', 31 | Authorization: `Bearer ${apiKey}`, 32 | }, 33 | body: formData, 34 | } 35 | ) 36 | 37 | if (!response.ok) { 38 | throw new Error(`Non-200 response: ${await response.text()}`) 39 | } 40 | 41 | interface GenerationResponse { 42 | artifacts: Array<{ 43 | base64: string 44 | seed: number 45 | finishReason: string 46 | }> 47 | } 48 | 49 | const responseJSON = (await response.json()) as GenerationResponse 50 | 51 | responseJSON.artifacts.forEach((image, index) => { 52 | fs.writeFileSync( 53 | `out/v1_img2img_${index}.png`, 54 | Buffer.from(image.base64, 'base64') 55 | ) 56 | }) 57 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/image_to_image.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-diffusion-v1-5' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. 12 | // Browsers should use their native FormData class. 13 | // React Native apps should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('init_image', fs.readFileSync('../init_image.png')) 16 | formData.append('init_image_mode', 'IMAGE_STRENGTH') 17 | formData.append('image_strength', 0.35) 18 | formData.append('text_prompts[0][text]', 'Galactic dog wearing a cape') 19 | formData.append('cfg_scale', 7) 20 | formData.append('clip_guidance_preset', 'FAST_BLUE') 21 | formData.append('height', 512) 22 | formData.append('width', 512) 23 | formData.append('samples', 1) 24 | formData.append('steps', 50) 25 | 26 | const response = await fetch( 27 | `${apiHost}/v1beta/generation/${engineId}/image-to-image`, 28 | { 29 | method: 'POST', 30 | headers: { 31 | ...formData.getHeaders(), 32 | Accept: 'application/json', 33 | Authorization: `Bearer ${apiKey}`, 34 | }, 35 | body: formData, 36 | } 37 | ) 38 | 39 | if (!response.ok) { 40 | throw new Error(`Non-200 response: ${await response.text()}`) 41 | } 42 | 43 | interface GenerationResponse { 44 | artifacts: Array<{ 45 | base64: string 46 | seed: number 47 | finishReason: string 48 | }> 49 | } 50 | 51 | const responseJSON = (await response.json()) as GenerationResponse 52 | 53 | responseJSON.artifacts.forEach((image, index) => { 54 | fs.writeFileSync( 55 | `out/v1beta_img2img_${index}.png`, 56 | Buffer.from(image.base64, 'base64') 57 | ) 58 | }) 59 | -------------------------------------------------------------------------------- /examples/ts/code/v1/masking.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-inpainting-512-v2-0' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. Browser 12 | // implementations should use their native FormData class. React Native 13 | // implementations should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('init_image', fs.readFileSync('../init_image.png')) 16 | formData.append('mask_image', fs.readFileSync('../mask_image_white.png')) 17 | formData.append('mask_source', 'MASK_IMAGE_WHITE') 18 | formData.append( 19 | 'text_prompts[0][text]', 20 | 'A large spiral galaxy with a bright central bulge and a ring of stars around it' 21 | ) 22 | formData.append('cfg_scale', '7') 23 | formData.append('clip_guidance_preset', 'FAST_BLUE') 24 | formData.append('samples', 1) 25 | formData.append('steps', 30) 26 | 27 | const response = await fetch( 28 | `${apiHost}/v1/generation/${engineId}/image-to-image/masking`, 29 | { 30 | method: 'POST', 31 | headers: { 32 | ...formData.getHeaders(), 33 | Accept: 'application/json', 34 | Authorization: `Bearer ${apiKey}`, 35 | }, 36 | body: formData, 37 | } 38 | ) 39 | 40 | if (!response.ok) { 41 | throw new Error(`Non-200 response: ${await response.text()}`) 42 | } 43 | 44 | interface GenerationResponse { 45 | artifacts: Array<{ 46 | base64: string 47 | seed: number 48 | finishReason: string 49 | }> 50 | } 51 | 52 | const responseJSON = (await response.json()) as GenerationResponse 53 | 54 | responseJSON.artifacts.forEach((image, index) => { 55 | fs.writeFileSync( 56 | `out/v1_img2img_masking_${index}.png`, 57 | Buffer.from(image.base64, 'base64') 58 | ) 59 | }) 60 | -------------------------------------------------------------------------------- /examples/go/code/v1/upscale_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io" 8 | "mime/multipart" 9 | "net/http" 10 | "os" 11 | ) 12 | 13 | func main() { 14 | engineId := "esrgan-v1-x2plus" 15 | 16 | // Build REST endpoint URL 17 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 18 | if !hasApiHost { 19 | apiHost = "https://api.stability.ai" 20 | } 21 | reqUrl := apiHost + "/v1/generation/" + engineId + "/image-to-image/upscale" 22 | 23 | // Acquire an API key from the environment 24 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 25 | if !hasAPIKey { 26 | panic("Missing STABILITY_API_KEY environment variable") 27 | } 28 | 29 | data := &bytes.Buffer{} 30 | writer := multipart.NewWriter(data) 31 | 32 | // Write the init image to the request 33 | initImageWriter, _ := writer.CreateFormField("image") 34 | initImageFile, initImageErr := os.Open("../init_image.png") 35 | if initImageErr != nil { 36 | panic("Could not open init_image.png") 37 | } 38 | _, _ = io.Copy(initImageWriter, initImageFile) 39 | 40 | // Write the options to the request 41 | _ = writer.WriteField("width", "1024") 42 | writer.Close() 43 | 44 | // Execute the request 45 | payload := bytes.NewReader(data.Bytes()) 46 | req, _ := http.NewRequest("POST", reqUrl, payload) 47 | req.Header.Add("Content-Type", writer.FormDataContentType()) 48 | req.Header.Add("Accept", "image/png") 49 | req.Header.Add("Authorization", "Bearer "+apiKey) 50 | res, _ := http.DefaultClient.Do(req) 51 | defer res.Body.Close() 52 | 53 | if res.StatusCode != 200 { 54 | var body map[string]interface{} 55 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 56 | panic(err) 57 | } 58 | panic(fmt.Sprintf("Non-200 response: %s", body)) 59 | } 60 | 61 | // Write the response to a file 62 | out, err := os.Create("./out/v1_upscaled_image.png") 63 | defer out.Close() 64 | if err != nil { 65 | panic(err) 66 | } 67 | 68 | _, err = io.Copy(out, res.Body) 69 | if err != nil { 70 | panic(err) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /examples/ts/code/v1beta/masking.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import FormData from 'form-data' 3 | import fs from 'node:fs' 4 | 5 | const engineId = 'stable-inpainting-512-v2-0' 6 | const apiHost = process.env.API_HOST ?? 'https://api.stability.ai' 7 | const apiKey = process.env.STABILITY_API_KEY 8 | 9 | if (!apiKey) throw new Error('Missing Stability API key.') 10 | 11 | // NOTE: This example is using a NodeJS FormData library. Browser 12 | // implementations should use their native FormData class. React Native 13 | // implementations should also use their native FormData class. 14 | const formData = new FormData() 15 | formData.append('init_image', fs.readFileSync('../init_image.png')) 16 | formData.append('mask_image', fs.readFileSync('../mask_image_white.png')) 17 | formData.append('mask_source', 'MASK_IMAGE_WHITE') 18 | formData.append( 19 | 'text_prompts[0][text]', 20 | 'A large spiral galaxy with a bright central bulge and a ring of stars around it' 21 | ) 22 | formData.append('cfg_scale', '7') 23 | formData.append('clip_guidance_preset', 'FAST_BLUE') 24 | formData.append('height', 512) 25 | formData.append('width', 512) 26 | formData.append('samples', 1) 27 | formData.append('steps', 50) 28 | 29 | const response = await fetch( 30 | `${apiHost}/v1beta/generation/${engineId}/image-to-image/masking`, 31 | { 32 | method: 'POST', 33 | headers: { 34 | ...formData.getHeaders(), 35 | Accept: 'application/json', 36 | Authorization: `Bearer ${apiKey}`, 37 | }, 38 | body: formData, 39 | } 40 | ) 41 | 42 | if (!response.ok) { 43 | throw new Error(`Non-200 response: ${await response.text()}`) 44 | } 45 | 46 | interface GenerationResponse { 47 | artifacts: Array<{ 48 | base64: string 49 | seed: number 50 | finishReason: string 51 | }> 52 | } 53 | 54 | const responseJSON = (await response.json()) as GenerationResponse 55 | 56 | responseJSON.artifacts.forEach((image, index) => { 57 | fs.writeFileSync( 58 | `out/v1beta_img2img_masking_${index}.png`, 59 | Buffer.from(image.base64, 'base64') 60 | ) 61 | }) 62 | -------------------------------------------------------------------------------- /.github/workflows/validate-spec.yml: -------------------------------------------------------------------------------- 1 | name: Validate API Spec 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | validate: 9 | name: Main 10 | runs-on: ubuntu-latest 11 | steps: 12 | # By default, when you use actions/checkout on a PR, it will checkout the 13 | # head commit in a detached head state. If you want to make some changes, 14 | # you have to checkout the branch the PR is coming from in the head repo. 15 | # 16 | # https://github.com/EndBug/add-and-commit#working-with-prs 17 | - uses: actions/checkout@v3 18 | with: 19 | repository: ${{ github.event.pull_request.head.repo.full_name }} 20 | ref: ${{ github.event.pull_request.head.ref }} 21 | if: github.event_name == 'pull_request' 22 | - uses: actions/checkout@v3 23 | if: github.event_name != 'pull_request' 24 | 25 | # Setup environment 26 | - uses: actions/setup-node@v3 27 | with: 28 | node-version: 16 29 | cache: 'yarn' 30 | - name: yarn install 31 | run: | 32 | yarn install --frozen-lockfile 33 | 34 | # Rebuild generated files and commit changes (if any) 35 | - name: yarn generate 36 | run: | 37 | yarn generate 38 | - name: Commit changes (if any) 39 | uses: EndBug/add-and-commit@v9 40 | with: 41 | add: 'generated/' 42 | message: 'chore: update generated files' 43 | committer_name: GitHub Actions 44 | committer_email: actions@github.com 45 | 46 | # Lint everything 47 | - name: yarn lint 48 | run: | 49 | yarn lint 50 | 51 | # Checking for breaking changes 52 | - name: Checkout base branch 53 | uses: actions/checkout@v2 54 | with: 55 | path: _base 56 | ref: main 57 | - name: Check v1beta for breaking changes 58 | uses: mvegter/openapi-diff-action@v0.23.5 59 | with: 60 | head-spec: generated/spec/v1beta.json 61 | base-spec: _base/generated/spec/v1beta.json 62 | - name: Check v1 for breaking changes 63 | uses: mvegter/openapi-diff-action@v0.23.5 64 | with: 65 | head-spec: generated/spec/v1.json 66 | base-spec: _base/generated/spec/v1.json 67 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/image_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "mime/multipart" 7 | "net/http" 8 | "os" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | engineId := "stable-diffusion-v1-5" 14 | 15 | // Build REST endpoint URL 16 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 17 | if !hasApiHost { 18 | apiHost = "https://api.stability.ai" 19 | } 20 | reqUrl := apiHost + "/v1alpha/generation/" + engineId + "/image-to-image" 21 | 22 | // Acquire an API key from the environment 23 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 24 | if !hasAPIKey { 25 | panic("Missing STABILITY_API_KEY environment variable") 26 | } 27 | 28 | data := &bytes.Buffer{} 29 | writer := multipart.NewWriter(data) 30 | 31 | // Write the init image to the request 32 | initImageWriter, _ := writer.CreateFormField("init_image") 33 | initImageFile, initImageErr := os.Open("../init_image.png") 34 | if initImageErr != nil { 35 | panic("Could not open init_image.png") 36 | } 37 | _, _ = io.Copy(initImageWriter, initImageFile) 38 | 39 | // Write the options to the request 40 | optionsFw, _ := writer.CreateFormField("options") 41 | _, _ = io.Copy(optionsFw, strings.NewReader(`{ 42 | "cfg_scale": 7, 43 | "clip_guidance_preset": "FAST_BLUE", 44 | "step_schedule_start": 0.6, 45 | "step_schedule_end": 0.01, 46 | "height": 512, 47 | "width": 512, 48 | "samples": 1, 49 | "steps": 50, 50 | "text_prompts": [{ 51 | "text": "A large spiral galaxy dog with a bright central bulge and a ring of stars around it", 52 | "weight": 1 53 | }] 54 | }`)) 55 | writer.Close() 56 | 57 | // Execute the request 58 | payload := bytes.NewReader(data.Bytes()) 59 | req, _ := http.NewRequest("POST", reqUrl, payload) 60 | req.Header.Add("Content-Type", writer.FormDataContentType()) 61 | req.Header.Add("Accept", "image/png") 62 | req.Header.Add("Authorization", apiKey) 63 | res, _ := http.DefaultClient.Do(req) 64 | defer res.Body.Close() 65 | body, _ := io.ReadAll(res.Body) 66 | 67 | if res.StatusCode != 200 { 68 | panic("Non-200 response: " + string(body)) 69 | } 70 | 71 | // Write the bytes to a file 72 | file, _ := os.Create("./out/v1alpha_img2img.png") 73 | defer file.Close() 74 | _, err := file.Write(body) 75 | if err != nil { 76 | panic(err) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /examples/go/code/v1/text_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "net/http" 9 | "os" 10 | ) 11 | 12 | type TextToImageImage struct { 13 | Base64 string `json:"base64"` 14 | Seed uint32 `json:"seed"` 15 | FinishReason string `json:"finishReason"` 16 | } 17 | 18 | type TextToImageResponse struct { 19 | Images []TextToImageImage `json:"artifacts"` 20 | } 21 | 22 | func main() { 23 | // Build REST endpoint URL w/ specified engine 24 | engineId := "stable-diffusion-v1-5" 25 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 26 | if !hasApiHost { 27 | apiHost = "https://api.stability.ai" 28 | } 29 | reqUrl := apiHost + "/v1/generation/" + engineId + "/text-to-image" 30 | 31 | // Acquire an API key from the environment 32 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 33 | if !hasAPIKey { 34 | panic("Missing STABILITY_API_KEY environment variable") 35 | } 36 | 37 | var data = []byte(`{ 38 | "text_prompts": [ 39 | { 40 | "text": "A lighthouse on a cliff" 41 | } 42 | ], 43 | "cfg_scale": 7, 44 | "clip_guidance_preset": "FAST_BLUE", 45 | "height": 512, 46 | "width": 512, 47 | "samples": 1, 48 | "steps": 30 49 | }`) 50 | 51 | req, _ := http.NewRequest("POST", reqUrl, bytes.NewBuffer(data)) 52 | req.Header.Add("Content-Type", "application/json") 53 | req.Header.Add("Accept", "application/json") 54 | req.Header.Add("Authorization", "Bearer "+apiKey) 55 | 56 | // Execute the request & read all the bytes of the body 57 | res, _ := http.DefaultClient.Do(req) 58 | defer res.Body.Close() 59 | 60 | if res.StatusCode != 200 { 61 | var body map[string]interface{} 62 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 63 | panic(err) 64 | } 65 | panic(fmt.Sprintf("Non-200 response: %s", body)) 66 | } 67 | 68 | // Decode the JSON body 69 | var body TextToImageResponse 70 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 71 | panic(err) 72 | } 73 | 74 | // Write the images to disk 75 | for i, image := range body.Images { 76 | outFile := fmt.Sprintf("./out/v1_txt2img_%d.png", i) 77 | file, err := os.Create(outFile) 78 | if err != nil { 79 | panic(err) 80 | } 81 | 82 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 83 | if err != nil { 84 | panic(err) 85 | } 86 | 87 | if _, err := file.Write(imageBytes); err != nil { 88 | panic(err) 89 | } 90 | 91 | if err := file.Close(); err != nil { 92 | panic(err) 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/text_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "net/http" 9 | "os" 10 | ) 11 | 12 | type TextToImageImage struct { 13 | Base64 string `json:"base64"` 14 | Seed uint32 `json:"seed"` 15 | FinishReason string `json:"finishReason"` 16 | } 17 | 18 | type TextToImageResponse struct { 19 | Images []TextToImageImage `json:"artifacts"` 20 | } 21 | 22 | func main() { 23 | // Build REST endpoint URL w/ specified engine 24 | engineId := "stable-diffusion-v1-5" 25 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 26 | if !hasApiHost { 27 | apiHost = "https://api.stability.ai" 28 | } 29 | reqUrl := apiHost + "/v1beta/generation/" + engineId + "/text-to-image" 30 | 31 | // Acquire an API key from the environment 32 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 33 | if !hasAPIKey { 34 | panic("Missing STABILITY_API_KEY environment variable") 35 | } 36 | 37 | var data = []byte(`{ 38 | "text_prompts": [ 39 | { 40 | "text": "A lighthouse on a cliff" 41 | } 42 | ], 43 | "cfg_scale": 7, 44 | "clip_guidance_preset": "FAST_BLUE", 45 | "height": 512, 46 | "width": 512, 47 | "samples": 1, 48 | "steps": 50 49 | }`) 50 | 51 | req, _ := http.NewRequest("POST", reqUrl, bytes.NewBuffer(data)) 52 | req.Header.Add("Content-Type", "application/json") 53 | req.Header.Add("Accept", "application/json") 54 | req.Header.Add("Authorization", "Bearer "+apiKey) 55 | 56 | // Execute the request & read all the bytes of the body 57 | res, _ := http.DefaultClient.Do(req) 58 | defer res.Body.Close() 59 | 60 | if res.StatusCode != 200 { 61 | var body map[string]interface{} 62 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 63 | panic(err) 64 | } 65 | panic(fmt.Sprintf("Non-200 response: %s", body)) 66 | } 67 | 68 | // Decode the JSON body 69 | var body TextToImageResponse 70 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 71 | panic(err) 72 | } 73 | 74 | // Write the images to disk 75 | for i, image := range body.Images { 76 | outFile := fmt.Sprintf("./out/v1beta_txt2img_%d.png", i) 77 | file, err := os.Create(outFile) 78 | if err != nil { 79 | panic(err) 80 | } 81 | 82 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 83 | if err != nil { 84 | panic(err) 85 | } 86 | 87 | if _, err := file.Write(imageBytes); err != nil { 88 | panic(err) 89 | } 90 | 91 | if err := file.Close(); err != nil { 92 | panic(err) 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /examples/go/code/v1alpha/masking.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "mime/multipart" 7 | "net/http" 8 | "os" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | engineId := "stable-inpainting-512-v2-0" 14 | 15 | // Build REST endpoint URL 16 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 17 | if !hasApiHost { 18 | apiHost = "https://api.stability.ai" 19 | } 20 | reqUrl := apiHost + "/v1alpha/generation/" + engineId + "/image-to-image/masking" 21 | 22 | // Acquire an API key from the environment 23 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 24 | if !hasAPIKey { 25 | panic("Missing STABILITY_API_KEY environment variable") 26 | } 27 | 28 | data := &bytes.Buffer{} 29 | writer := multipart.NewWriter(data) 30 | 31 | // Write the init image to the request 32 | initImageWriter, _ := writer.CreateFormField("init_image") 33 | initImageFile, initImageErr := os.Open("../init_image.png") 34 | if initImageErr != nil { 35 | panic("Could not open init_image.png") 36 | } 37 | _, _ = io.Copy(initImageWriter, initImageFile) 38 | 39 | // Write the mask image to the request 40 | maskImageWriter, _ := writer.CreateFormField("mask_image") 41 | maskImageFile, maskImageErr := os.Open("../mask_image_white.png") 42 | if maskImageErr != nil { 43 | panic("Could not open mask_image_white.png") 44 | } 45 | _, _ = io.Copy(maskImageWriter, maskImageFile) 46 | 47 | // Write the options to the request 48 | optionsFw, _ := writer.CreateFormField("options") 49 | _, _ = io.Copy(optionsFw, strings.NewReader(`{ 50 | "mask_source": "MASK_IMAGE_WHITE", 51 | "cfg_scale": 7, 52 | "clip_guidance_preset": "FAST_BLUE", 53 | "height": 512, 54 | "width": 512, 55 | "samples": 1, 56 | "steps": 50, 57 | "text_prompts": [{ 58 | "text": "A large spiral galaxy dog with a bright central bulge and a ring of stars around it", 59 | "weight": 1 60 | }] 61 | }`)) 62 | writer.Close() 63 | 64 | // Execute the request & read all the bytes of the response 65 | payload := bytes.NewReader(data.Bytes()) 66 | req, _ := http.NewRequest("POST", reqUrl, payload) 67 | req.Header.Add("Content-Type", writer.FormDataContentType()) 68 | req.Header.Add("Accept", "image/png") 69 | req.Header.Add("Authorization", apiKey) 70 | res, _ := http.DefaultClient.Do(req) 71 | defer res.Body.Close() 72 | body, _ := io.ReadAll(res.Body) 73 | 74 | if res.StatusCode != 200 { 75 | panic("Non-200 response: " + string(body)) 76 | } 77 | 78 | // Write the bytes to a file 79 | file, _ := os.Create("./out/v1alpha_img2img_masking.png") 80 | defer file.Close() 81 | _, err := file.Write(body) 82 | if err != nil { 83 | panic(err) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /examples/go/code/v1/image_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "mime/multipart" 10 | "net/http" 11 | "os" 12 | ) 13 | 14 | type ImageToImageImage struct { 15 | Base64 string `json:"base64"` 16 | Seed uint32 `json:"seed"` 17 | FinishReason string `json:"finishReason"` 18 | } 19 | 20 | type ImageToImageResponse struct { 21 | Images []ImageToImageImage `json:"artifacts"` 22 | } 23 | 24 | func main() { 25 | engineId := "stable-diffusion-v1-5" 26 | 27 | // Build REST endpoint URL 28 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 29 | if !hasApiHost { 30 | apiHost = "https://api.stability.ai" 31 | } 32 | reqUrl := apiHost + "/v1/generation/" + engineId + "/image-to-image" 33 | 34 | // Acquire an API key from the environment 35 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 36 | if !hasAPIKey { 37 | panic("Missing STABILITY_API_KEY environment variable") 38 | } 39 | 40 | data := &bytes.Buffer{} 41 | writer := multipart.NewWriter(data) 42 | 43 | // Write the init image to the request 44 | initImageWriter, _ := writer.CreateFormField("init_image") 45 | initImageFile, initImageErr := os.Open("../init_image.png") 46 | if initImageErr != nil { 47 | panic("Could not open init_image.png") 48 | } 49 | _, _ = io.Copy(initImageWriter, initImageFile) 50 | 51 | // Write the options to the request 52 | _ = writer.WriteField("init_image_mode", "IMAGE_STRENGTH") 53 | _ = writer.WriteField("image_strength", "0.35") 54 | _ = writer.WriteField("text_prompts[0][text]", "Galactic dog with a cape") 55 | _ = writer.WriteField("cfg_scale", "7") 56 | _ = writer.WriteField("clip_guidance_preset", "FAST_BLUE") 57 | _ = writer.WriteField("samples", "1") 58 | _ = writer.WriteField("steps", "30") 59 | writer.Close() 60 | 61 | // Execute the request 62 | payload := bytes.NewReader(data.Bytes()) 63 | req, _ := http.NewRequest("POST", reqUrl, payload) 64 | req.Header.Add("Content-Type", writer.FormDataContentType()) 65 | req.Header.Add("Accept", "application/json") 66 | req.Header.Add("Authorization", "Bearer "+apiKey) 67 | res, _ := http.DefaultClient.Do(req) 68 | defer res.Body.Close() 69 | 70 | if res.StatusCode != 200 { 71 | var body map[string]interface{} 72 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 73 | panic(err) 74 | } 75 | panic(fmt.Sprintf("Non-200 response: %s", body)) 76 | } 77 | 78 | // Decode the JSON body 79 | var body ImageToImageResponse 80 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 81 | panic(err) 82 | } 83 | 84 | // Write the images to disk 85 | for i, image := range body.Images { 86 | outFile := fmt.Sprintf("./out/v1_img2img_%d.png", i) 87 | file, err := os.Create(outFile) 88 | if err != nil { 89 | panic(err) 90 | } 91 | 92 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 93 | if err != nil { 94 | panic(err) 95 | } 96 | 97 | if _, err := file.Write(imageBytes); err != nil { 98 | panic(err) 99 | } 100 | 101 | if err := file.Close(); err != nil { 102 | panic(err) 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/image_to_image.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "mime/multipart" 10 | "net/http" 11 | "os" 12 | ) 13 | 14 | type ImageToImageImage struct { 15 | Base64 string `json:"base64"` 16 | Seed uint32 `json:"seed"` 17 | FinishReason string `json:"finishReason"` 18 | } 19 | 20 | type ImageToImageResponse struct { 21 | Images []ImageToImageImage `json:"artifacts"` 22 | } 23 | 24 | func main() { 25 | engineId := "stable-diffusion-v1-5" 26 | 27 | // Build REST endpoint URL 28 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 29 | if !hasApiHost { 30 | apiHost = "https://api.stability.ai" 31 | } 32 | reqUrl := apiHost + "/v1beta/generation/" + engineId + "/image-to-image" 33 | 34 | // Acquire an API key from the environment 35 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 36 | if !hasAPIKey { 37 | panic("Missing STABILITY_API_KEY environment variable") 38 | } 39 | 40 | data := &bytes.Buffer{} 41 | writer := multipart.NewWriter(data) 42 | 43 | // Write the init image to the request 44 | initImageWriter, _ := writer.CreateFormField("init_image") 45 | initImageFile, initImageErr := os.Open("../init_image.png") 46 | if initImageErr != nil { 47 | panic("Could not open init_image.png") 48 | } 49 | _, _ = io.Copy(initImageWriter, initImageFile) 50 | 51 | // Write the options to the request 52 | _ = writer.WriteField("init_image_mode", "IMAGE_STRENGTH") 53 | _ = writer.WriteField("image_strength", "0.35") 54 | _ = writer.WriteField("text_prompts[0][text]", "Galactic dog with a cape") 55 | _ = writer.WriteField("cfg_scale", "7") 56 | _ = writer.WriteField("clip_guidance_preset", "FAST_BLUE") 57 | _ = writer.WriteField("height", "512") 58 | _ = writer.WriteField("width", "512") 59 | _ = writer.WriteField("samples", "1") 60 | _ = writer.WriteField("steps", "50") 61 | writer.Close() 62 | 63 | // Execute the request 64 | payload := bytes.NewReader(data.Bytes()) 65 | req, _ := http.NewRequest("POST", reqUrl, payload) 66 | req.Header.Add("Content-Type", writer.FormDataContentType()) 67 | req.Header.Add("Accept", "application/json") 68 | req.Header.Add("Authorization", "Bearer "+apiKey) 69 | res, _ := http.DefaultClient.Do(req) 70 | defer res.Body.Close() 71 | 72 | if res.StatusCode != 200 { 73 | var body map[string]interface{} 74 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 75 | panic(err) 76 | } 77 | panic(fmt.Sprintf("Non-200 response: %s", body)) 78 | } 79 | 80 | // Decode the JSON body 81 | var body ImageToImageResponse 82 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 83 | panic(err) 84 | } 85 | 86 | // Write the images to disk 87 | for i, image := range body.Images { 88 | outFile := fmt.Sprintf("./out/v1beta_img2img_%d.png", i) 89 | file, err := os.Create(outFile) 90 | if err != nil { 91 | panic(err) 92 | } 93 | 94 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 95 | if err != nil { 96 | panic(err) 97 | } 98 | 99 | if _, err := file.Write(imageBytes); err != nil { 100 | panic(err) 101 | } 102 | 103 | if err := file.Close(); err != nil { 104 | panic(err) 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/python/poetry.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Poetry and should not be changed by hand. 2 | 3 | [[package]] 4 | name = "certifi" 5 | version = "2022.12.7" 6 | description = "Python package for providing Mozilla's CA Bundle." 7 | category = "main" 8 | optional = false 9 | python-versions = ">=3.6" 10 | files = [ 11 | {file = "certifi-2022.12.7-py3-none-any.whl", hash = "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"}, 12 | {file = "certifi-2022.12.7.tar.gz", hash = "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3"}, 13 | ] 14 | 15 | [[package]] 16 | name = "charset-normalizer" 17 | version = "2.1.1" 18 | description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." 19 | category = "main" 20 | optional = false 21 | python-versions = ">=3.6.0" 22 | files = [ 23 | {file = "charset-normalizer-2.1.1.tar.gz", hash = "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845"}, 24 | {file = "charset_normalizer-2.1.1-py3-none-any.whl", hash = "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"}, 25 | ] 26 | 27 | [package.extras] 28 | unicode-backport = ["unicodedata2"] 29 | 30 | [[package]] 31 | name = "idna" 32 | version = "3.4" 33 | description = "Internationalized Domain Names in Applications (IDNA)" 34 | category = "main" 35 | optional = false 36 | python-versions = ">=3.5" 37 | files = [ 38 | {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"}, 39 | {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, 40 | ] 41 | 42 | [[package]] 43 | name = "requests" 44 | version = "2.28.1" 45 | description = "Python HTTP for Humans." 46 | category = "main" 47 | optional = false 48 | python-versions = ">=3.7, <4" 49 | files = [ 50 | {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, 51 | {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, 52 | ] 53 | 54 | [package.dependencies] 55 | certifi = ">=2017.4.17" 56 | charset-normalizer = ">=2,<3" 57 | idna = ">=2.5,<4" 58 | urllib3 = ">=1.21.1,<1.27" 59 | 60 | [package.extras] 61 | socks = ["PySocks (>=1.5.6,!=1.5.7)"] 62 | use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] 63 | 64 | [[package]] 65 | name = "urllib3" 66 | version = "1.26.13" 67 | description = "HTTP library with thread-safe connection pooling, file post, and more." 68 | category = "main" 69 | optional = false 70 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" 71 | files = [ 72 | {file = "urllib3-1.26.13-py2.py3-none-any.whl", hash = "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc"}, 73 | {file = "urllib3-1.26.13.tar.gz", hash = "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"}, 74 | ] 75 | 76 | [package.extras] 77 | brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] 78 | secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] 79 | socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] 80 | 81 | [metadata] 82 | lock-version = "2.0" 83 | python-versions = "^3.7" 84 | content-hash = "258402ead0622eb7a8fb2f46b5bfbe5da2d95c35e558ac7a92f97a8a696f4520" 85 | -------------------------------------------------------------------------------- /examples/go/code/v1/masking.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "mime/multipart" 10 | "net/http" 11 | "os" 12 | ) 13 | 14 | type MaskingImage struct { 15 | Base64 string `json:"base64"` 16 | Seed uint32 `json:"seed"` 17 | FinishReason string `json:"finishReason"` 18 | } 19 | 20 | type MaskingResponse struct { 21 | Images []MaskingImage `json:"artifacts"` 22 | } 23 | 24 | func main() { 25 | engineId := "stable-inpainting-512-v2-0" 26 | 27 | // Build REST endpoint URL 28 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 29 | if !hasApiHost { 30 | apiHost = "https://api.stability.ai" 31 | } 32 | reqUrl := apiHost + "/v1/generation/" + engineId + "/image-to-image/masking" 33 | 34 | // Acquire an API key from the environment 35 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 36 | if !hasAPIKey { 37 | panic("Missing STABILITY_API_KEY environment variable") 38 | } 39 | 40 | data := &bytes.Buffer{} 41 | writer := multipart.NewWriter(data) 42 | 43 | // Write the init image to the request 44 | initImageWriter, _ := writer.CreateFormField("init_image") 45 | initImageFile, initImageErr := os.Open("../init_image.png") 46 | if initImageErr != nil { 47 | panic("Could not open init_image.png") 48 | } 49 | _, _ = io.Copy(initImageWriter, initImageFile) 50 | 51 | // Write the mask image to the request 52 | maskImageWriter, _ := writer.CreateFormField("mask_image") 53 | maskImageFile, maskImageErr := os.Open("../mask_image_white.png") 54 | if maskImageErr != nil { 55 | panic("Could not open mask_image_white.png") 56 | } 57 | _, _ = io.Copy(maskImageWriter, maskImageFile) 58 | 59 | // Write the options to the request 60 | _ = writer.WriteField("mask_source", "MASK_IMAGE_WHITE") 61 | _ = writer.WriteField("text_prompts[0][text]", "A large spiral galaxy with a bright central bulge and a ring of stars around it") 62 | _ = writer.WriteField("cfg_scale", "7") 63 | _ = writer.WriteField("clip_guidance_preset", "FAST_BLUE") 64 | _ = writer.WriteField("samples", "1") 65 | _ = writer.WriteField("steps", "30") 66 | writer.Close() 67 | 68 | // Execute the request & read all the bytes of the response 69 | payload := bytes.NewReader(data.Bytes()) 70 | req, _ := http.NewRequest("POST", reqUrl, payload) 71 | req.Header.Add("Content-Type", writer.FormDataContentType()) 72 | req.Header.Add("Accept", "application/json") 73 | req.Header.Add("Authorization", "Bearer "+apiKey) 74 | res, _ := http.DefaultClient.Do(req) 75 | defer res.Body.Close() 76 | 77 | if res.StatusCode != 200 { 78 | var body map[string]interface{} 79 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 80 | panic(err) 81 | } 82 | panic(fmt.Sprintf("Non-200 response: %s", body)) 83 | } 84 | 85 | // Decode the JSON body 86 | var body MaskingResponse 87 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 88 | panic(err) 89 | } 90 | 91 | // Write the images to disk 92 | for i, image := range body.Images { 93 | outFile := fmt.Sprintf("./out/v1_img2img_masking_%d.png", i) 94 | file, err := os.Create(outFile) 95 | if err != nil { 96 | panic(err) 97 | } 98 | 99 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 100 | if err != nil { 101 | panic(err) 102 | } 103 | 104 | if _, err := file.Write(imageBytes); err != nil { 105 | panic(err) 106 | } 107 | 108 | if err := file.Close(); err != nil { 109 | panic(err) 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /examples/go/code/v1beta/masking.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "mime/multipart" 10 | "net/http" 11 | "os" 12 | ) 13 | 14 | type MaskingImage struct { 15 | Base64 string `json:"base64"` 16 | Seed uint32 `json:"seed"` 17 | FinishReason string `json:"finishReason"` 18 | } 19 | 20 | type MaskingResponse struct { 21 | Images []MaskingImage `json:"artifacts"` 22 | } 23 | 24 | func main() { 25 | engineId := "stable-inpainting-512-v2-0" 26 | 27 | // Build REST endpoint URL 28 | apiHost, hasApiHost := os.LookupEnv("API_HOST") 29 | if !hasApiHost { 30 | apiHost = "https://api.stability.ai" 31 | } 32 | reqUrl := apiHost + "/v1beta/generation/" + engineId + "/image-to-image/masking" 33 | 34 | // Acquire an API key from the environment 35 | apiKey, hasAPIKey := os.LookupEnv("STABILITY_API_KEY") 36 | if !hasAPIKey { 37 | panic("Missing STABILITY_API_KEY environment variable") 38 | } 39 | 40 | data := &bytes.Buffer{} 41 | writer := multipart.NewWriter(data) 42 | 43 | // Write the init image to the request 44 | initImageWriter, _ := writer.CreateFormField("init_image") 45 | initImageFile, initImageErr := os.Open("../init_image.png") 46 | if initImageErr != nil { 47 | panic("Could not open init_image.png") 48 | } 49 | _, _ = io.Copy(initImageWriter, initImageFile) 50 | 51 | // Write the mask image to the request 52 | maskImageWriter, _ := writer.CreateFormField("mask_image") 53 | maskImageFile, maskImageErr := os.Open("../mask_image_white.png") 54 | if maskImageErr != nil { 55 | panic("Could not open mask_image_white.png") 56 | } 57 | _, _ = io.Copy(maskImageWriter, maskImageFile) 58 | 59 | // Write the options to the request 60 | _ = writer.WriteField("mask_source", "MASK_IMAGE_WHITE") 61 | _ = writer.WriteField("text_prompts[0][text]", "A large spiral galaxy with a bright central bulge and a ring of stars around it") 62 | _ = writer.WriteField("cfg_scale", "7") 63 | _ = writer.WriteField("clip_guidance_preset", "FAST_BLUE") 64 | _ = writer.WriteField("height", "512") 65 | _ = writer.WriteField("width", "512") 66 | _ = writer.WriteField("samples", "1") 67 | _ = writer.WriteField("steps", "50") 68 | writer.Close() 69 | 70 | // Execute the request & read all the bytes of the response 71 | payload := bytes.NewReader(data.Bytes()) 72 | req, _ := http.NewRequest("POST", reqUrl, payload) 73 | req.Header.Add("Content-Type", writer.FormDataContentType()) 74 | req.Header.Add("Accept", "application/json") 75 | req.Header.Add("Authorization", "Bearer "+apiKey) 76 | res, _ := http.DefaultClient.Do(req) 77 | defer res.Body.Close() 78 | 79 | if res.StatusCode != 200 { 80 | var body map[string]interface{} 81 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 82 | panic(err) 83 | } 84 | panic(fmt.Sprintf("Non-200 response: %s", body)) 85 | } 86 | 87 | // Decode the JSON body 88 | var body MaskingResponse 89 | if err := json.NewDecoder(res.Body).Decode(&body); err != nil { 90 | panic(err) 91 | } 92 | 93 | // Write the images to disk 94 | for i, image := range body.Images { 95 | outFile := fmt.Sprintf("./out/v1beta_img2img_masking_%d.png", i) 96 | file, err := os.Create(outFile) 97 | if err != nil { 98 | panic(err) 99 | } 100 | 101 | imageBytes, err := base64.StdEncoding.DecodeString(image.Base64) 102 | if err != nil { 103 | panic(err) 104 | } 105 | 106 | if _, err := file.Write(imageBytes); err != nil { 107 | panic(err) 108 | } 109 | 110 | if err := file.Close(); err != nil { 111 | panic(err) 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /examples/ts/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@esbuild-kit/cjs-loader@^2.4.0": 6 | version "2.4.1" 7 | resolved "https://registry.yarnpkg.com/@esbuild-kit/cjs-loader/-/cjs-loader-2.4.1.tgz#5c1183ac3906223f0da3bb4ff5b74d0f0b13c326" 8 | integrity sha512-lhc/XLith28QdW0HpHZvZKkorWgmCNT7sVelMHDj3HFdTfdqkwEKvT+aXVQtNAmCC39VJhunDkWhONWB7335mg== 9 | dependencies: 10 | "@esbuild-kit/core-utils" "^3.0.0" 11 | get-tsconfig "^4.2.0" 12 | 13 | "@esbuild-kit/core-utils@^3.0.0": 14 | version "3.0.0" 15 | resolved "https://registry.yarnpkg.com/@esbuild-kit/core-utils/-/core-utils-3.0.0.tgz#e0f8463a32b4a9c9b456a7f9c31a5e038c8d2c19" 16 | integrity sha512-TXmwH9EFS3DC2sI2YJWJBgHGhlteK0Xyu1VabwetMULfm3oYhbrsWV5yaSr2NTWZIgDGVLHbRf0inxbjXqAcmQ== 17 | dependencies: 18 | esbuild "~0.15.10" 19 | source-map-support "^0.5.21" 20 | 21 | "@esbuild-kit/esm-loader@^2.5.0": 22 | version "2.5.0" 23 | resolved "https://registry.yarnpkg.com/@esbuild-kit/esm-loader/-/esm-loader-2.5.0.tgz#af208eb9e0449038e7f35957ec51b7e70135e116" 24 | integrity sha512-ySs0qOsiwj+hsgZM9/MniGdvfa9/WzqfFuIia8/5gSUPeIQIX2/tG91QakxPFOR35VFiwTB7wCiHtiS6dc6SkA== 25 | dependencies: 26 | "@esbuild-kit/core-utils" "^3.0.0" 27 | get-tsconfig "^4.2.0" 28 | 29 | "@esbuild/android-arm@0.15.15": 30 | version "0.15.15" 31 | resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.15.15.tgz#35b3cc0f9e69cb53932d44f60b99dd440335d2f0" 32 | integrity sha512-JJjZjJi2eBL01QJuWjfCdZxcIgot+VoK6Fq7eKF9w4YHm9hwl7nhBR1o2Wnt/WcANk5l9SkpvrldW1PLuXxcbw== 33 | 34 | "@esbuild/linux-loong64@0.15.15": 35 | version "0.15.15" 36 | resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.15.15.tgz#32c65517a09320b62530867345222fde7794fbe1" 37 | integrity sha512-lhz6UNPMDXUhtXSulw8XlFAtSYO26WmHQnCi2Lg2p+/TMiJKNLtZCYUxV4wG6rZMzXmr8InGpNwk+DLT2Hm0PA== 38 | 39 | "@types/node@^18.11.9": 40 | version "18.11.9" 41 | resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4" 42 | integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg== 43 | 44 | asynckit@^0.4.0: 45 | version "0.4.0" 46 | resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" 47 | integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== 48 | 49 | buffer-from@^1.0.0: 50 | version "1.1.2" 51 | resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" 52 | integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== 53 | 54 | combined-stream@^1.0.8: 55 | version "1.0.8" 56 | resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" 57 | integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== 58 | dependencies: 59 | delayed-stream "~1.0.0" 60 | 61 | data-uri-to-buffer@^4.0.0: 62 | version "4.0.0" 63 | resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b" 64 | integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA== 65 | 66 | delayed-stream@~1.0.0: 67 | version "1.0.0" 68 | resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" 69 | integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== 70 | 71 | esbuild-android-64@0.15.15: 72 | version "0.15.15" 73 | resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.15.15.tgz#fd959b034dd761d14e13dda6214b6948841ff4ff" 74 | integrity sha512-F+WjjQxO+JQOva3tJWNdVjouFMLK6R6i5gjDvgUthLYJnIZJsp1HlF523k73hELY20WPyEO8xcz7aaYBVkeg5Q== 75 | 76 | esbuild-android-arm64@0.15.15: 77 | version "0.15.15" 78 | resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.15.15.tgz#9733b71cf0229b4356f106a455b2cfdf7884aa59" 79 | integrity sha512-attlyhD6Y22jNyQ0fIIQ7mnPvDWKw7k6FKnsXlBvQE6s3z6s6cuEHcSgoirquQc7TmZgVCK5fD/2uxmRN+ZpcQ== 80 | 81 | esbuild-darwin-64@0.15.15: 82 | version "0.15.15" 83 | resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.15.15.tgz#fc3482fdf5e798dbc0b8b2fe13287d257a45efc6" 84 | integrity sha512-ohZtF8W1SHJ4JWldsPVdk8st0r9ExbAOSrBOh5L+Mq47i696GVwv1ab/KlmbUoikSTNoXEhDzVpxUR/WIO19FQ== 85 | 86 | esbuild-darwin-arm64@0.15.15: 87 | version "0.15.15" 88 | resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.15.tgz#e922ec387c00fa84d664e14b5722fe13613f4adc" 89 | integrity sha512-P8jOZ5zshCNIuGn+9KehKs/cq5uIniC+BeCykvdVhx/rBXSxmtj3CUIKZz4sDCuESMbitK54drf/2QX9QHG5Ag== 90 | 91 | esbuild-freebsd-64@0.15.15: 92 | version "0.15.15" 93 | resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.15.tgz#69a42d79137d7d3ea718414c432bc10e8bb97c68" 94 | integrity sha512-KkTg+AmDXz1IvA9S1gt8dE24C8Thx0X5oM0KGF322DuP+P3evwTL9YyusHAWNsh4qLsR80nvBr/EIYs29VSwuA== 95 | 96 | esbuild-freebsd-arm64@0.15.15: 97 | version "0.15.15" 98 | resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.15.tgz#63b6d0dd492f7394f8d07a0e2b931151eb9d60c4" 99 | integrity sha512-FUcML0DRsuyqCMfAC+HoeAqvWxMeq0qXvclZZ/lt2kLU6XBnDA5uKTLUd379WYEyVD4KKFctqWd9tTuk8C/96g== 100 | 101 | esbuild-linux-32@0.15.15: 102 | version "0.15.15" 103 | resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.15.15.tgz#7f295795fd7e61ea57d1135f717424a6771a7472" 104 | integrity sha512-q28Qn5pZgHNqug02aTkzw5sW9OklSo96b5nm17Mq0pDXrdTBcQ+M6Q9A1B+dalFeynunwh/pvfrNucjzwDXj+Q== 105 | 106 | esbuild-linux-64@0.15.15: 107 | version "0.15.15" 108 | resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.15.15.tgz#11a430a86403b0411ca0a355b891f1cb8c4c4ec6" 109 | integrity sha512-217KPmWMirkf8liO+fj2qrPwbIbhNTGNVtvqI1TnOWJgcMjUWvd677Gq3fTzXEjilkx2yWypVnTswM2KbXgoAg== 110 | 111 | esbuild-linux-arm64@0.15.15: 112 | version "0.15.15" 113 | resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.15.tgz#b65f9a2c60e8e5b62f6cfd392cd0410f22e8c390" 114 | integrity sha512-/ltmNFs0FivZkYsTzAsXIfLQX38lFnwJTWCJts0IbCqWZQe+jjj0vYBNbI0kmXLb3y5NljiM5USVAO1NVkdh2g== 115 | 116 | esbuild-linux-arm@0.15.15: 117 | version "0.15.15" 118 | resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.15.15.tgz#c8e13e45a0a6f0cb145ce13ae26ce1d2551d9bcc" 119 | integrity sha512-RYVW9o2yN8yM7SB1yaWr378CwrjvGCyGybX3SdzPHpikUHkME2AP55Ma20uNwkNyY2eSYFX9D55kDrfQmQBR4w== 120 | 121 | esbuild-linux-mips64le@0.15.15: 122 | version "0.15.15" 123 | resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.15.tgz#d4c24d47e43966fcac748c90621be7edd53456c0" 124 | integrity sha512-PksEPb321/28GFFxtvL33yVPfnMZihxkEv5zME2zapXGp7fA1X2jYeiTUK+9tJ/EGgcNWuwvtawPxJG7Mmn86A== 125 | 126 | esbuild-linux-ppc64le@0.15.15: 127 | version "0.15.15" 128 | resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.15.tgz#2eba53fe2282438ceca5471bdb57ba2e00216ed6" 129 | integrity sha512-ek8gJBEIhcpGI327eAZigBOHl58QqrJrYYIZBWQCnH3UnXoeWMrMZLeeZL8BI2XMBhP+sQ6ERctD5X+ajL/AIA== 130 | 131 | esbuild-linux-riscv64@0.15.15: 132 | version "0.15.15" 133 | resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.15.tgz#1afa8dfe55a6c312f1904ee608b81417205f5027" 134 | integrity sha512-H5ilTZb33/GnUBrZMNJtBk7/OXzDHDXjIzoLXHSutwwsLxSNaLxzAaMoDGDd/keZoS+GDBqNVxdCkpuiRW4OSw== 135 | 136 | esbuild-linux-s390x@0.15.15: 137 | version "0.15.15" 138 | resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.15.tgz#1f7b3c4429c8ca99920ba6bf356ccc5b38fabd34" 139 | integrity sha512-jKaLUg78mua3rrtrkpv4Or2dNTJU7bgHN4bEjT4OX4GR7nLBSA9dfJezQouTxMmIW7opwEC5/iR9mpC18utnxQ== 140 | 141 | esbuild-netbsd-64@0.15.15: 142 | version "0.15.15" 143 | resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.15.tgz#d72c7155686c938c1aff126209b689c22823347c" 144 | integrity sha512-aOvmF/UkjFuW6F36HbIlImJTTx45KUCHJndtKo+KdP8Dhq3mgLRKW9+6Ircpm8bX/RcS3zZMMmaBLkvGY06Gvw== 145 | 146 | esbuild-openbsd-64@0.15.15: 147 | version "0.15.15" 148 | resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.15.tgz#761bd87ecab97386948eaf667a065cb0ecaa0f76" 149 | integrity sha512-HFFX+WYedx1w2yJ1VyR1Dfo8zyYGQZf1cA69bLdrHzu9svj6KH6ZLK0k3A1/LFPhcEY9idSOhsB2UyU0tHPxgQ== 150 | 151 | esbuild-sunos-64@0.15.15: 152 | version "0.15.15" 153 | resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.15.15.tgz#07e04cbf9747f281a967d09230a158a1be5b530c" 154 | integrity sha512-jOPBudffG4HN8yJXcK9rib/ZTFoTA5pvIKbRrt3IKAGMq1EpBi4xoVoSRrq/0d4OgZLaQbmkHp8RO9eZIn5atA== 155 | 156 | esbuild-windows-32@0.15.15: 157 | version "0.15.15" 158 | resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.15.15.tgz#130d1982cc41fb67461e9f8a65c6ebd13a1f35bb" 159 | integrity sha512-MDkJ3QkjnCetKF0fKxCyYNBnOq6dmidcwstBVeMtXSgGYTy8XSwBeIE4+HuKiSsG6I/mXEb++px3IGSmTN0XiA== 160 | 161 | esbuild-windows-64@0.15.15: 162 | version "0.15.15" 163 | resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.15.15.tgz#638bdf495c109c1882e8b0529cb8e2fea11383fb" 164 | integrity sha512-xaAUIB2qllE888SsMU3j9nrqyLbkqqkpQyWVkfwSil6BBPgcPk3zOFitTTncEKCLTQy3XV9RuH7PDj3aJDljWA== 165 | 166 | esbuild-windows-arm64@0.15.15: 167 | version "0.15.15" 168 | resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.15.tgz#5a277ce10de999d2a6465fc92a8c2a2d207ebd31" 169 | integrity sha512-ttuoCYCIJAFx4UUKKWYnFdrVpoXa3+3WWkXVI6s09U+YjhnyM5h96ewTq/WgQj9LFSIlABQvadHSOQyAVjW5xQ== 170 | 171 | esbuild@~0.15.10: 172 | version "0.15.15" 173 | resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.15.tgz#503b70bdc18d72d8fc2962ed3ab9219249e58bbe" 174 | integrity sha512-TEw/lwK4Zzld9x3FedV6jy8onOUHqcEX3ADFk4k+gzPUwrxn8nWV62tH0udo8jOtjFodlEfc4ypsqX3e+WWO6w== 175 | optionalDependencies: 176 | "@esbuild/android-arm" "0.15.15" 177 | "@esbuild/linux-loong64" "0.15.15" 178 | esbuild-android-64 "0.15.15" 179 | esbuild-android-arm64 "0.15.15" 180 | esbuild-darwin-64 "0.15.15" 181 | esbuild-darwin-arm64 "0.15.15" 182 | esbuild-freebsd-64 "0.15.15" 183 | esbuild-freebsd-arm64 "0.15.15" 184 | esbuild-linux-32 "0.15.15" 185 | esbuild-linux-64 "0.15.15" 186 | esbuild-linux-arm "0.15.15" 187 | esbuild-linux-arm64 "0.15.15" 188 | esbuild-linux-mips64le "0.15.15" 189 | esbuild-linux-ppc64le "0.15.15" 190 | esbuild-linux-riscv64 "0.15.15" 191 | esbuild-linux-s390x "0.15.15" 192 | esbuild-netbsd-64 "0.15.15" 193 | esbuild-openbsd-64 "0.15.15" 194 | esbuild-sunos-64 "0.15.15" 195 | esbuild-windows-32 "0.15.15" 196 | esbuild-windows-64 "0.15.15" 197 | esbuild-windows-arm64 "0.15.15" 198 | 199 | fetch-blob@^3.1.2, fetch-blob@^3.1.4: 200 | version "3.2.0" 201 | resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9" 202 | integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ== 203 | dependencies: 204 | node-domexception "^1.0.0" 205 | web-streams-polyfill "^3.0.3" 206 | 207 | form-data@^4.0.0: 208 | version "4.0.0" 209 | resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" 210 | integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== 211 | dependencies: 212 | asynckit "^0.4.0" 213 | combined-stream "^1.0.8" 214 | mime-types "^2.1.12" 215 | 216 | formdata-polyfill@^4.0.10: 217 | version "4.0.10" 218 | resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" 219 | integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== 220 | dependencies: 221 | fetch-blob "^3.1.2" 222 | 223 | fsevents@~2.3.2: 224 | version "2.3.2" 225 | resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" 226 | integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== 227 | 228 | get-tsconfig@^4.2.0: 229 | version "4.2.0" 230 | resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.2.0.tgz#ff368dd7104dab47bf923404eb93838245c66543" 231 | integrity sha512-X8u8fREiYOE6S8hLbq99PeykTDoLVnxvF4DjWKJmz9xy2nNRdUcV8ZN9tniJFeKyTU3qnC9lL8n4Chd6LmVKHg== 232 | 233 | mime-db@1.52.0: 234 | version "1.52.0" 235 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" 236 | integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== 237 | 238 | mime-types@^2.1.12: 239 | version "2.1.35" 240 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" 241 | integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== 242 | dependencies: 243 | mime-db "1.52.0" 244 | 245 | node-domexception@^1.0.0: 246 | version "1.0.0" 247 | resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" 248 | integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== 249 | 250 | node-fetch@^3.3.0: 251 | version "3.3.0" 252 | resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.0.tgz#37e71db4ecc257057af828d523a7243d651d91e4" 253 | integrity sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA== 254 | dependencies: 255 | data-uri-to-buffer "^4.0.0" 256 | fetch-blob "^3.1.4" 257 | formdata-polyfill "^4.0.10" 258 | 259 | source-map-support@^0.5.21: 260 | version "0.5.21" 261 | resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" 262 | integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== 263 | dependencies: 264 | buffer-from "^1.0.0" 265 | source-map "^0.6.0" 266 | 267 | source-map@^0.6.0: 268 | version "0.6.1" 269 | resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" 270 | integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== 271 | 272 | tsx@^3.12.1: 273 | version "3.12.1" 274 | resolved "https://registry.yarnpkg.com/tsx/-/tsx-3.12.1.tgz#d07532004c573bfea50a4ac687aa7270b3e34277" 275 | integrity sha512-Rcg1x+rNe7qwlP8j7kx4VjP/pJo/V57k+17hlrn6a7FuQLNwkaw5W4JF75tYornNVCxkXdSUnqlIT8JY/ttvIw== 276 | dependencies: 277 | "@esbuild-kit/cjs-loader" "^2.4.0" 278 | "@esbuild-kit/core-utils" "^3.0.0" 279 | "@esbuild-kit/esm-loader" "^2.5.0" 280 | optionalDependencies: 281 | fsevents "~2.3.2" 282 | 283 | web-streams-polyfill@^3.0.3: 284 | version "3.2.1" 285 | resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" 286 | integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== 287 | -------------------------------------------------------------------------------- /spec/v1alpha.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.3 2 | info: 3 | title: Stability.ai REST API 4 | version: 'v1alpha' 5 | servers: 6 | - url: https://api.stability.ai/v1alpha 7 | paths: 8 | /engines/list: 9 | get: 10 | description: List all engines available to your organization/user 11 | operationId: listEngines 12 | summary: list 13 | tags: 14 | - v1alpha/engines 15 | parameters: 16 | - $ref: '#/components/parameters/organization' 17 | - $ref: '#/components/parameters/apiKey' 18 | responses: 19 | '200': 20 | content: 21 | application/json: 22 | schema: 23 | $ref: '#/components/schemas/ListEnginesResponseBody' 24 | description: OK response. 25 | '401': 26 | content: 27 | application/json: 28 | schema: 29 | $ref: '#/components/schemas/Error' 30 | description: 'Unauthorized: The provided API key is not valid' 31 | security: 32 | - STABILITY_API_KEY: [] 33 | x-codeSamples: 34 | - lang: Python 35 | source: 36 | $ref: '../examples/python/code/v1alpha/list_engines.py' 37 | - label: TypeScript 38 | lang: Javascript 39 | source: 40 | $ref: '../examples/ts/code/v1alpha/list_engines.ts' 41 | - lang: Go 42 | source: 43 | $ref: '../examples/go/code/v1alpha/list_engines.go' 44 | - lang: cURL 45 | source: 46 | $ref: '../examples/curl/code/v1alpha/list_engines.sh' 47 | /generation/{engine_id}/image-to-image: 48 | post: 49 | description: Generate big fancy pictures from small fancy pictures - deprecated, use v1beta/image-to-image instead 50 | operationId: imageToImage 51 | summary: image-to-image 52 | tags: 53 | - v1alpha/generation 54 | parameters: 55 | - $ref: '#/components/parameters/engineID' 56 | - $ref: '#/components/parameters/accept' 57 | - $ref: '#/components/parameters/organization' 58 | - $ref: '#/components/parameters/apiKey' 59 | requestBody: 60 | content: 61 | multipart/form-data: 62 | example: 63 | init_image: 64 | options: 65 | cfg_scale: 7 66 | clip_guidance_preset: FAST_BLUE 67 | height: 512 68 | width: 512 69 | sampler: K_DPM_2_ANCESTRAL 70 | samples: 1 71 | seed: 0 72 | step_schedule_end: 0.01 73 | step_schedule_start: 0.4 74 | steps: 75 75 | text_prompts: 76 | - text: A lighthouse on a cliff 77 | weight: 1 78 | schema: 79 | $ref: '#/components/schemas/ImageToImageRequestBody' 80 | required: true 81 | responses: 82 | '200': 83 | description: OK response. 84 | headers: 85 | Content-Length: 86 | $ref: '#/components/headers/Content-Length' 87 | Content-Type: 88 | $ref: '#/components/headers/Content-Type' 89 | Finish-Reason: 90 | $ref: '#/components/headers/Finish-Reason' 91 | Seed: 92 | $ref: '#/components/headers/Seed' 93 | '400': 94 | content: 95 | application/json: 96 | schema: 97 | $ref: '#/components/schemas/Error' 98 | description: "bad_request: \n- invalid_samples: Sample count may only be greater than 1 when the accept header is set to `application/json`\n- invalid_height_or_width: Height and width must be specified in increments of 64\n- invalid_file_size: The file size of one or more of the provided files is invalid\n- invalid_mime_type: The mime type of one or more of the provided files is invalid\n- invalid_prompts: One or more of the prompts contains filtered words\n- invalid_pixel_count: Incorrect number of pixels specified. Requirements:\n\t- For 768 engines : 589,824 `height * width` 1,048,576\n\t- All other engines: 262,144 `height * width` 1,048,576\n" 99 | '401': 100 | content: 101 | application/json: 102 | schema: 103 | $ref: '#/components/schemas/Error' 104 | description: 'unauthorized: API key missing or invalid' 105 | '403': 106 | content: 107 | application/json: 108 | schema: 109 | $ref: '#/components/schemas/Error' 110 | description: 'permission_denied: You lack the necessary permissions to perform this action' 111 | '404': 112 | content: 113 | application/json: 114 | schema: 115 | $ref: '#/components/schemas/Error' 116 | description: 'not_found: The requested resource was not found (e.g. specifing a model that does not exist)' 117 | security: 118 | - STABILITY_API_KEY: [] 119 | x-codeSamples: 120 | - lang: Python 121 | source: 122 | $ref: '../examples/python/code/v1alpha/image_to_image.py' 123 | - label: TypeScript 124 | lang: Javascript 125 | source: 126 | $ref: '../examples/ts/code/v1alpha/image_to_image.ts' 127 | - lang: Go 128 | source: 129 | $ref: '../examples/go/code/v1alpha/image_to_image.go' 130 | - lang: cURL 131 | source: 132 | $ref: '../examples/curl/code/v1alpha/image_to_image.sh' 133 | /generation/{engine_id}/image-to-image/masking: 134 | post: 135 | description: Paint fancy things into fancy pictures - deprecated, use v1beta/image-to-image/masking instead 136 | operationId: masking 137 | summary: image-to-image/masking 138 | tags: 139 | - v1alpha/generation 140 | parameters: 141 | - $ref: '#/components/parameters/engineID' 142 | - $ref: '#/components/parameters/accept' 143 | - $ref: '#/components/parameters/organization' 144 | - $ref: '#/components/parameters/apiKey' 145 | requestBody: 146 | content: 147 | multipart/form-data: 148 | example: 149 | init_image: 150 | mask_image: 151 | options: 152 | cfg_scale: 7 153 | clip_guidance_preset: FAST_BLUE 154 | height: 512 155 | width: 512 156 | mask_source: MASK_IMAGE_BLACK 157 | sampler: K_DPM_2_ANCESTRAL 158 | samples: 1 159 | seed: 0 160 | steps: 75 161 | text_prompts: 162 | - text: A lighthouse on a cliff 163 | weight: 1 164 | schema: 165 | $ref: '#/components/schemas/MaskingRequestBody' 166 | required: true 167 | responses: 168 | '200': 169 | description: OK response. 170 | headers: 171 | Content-Length: 172 | $ref: '#/components/headers/Content-Length' 173 | Content-Type: 174 | $ref: '#/components/headers/Content-Type' 175 | Finish-Reason: 176 | $ref: '#/components/headers/Finish-Reason' 177 | Seed: 178 | $ref: '#/components/headers/Seed' 179 | '400': 180 | content: 181 | application/json: 182 | schema: 183 | $ref: '#/components/schemas/Error' 184 | description: "bad_request: \n- invalid_samples: Sample count may only be greater than 1 when the accept header is set to `application/json`\n- invalid_height_or_width: Height and width must be specified in increments of 64\n- invalid_file_size: The file size of one or more of the provided files is invalid\n- invalid_mime_type: The mime type of one or more of the provided files is invalid\n- invalid_image_dimensions: The dimensions of the provided `init_image` and `mask_image` do not match\n- invalid_mask_image: The parameter `mask_source` was set to `MASK_IMAGE_WHITE` or `MASK_IMAGE_BLACK` but no `mask_image` was provided\n- invalid_prompts: One or more of the prompts contains filtered words\n- invalid_pixel_count: Incorrect number of pixels specified. Requirements:\n\t- For 768 engines : 589,824 `height * width` 1,048,576\n\t- All other engines: 262,144 `height * width` 1,048,576\n" 185 | '401': 186 | content: 187 | application/json: 188 | schema: 189 | $ref: '#/components/schemas/Error' 190 | description: 'unauthorized: API key missing or invalid' 191 | '403': 192 | content: 193 | application/json: 194 | schema: 195 | $ref: '#/components/schemas/Error' 196 | description: 'permission_denied: You lack the necessary permissions to perform this action' 197 | '404': 198 | content: 199 | application/json: 200 | schema: 201 | $ref: '#/components/schemas/Error' 202 | description: 'not_found: The requested resource was not found (e.g. specifing a model that does not exist)' 203 | security: 204 | - STABILITY_API_KEY: [] 205 | x-codeSamples: 206 | - lang: Python 207 | source: 208 | $ref: '../examples/python/code/v1alpha/masking.py' 209 | - label: TypeScript 210 | lang: Javascript 211 | source: 212 | $ref: '../examples/ts/code/v1alpha/masking.ts' 213 | - lang: Go 214 | source: 215 | $ref: '../examples/go/code/v1alpha/masking.go' 216 | - lang: cURL 217 | source: 218 | $ref: '../examples/curl/code/v1alpha/masking.sh' 219 | /generation/{engine_id}/text-to-image: 220 | post: 221 | description: Generate an image from text - deprecated, use v1beta/text-to-image instead 222 | operationId: textToImage 223 | summary: text-to-image 224 | tags: 225 | - v1alpha/generation 226 | parameters: 227 | - $ref: '#/components/parameters/engineID' 228 | - $ref: '#/components/parameters/accept' 229 | - $ref: '#/components/parameters/organization' 230 | - $ref: '#/components/parameters/apiKey' 231 | requestBody: 232 | content: 233 | application/json: 234 | example: 235 | cfg_scale: 7 236 | clip_guidance_preset: FAST_BLUE 237 | height: 512 238 | width: 512 239 | sampler: K_DPM_2_ANCESTRAL 240 | samples: 1 241 | seed: 0 242 | steps: 75 243 | text_prompts: 244 | - text: A lighthouse on a cliff 245 | weight: 1 246 | schema: 247 | $ref: '#/components/schemas/TextToImageRequestBody' 248 | required: true 249 | responses: 250 | '200': 251 | description: OK response. 252 | headers: 253 | Content-Length: 254 | $ref: '#/components/headers/Content-Length' 255 | Content-Type: 256 | $ref: '#/components/headers/Content-Type' 257 | Finish-Reason: 258 | $ref: '#/components/headers/Finish-Reason' 259 | Seed: 260 | $ref: '#/components/headers/Seed' 261 | content: 262 | application/json: 263 | schema: 264 | type: array 265 | items: 266 | $ref: '#/components/schemas/Image' 267 | image/png: 268 | schema: 269 | format: binary 270 | type: string 271 | '400': 272 | content: 273 | application/json: 274 | schema: 275 | $ref: '#/components/schemas/Error' 276 | description: "bad_request: \n- invalid_samples: Sample count may only be greater than 1 when the accept header is set to `application/json`\n- invalid_height_or_width: Height and width must be specified in increments of 64\n- invalid_prompts: One or more of the prompts contains filtered words\n- invalid_pixel_count: Incorrect number of pixels specified. Requirements:\n\t- For 768 engines : 589,824 `height * width` 1,048,576\n\t- All other engines: 262,144 `height * width` 1,048,576\n" 277 | '401': 278 | content: 279 | application/json: 280 | schema: 281 | $ref: '#/components/schemas/Error' 282 | description: 'unauthorized: API key missing or invalid' 283 | '403': 284 | content: 285 | application/json: 286 | schema: 287 | $ref: '#/components/schemas/Error' 288 | description: 'permission_denied: You lack the necessary permissions to perform this action' 289 | '404': 290 | content: 291 | application/json: 292 | schema: 293 | $ref: '#/components/schemas/Error' 294 | description: 'not_found: The requested resource was not found (e.g. specifing a model that does not exist)' 295 | security: 296 | - STABILITY_API_KEY: [] 297 | x-codeSamples: 298 | - lang: Python 299 | source: 300 | $ref: '../examples/python/code/v1alpha/text_to_image.py' 301 | - label: TypeScript 302 | lang: Javascript 303 | source: 304 | $ref: '../examples/ts/code/v1alpha/text_to_image.ts' 305 | - lang: Go 306 | source: 307 | $ref: '../examples/go/code/v1alpha/text_to_image.go' 308 | - lang: cURL 309 | source: 310 | $ref: '../examples/curl/code/v1alpha/text_to_image.sh' 311 | /user/account: 312 | get: 313 | description: Get information about the account associated with the provided API key 314 | operationId: userAccount 315 | summary: account 316 | tags: 317 | - v1alpha/user 318 | parameters: 319 | - $ref: '#/components/parameters/apiKey' 320 | responses: 321 | '200': 322 | content: 323 | application/json: 324 | schema: 325 | $ref: '#/components/schemas/AccountResponseBody' 326 | description: OK response. 327 | '401': 328 | content: 329 | application/json: 330 | schema: 331 | $ref: '#/components/schemas/Error' 332 | description: 'Unauthorized: The provided API key is not valid' 333 | security: 334 | - STABILITY_API_KEY: [] 335 | x-codeSamples: 336 | - lang: Python 337 | source: 338 | $ref: '../examples/python/code/v1alpha/get_account.py' 339 | - label: TypeScript 340 | lang: Javascript 341 | source: 342 | $ref: '../examples/ts/code/v1alpha/get_account.ts' 343 | - lang: Go 344 | source: 345 | $ref: '../examples/go/code/v1alpha/get_account.go' 346 | - lang: cURL 347 | source: 348 | $ref: '../examples/curl/code/v1alpha/get_account.sh' 349 | /user/balance: 350 | get: 351 | description: Get the credit balance of the account/organization associated with the API key 352 | operationId: userBalance 353 | summary: balance 354 | tags: 355 | - v1alpha/user 356 | parameters: 357 | - $ref: '#/components/parameters/apiKey' 358 | - $ref: '#/components/parameters/organization' 359 | responses: 360 | '200': 361 | content: 362 | application/json: 363 | example: 364 | credits: 0.6336833840314097 365 | schema: 366 | $ref: '#/components/schemas/BalanceResponseBody' 367 | description: OK response. 368 | '401': 369 | content: 370 | application/json: 371 | schema: 372 | $ref: '#/components/schemas/Error' 373 | description: 'Unauthorized: The provided API key is not valid' 374 | security: 375 | - STABILITY_API_KEY: [] 376 | x-codeSamples: 377 | - lang: Python 378 | source: 379 | $ref: '../examples/python/code/v1alpha/get_balance.py' 380 | - label: TypeScript 381 | lang: Javascript 382 | source: 383 | $ref: '../examples/ts/code/v1alpha/get_balance.ts' 384 | - lang: Go 385 | source: 386 | $ref: '../examples/go/code/v1alpha/get_balance.go' 387 | - lang: cURL 388 | source: 389 | $ref: '../examples/curl/code/v1alpha/get_balance.sh' 390 | components: 391 | securitySchemes: 392 | STABILITY_API_KEY: 393 | type: apiKey 394 | name: Authorization 395 | in: header 396 | parameters: 397 | engineID: 398 | example: stable-diffusion-512-v2-0 399 | in: path 400 | name: engine_id 401 | required: true 402 | schema: 403 | example: stable-diffusion-512-v2-0 404 | type: string 405 | organization: 406 | allowEmptyValue: false 407 | description: "Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used." 408 | example: org-123456 409 | in: header 410 | name: Organization 411 | x-go-name: OrganizationID 412 | schema: 413 | type: string 414 | apiKey: 415 | allowEmptyValue: false 416 | required: true 417 | example: sk-KT........ 418 | in: header 419 | name: Authorization 420 | x-go-name: APIKey 421 | schema: 422 | type: string 423 | accept: 424 | allowEmptyValue: true 425 | in: header 426 | name: Accept 427 | schema: 428 | default: application/json 429 | enum: 430 | - application/json 431 | - image/png 432 | example: application/json 433 | type: string 434 | headers: 435 | Content-Length: 436 | required: true 437 | schema: 438 | type: integer 439 | Content-Type: 440 | required: true 441 | schema: 442 | enum: 443 | - image/png 444 | - application/json 445 | type: string 446 | Finish-Reason: 447 | schema: 448 | description: |- 449 | The result of the generation process. 450 | - `SUCCESS` indicates success 451 | - `ERROR` indicates an error 452 | - `CONTENT_FILTERED` indicates the result affected by the content filter and may be blurred. 453 | enum: 454 | - SUCCESS 455 | - ERROR 456 | - CONTENT_FILTERED 457 | type: string 458 | Seed: 459 | example: 3817857576 460 | schema: 461 | example: 787078103 462 | type: integer 463 | schemas: 464 | Engine: 465 | type: object 466 | properties: 467 | description: 468 | type: string 469 | id: 470 | type: string 471 | x-go-name: ID 472 | description: Unique identifier for the engine 473 | example: stable-diffusion-v1-5 474 | name: 475 | type: string 476 | description: Name of the engine 477 | example: Stable Diffusion v1.5 478 | type: 479 | type: string 480 | description: The type of content this engine produces 481 | example: PICTURE 482 | enum: 483 | - AUDIO 484 | - CLASSIFICATION 485 | - PICTURE 486 | - STORAGE 487 | - TEXT 488 | - VIDEO 489 | required: 490 | - id 491 | - name 492 | - description 493 | - type 494 | ListEnginesResponseBody: 495 | type: object 496 | properties: 497 | engines: 498 | type: array 499 | items: 500 | $ref: '#/components/schemas/Engine' 501 | description: The engines available to your user/organization 502 | example: 503 | - description: Stability-AI Stable Diffusion v1.5 504 | id: stable-diffusion-v1-5 505 | name: Stable Diffusion v1.5 506 | type: PICTURE 507 | - description: Stability-AI Stable Diffusion v2.1 508 | id: stable-diffusion-512-v2-1 509 | name: Stable Diffusion v2.1 510 | type: PICTURE 511 | - description: Stability-AI Stable Diffusion 768 v2.1 512 | id: stable-diffusion-768-v2-1 513 | name: Stable Diffusion v2.1-768 514 | type: PICTURE 515 | example: 516 | engines: 517 | - description: Stability-AI Stable Diffusion v1.5 518 | id: stable-diffusion-v1-5 519 | name: Stable Diffusion v1.5 520 | type: PICTURE 521 | - description: Stability-AI Stable Diffusion v2.1 522 | id: stable-diffusion-512-v2-1 523 | name: Stable Diffusion v2.1 524 | type: PICTURE 525 | - description: Stability-AI Stable Diffusion 768 v2.1 526 | id: stable-diffusion-768-v2-1 527 | name: Stable Diffusion v2.1-768 528 | type: PICTURE 529 | required: 530 | - engines 531 | Error: 532 | type: object 533 | x-go-name: RESTError 534 | properties: 535 | id: 536 | type: string 537 | description: ID is a unique identifier for this particular occurrence of the problem. 538 | example: 123abc 539 | x-go-name: ID 540 | name: 541 | type: string 542 | description: Name is the name of this class of errors. 543 | example: bad_request 544 | message: 545 | type: string 546 | description: Message is a human-readable explanation specific to this occurrence of the problem. 547 | example: parameter 'p' must be an integer 548 | fault: 549 | type: boolean 550 | description: Is the error a server-side fault? 551 | example: true 552 | temporary: 553 | type: boolean 554 | description: Is the error temporary? 555 | example: true 556 | timeout: 557 | type: boolean 558 | description: Is the error a timeout? 559 | example: false 560 | example: 561 | id: jqe9aYAI 562 | message: Value of ID must be an integer 563 | name: bad_request 564 | temporary: false 565 | timeout: false 566 | fault: true 567 | required: 568 | - id 569 | - name 570 | - message 571 | - temporary 572 | - timeout 573 | - fault 574 | - status 575 | CfgScale: 576 | type: number 577 | description: How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt) 578 | default: 7 579 | example: 7 580 | minimum: 0 581 | maximum: 35 582 | ClipGuidancePreset: 583 | type: string 584 | default: NONE 585 | example: FAST_BLUE 586 | enum: 587 | - FAST_BLUE 588 | - FAST_GREEN 589 | - NONE 590 | - SIMPLE 591 | - SLOW 592 | - SLOWER 593 | - SLOWEST 594 | Height: 595 | x-go-type: uint64 596 | type: integer 597 | description: |- 598 | Width of the image in pixels. Must be in increments of 64 and pass the following validation: 599 | - For 768 engines: 589,824 `height * width` 1,048,576 600 | - All other engines: 262,144 `height * width` 1,048,576 601 | default: 512 602 | example: 512 603 | minimum: 128 604 | Width: 605 | x-go-type: uint64 606 | type: integer 607 | description: |- 608 | Height of the image in pixels. Must be in increments of 64 and pass the following validation: 609 | - For 768 engines: 589,824 `height * width` 1,048,576 610 | - All other engines: 262,144 `height * width` 1,048,576 611 | default: 512 612 | example: 512 613 | minimum: 128 614 | Sampler: 615 | type: string 616 | description: Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you. 617 | example: K_DPM_2_ANCESTRAL 618 | enum: 619 | - DDIM 620 | - DDPM 621 | - K_DPMPP_2M 622 | - K_DPMPP_2S_ANCESTRAL 623 | - K_DPM_2 624 | - K_DPM_2_ANCESTRAL 625 | - K_EULER 626 | - K_EULER_ANCESTRAL 627 | - K_HEUN 628 | - K_LMS 629 | Samples: 630 | # TODO: Try to use int here? 631 | x-go-type: uint64 632 | type: integer 633 | description: Number of images to generate 634 | default: 1 635 | example: 1 636 | minimum: 1 637 | maximum: 10 638 | Seed: 639 | type: integer 640 | x-go-type: uint32 641 | description: Random noise seed (omit this option or use `0` for a random seed) 642 | default: 0 643 | example: 0 644 | minimum: 0 645 | maximum: 2147483647 646 | Steps: 647 | # TODO: Try to use int here? 648 | x-go-type: uint64 649 | type: integer 650 | description: Number of diffusion steps to run 651 | default: 50 652 | example: 75 653 | minimum: 10 654 | maximum: 150 655 | TextPrompt: 656 | type: object 657 | properties: 658 | text: 659 | type: string 660 | example: 6el 661 | maxLength: 2000 662 | weight: 663 | type: number 664 | description: Weight of the prompt (use negative numbers for negative prompts) 665 | example: 0.8167237 666 | format: float 667 | description: Text prompt for image generation 668 | example: 669 | text: nf9 670 | weight: 0.40370443 671 | required: 672 | - text 673 | TextPrompts: 674 | type: array 675 | items: 676 | $ref: '#/components/schemas/TextPrompt' 677 | example: 678 | - text: A lighthouse on a cliff 679 | weight: 1 680 | minItems: 1 681 | ImageToImageOptions: 682 | type: object 683 | properties: 684 | cfg_scale: 685 | $ref: '#/components/schemas/CfgScale' 686 | clip_guidance_preset: 687 | $ref: '#/components/schemas/ClipGuidancePreset' 688 | height: 689 | $ref: '#/components/schemas/Height' 690 | width: 691 | $ref: '#/components/schemas/Width' 692 | sampler: 693 | $ref: '#/components/schemas/Sampler' 694 | samples: 695 | $ref: '#/components/schemas/Samples' 696 | seed: 697 | $ref: '#/components/schemas/Seed' 698 | steps: 699 | $ref: '#/components/schemas/Steps' 700 | text_prompts: 701 | $ref: '#/components/schemas/TextPrompts' 702 | step_schedule_end: 703 | type: number 704 | description: Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. 705 | example: 0.01 706 | minimum: 0 707 | maximum: 1 708 | step_schedule_start: 709 | type: number 710 | description: Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of `0` would simply return you the init_image, where a value of `1` would return you a completely different image.) 711 | example: 0.4 712 | minimum: 0 713 | maximum: 1 714 | example: 715 | cfg_scale: 7 716 | clip_guidance_preset: FAST_BLUE 717 | height: 512 718 | sampler: K_DPM_2_ANCESTRAL 719 | samples: 1 720 | seed: 0 721 | step_schedule_end: 0.01 722 | step_schedule_start: 0.4 723 | steps: 75 724 | text_prompts: 725 | - text: A lighthouse on a cliff 726 | weight: 1 727 | width: 512 728 | required: 729 | - text_prompts 730 | ImageToImageRequestBody: 731 | type: object 732 | properties: 733 | init_image: 734 | x-go-type: '[]byte' 735 | type: string 736 | description: Initial image to use for the image-to-image generation 737 | example: 738 | format: binary 739 | options: 740 | $ref: '#/components/schemas/ImageToImageOptions' 741 | example: 742 | init_image: 743 | options: 744 | cfg_scale: 7 745 | clip_guidance_preset: FAST_BLUE 746 | height: 512 747 | sampler: K_DPM_2_ANCESTRAL 748 | samples: 1 749 | seed: 0 750 | step_schedule_end: 0.01 751 | step_schedule_start: 0.4 752 | steps: 75 753 | text_prompts: 754 | - text: A lighthouse on a cliff 755 | weight: 1 756 | width: 512 757 | required: 758 | - options 759 | - init_image 760 | MaskingOptions: 761 | type: object 762 | properties: 763 | cfg_scale: 764 | $ref: '#/components/schemas/CfgScale' 765 | clip_guidance_preset: 766 | $ref: '#/components/schemas/ClipGuidancePreset' 767 | height: 768 | $ref: '#/components/schemas/Height' 769 | width: 770 | $ref: '#/components/schemas/Width' 771 | sampler: 772 | $ref: '#/components/schemas/Sampler' 773 | samples: 774 | $ref: '#/components/schemas/Samples' 775 | seed: 776 | $ref: '#/components/schemas/Seed' 777 | steps: 778 | $ref: '#/components/schemas/Steps' 779 | text_prompts: 780 | $ref: '#/components/schemas/TextPrompts' 781 | step_schedule_end: 782 | type: number 783 | description: Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. 784 | example: 0.01 785 | minimum: 0 786 | maximum: 1 787 | step_schedule_start: 788 | type: number 789 | description: Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of `0` would simply return you the init_image, where a value of `1` would return you a completely different image.) 790 | example: 0.4 791 | minimum: 0 792 | maximum: 1 793 | mask_source: 794 | type: string 795 | description: |- 796 | For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from: 797 | - `MASK_IMAGE_WHITE` will use the white pixels of the mask_image as the mask, where white pixels are completely replaced and black pixels are unchanged 798 | - `MASK_IMAGE_BLACK` will use the black pixels of the mask_image as the mask, where black pixels are completely replaced and white pixels are unchanged 799 | - `INIT_IMAGE_ALPHA` will use the alpha channel of the init_image as the mask, where fully transparent pixels are completely replaced and fully opaque pixels are unchanged (**Note:** we ignore mask_image when this parameter is present so it can be omitted) 800 | example: MASK_IMAGE_WHITE 801 | enum: 802 | - INIT_IMAGE_ALPHA 803 | - MASK_IMAGE_WHITE 804 | - MASK_IMAGE_BLACK 805 | example: 806 | cfg_scale: 7 807 | clip_guidance_preset: FAST_BLUE 808 | height: 512 809 | mask_source: INIT_IMAGE_ALPHA 810 | sampler: K_DPM_2_ANCESTRAL 811 | samples: 1 812 | seed: 0 813 | steps: 75 814 | text_prompts: 815 | - text: A lighthouse on a cliff 816 | weight: 1 817 | width: 512 818 | required: 819 | - text_prompts 820 | - mask_source 821 | MaskingRequestBody: 822 | type: object 823 | properties: 824 | init_image: 825 | x-go-type: '[]byte' 826 | type: string 827 | description: Initial image to use for the image-to-image generation 828 | example: 829 | format: binary 830 | mask_image: 831 | x-go-type: '[]byte' 832 | type: string 833 | description: 'Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the `init_image`. Use the `mask_source` option to specify whether the white or black pixels should be inpainted. (Note: if you set `mask_source` to `INIT_IMAGE_ALPHA` you can omit the `mask_image` parameter.)' 834 | example: 835 | format: binary 836 | options: 837 | $ref: '#/components/schemas/MaskingOptions' 838 | example: 839 | init_image: 840 | mask_image: 841 | options: 842 | cfg_scale: 7 843 | clip_guidance_preset: FAST_BLUE 844 | height: 512 845 | mask_source: MASK_IMAGE_BLACK 846 | sampler: K_DPM_2_ANCESTRAL 847 | samples: 1 848 | seed: 0 849 | steps: 75 850 | text_prompts: 851 | - text: A lighthouse on a cliff 852 | weight: 1 853 | width: 512 854 | required: 855 | - options 856 | - init_image 857 | TextToImageRequestBody: 858 | type: object 859 | properties: 860 | cfg_scale: 861 | $ref: '#/components/schemas/CfgScale' 862 | clip_guidance_preset: 863 | $ref: '#/components/schemas/ClipGuidancePreset' 864 | height: 865 | $ref: '#/components/schemas/Height' 866 | width: 867 | $ref: '#/components/schemas/Width' 868 | sampler: 869 | $ref: '#/components/schemas/Sampler' 870 | samples: 871 | $ref: '#/components/schemas/Samples' 872 | seed: 873 | $ref: '#/components/schemas/Seed' 874 | steps: 875 | $ref: '#/components/schemas/Steps' 876 | text_prompts: 877 | $ref: '#/components/schemas/TextPrompts' 878 | example: 879 | cfg_scale: 7 880 | clip_guidance_preset: FAST_BLUE 881 | height: 512 882 | sampler: K_DPM_2_ANCESTRAL 883 | samples: 1 884 | seed: 0 885 | steps: 75 886 | text_prompts: 887 | - text: A lighthouse on a cliff 888 | weight: 1 889 | width: 512 890 | required: 891 | - text_prompts 892 | Image: 893 | type: object 894 | properties: 895 | base64: 896 | type: string 897 | description: Image encoded in base64 898 | example: Sed corporis modi et. 899 | finishReason: 900 | type: string 901 | example: CONTENT_FILTERED 902 | enum: 903 | - SUCCESS 904 | - ERROR 905 | - CONTENT_FILTERED 906 | seed: 907 | type: number 908 | description: The seed associated with this image 909 | example: 1229191277 910 | example: 911 | - base64: ...very long string... 912 | finishReason: SUCCESS 913 | seed: 1050625087 914 | - base64: ...very long string... 915 | finishReason: CONTENT_FILTERED 916 | seed: 1229191277 917 | OrganizationMembership: 918 | type: object 919 | properties: 920 | id: 921 | type: string 922 | example: org-123456 923 | x-go-name: ID 924 | is_default: 925 | type: boolean 926 | example: false 927 | name: 928 | type: string 929 | example: My Organization 930 | role: 931 | type: string 932 | example: MEMBER 933 | example: 934 | id: org-123456 935 | is_default: false 936 | name: My Organization 937 | role: MEMBER 938 | required: 939 | - id 940 | - name 941 | - role 942 | - is_default 943 | AccountResponseBody: 944 | type: object 945 | properties: 946 | email: 947 | type: string 948 | description: The user's email 949 | example: example@stability.ai 950 | format: email 951 | id: 952 | type: string 953 | description: The user's ID 954 | example: user-1234 955 | x-go-name: ID 956 | organizations: 957 | type: array 958 | items: 959 | $ref: '#/components/schemas/OrganizationMembership' 960 | description: The user's organizations 961 | example: 962 | - id: org-123456 963 | is_default: false 964 | name: My Organization 965 | role: MEMBER 966 | - id: org-123456 967 | is_default: false 968 | name: My Organization 969 | role: MEMBER 970 | - id: org-123456 971 | is_default: false 972 | name: My Organization 973 | role: MEMBER 974 | profile_picture: 975 | type: string 976 | description: The user's profile picture 977 | example: https://api.stability.ai/example.png 978 | format: uri 979 | example: 980 | email: example@stability.ai 981 | id: user-1234 982 | organizations: 983 | - id: org-123456 984 | is_default: false 985 | name: My Organization 986 | role: MEMBER 987 | - id: org-123456 988 | is_default: false 989 | name: My Organization 990 | role: MEMBER 991 | - id: org-123456 992 | is_default: false 993 | name: My Organization 994 | role: MEMBER 995 | - id: org-123456 996 | is_default: false 997 | name: My Organization 998 | role: MEMBER 999 | profile_picture: https://api.stability.ai/example.png 1000 | required: 1001 | - id 1002 | - email 1003 | - organizations 1004 | BalanceResponseBody: 1005 | type: object 1006 | properties: 1007 | credits: 1008 | type: number 1009 | description: The balance of the account/organization associated with the API key 1010 | example: 0.41122252265928866 1011 | format: double 1012 | example: 1013 | credits: 0.07903292496944721 1014 | required: 1015 | - credits 1016 | tags: 1017 | - name: v1alpha/user 1018 | description: Manage your Stability.ai account, and view account/organization balances - deprecated, use v1beta/user instead 1019 | - name: v1alpha/engines 1020 | description: Enumerate available engines - deprecated, use v1beta/engines instead 1021 | - name: v1alpha/generation 1022 | description: Generate images from text, existing images, or both - deprecated, use v1beta/generation instead 1023 | -------------------------------------------------------------------------------- /spec/v1beta.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.3 2 | info: 3 | title: Stability.ai REST API 4 | version: 'v1beta' 5 | servers: 6 | - url: https://api.stability.ai/v1beta 7 | paths: 8 | /generation/{engine_id}/text-to-image: 9 | post: 10 | description: Generate an image from text - deprecated, use v1/text-to-image instead 11 | operationId: textToImage 12 | summary: text-to-image 13 | tags: 14 | - v1beta/generation 15 | parameters: 16 | - $ref: '#/components/parameters/engineID' 17 | - $ref: '#/components/parameters/accept' 18 | - $ref: '#/components/parameters/organization' 19 | requestBody: 20 | content: 21 | application/json: 22 | example: 23 | cfg_scale: 7 24 | clip_guidance_preset: FAST_BLUE 25 | height: 512 26 | width: 512 27 | sampler: K_DPM_2_ANCESTRAL 28 | samples: 1 29 | steps: 75 30 | text_prompts: 31 | - text: A lighthouse on a cliff 32 | weight: 1 33 | schema: 34 | $ref: '#/components/schemas/TextToImageRequestBody' 35 | required: true 36 | responses: 37 | '200': 38 | description: OK response. 39 | content: 40 | application/json: 41 | schema: 42 | description: The result of the generation request, containing one or more images as base64 encoded strings. 43 | items: 44 | $ref: '#/components/schemas/Image' 45 | type: array 46 | image/png: 47 | example: PNG bytes, what did you expect? 48 | schema: 49 | description: The bytes of the generated image 50 | format: binary 51 | type: string 52 | headers: 53 | Content-Length: 54 | $ref: '#/components/headers/Content-Length' 55 | Content-Type: 56 | $ref: '#/components/headers/Content-Type' 57 | Finish-Reason: 58 | $ref: '#/components/headers/Finish-Reason' 59 | Seed: 60 | $ref: '#/components/headers/Seed' 61 | '400': 62 | $ref: '#/components/responses/400FromGeneration' 63 | '401': 64 | $ref: '#/components/responses/401' 65 | '403': 66 | $ref: '#/components/responses/403' 67 | '404': 68 | $ref: '#/components/responses/404' 69 | '500': 70 | $ref: '#/components/responses/500' 71 | security: 72 | - STABILITY_API_KEY: [] 73 | x-codeSamples: 74 | - lang: Python 75 | source: 76 | $ref: '../examples/python/code/v1beta/text_to_image.py' 77 | - label: TypeScript 78 | lang: Javascript 79 | source: 80 | $ref: '../examples/ts/code/v1beta/text_to_image.ts' 81 | - lang: Go 82 | source: 83 | $ref: '../examples/go/code/v1beta/text_to_image.go' 84 | - lang: cURL 85 | source: 86 | $ref: '../examples/curl/code/v1beta/text_to_image.sh' 87 | /generation/{engine_id}/image-to-image: 88 | post: 89 | description: Generate big fancy pictures from small fancy pictures - deprecated, use v1/image-to-image instead 90 | operationId: imageToImage 91 | summary: image-to-image 92 | tags: 93 | - v1beta/generation 94 | parameters: 95 | - $ref: '#/components/parameters/engineID' 96 | - $ref: '#/components/parameters/accept' 97 | - $ref: '#/components/parameters/organization' 98 | requestBody: 99 | content: 100 | multipart/form-data: 101 | schema: 102 | $ref: '#/components/schemas/ImageToImageRequestBody' 103 | examples: 104 | IMAGE_STRENGTH: 105 | summary: Using IMAGE_STRENGTH 106 | description: Request using 35% image_strength 107 | value: 108 | image_strength: 0.35 109 | init_image_mode: 'IMAGE_STRENGTH' 110 | init_image: '' 111 | text_prompts[0][text]: A dog space commander 112 | text_prompts[0][weight]: 1 113 | cfg_scale: 7 114 | clip_guidance_preset: FAST_BLUE 115 | height: 512 116 | width: 512 117 | sampler: K_DPM_2_ANCESTRAL 118 | samples: 3 119 | steps: 20 120 | STEP_SCHEDULE: 121 | summary: Using STEP_SCHEDULE 122 | description: Equivalent request using step_schedule_start 123 | value: 124 | step_schedule_start: 0.65 125 | init_image_mode: 'STEP_SCHEDULE' 126 | init_image: '' 127 | text_prompts[0][text]: A dog space commander 128 | text_prompts[0][weight]: 1 129 | cfg_scale: 7 130 | clip_guidance_preset: FAST_BLUE 131 | height: 512 132 | width: 512 133 | sampler: K_DPM_2_ANCESTRAL 134 | samples: 3 135 | steps: 20 136 | required: true 137 | responses: 138 | '200': 139 | description: OK response. 140 | content: 141 | application/json: 142 | schema: 143 | description: The result of the generation request, containing one or more images as base64 encoded strings. 144 | items: 145 | $ref: '#/components/schemas/Image' 146 | type: array 147 | image/png: 148 | example: PNG bytes, what did you expect? 149 | schema: 150 | description: The bytes of the generated image 151 | format: binary 152 | type: string 153 | headers: 154 | Content-Length: 155 | $ref: '#/components/headers/Content-Length' 156 | Content-Type: 157 | $ref: '#/components/headers/Content-Type' 158 | Finish-Reason: 159 | $ref: '#/components/headers/Finish-Reason' 160 | Seed: 161 | $ref: '#/components/headers/Seed' 162 | '400': 163 | $ref: '#/components/responses/400FromGeneration' 164 | '401': 165 | $ref: '#/components/responses/401' 166 | '403': 167 | $ref: '#/components/responses/403' 168 | '404': 169 | $ref: '#/components/responses/404' 170 | '500': 171 | $ref: '#/components/responses/500' 172 | security: 173 | - STABILITY_API_KEY: [] 174 | x-codeSamples: 175 | - lang: Python 176 | source: 177 | $ref: '../examples/python/code/v1beta/image_to_image.py' 178 | - label: TypeScript 179 | lang: Javascript 180 | source: 181 | $ref: '../examples/ts/code/v1beta/image_to_image.ts' 182 | - lang: Go 183 | source: 184 | $ref: '../examples/go/code/v1beta/image_to_image.go' 185 | - lang: cURL 186 | source: 187 | $ref: '../examples/curl/code/v1beta/image_to_image.sh' 188 | /generation/{engine_id}/image-to-image/masking: 189 | post: 190 | description: Paint fancy things into fancy pictures 191 | operationId: masking 192 | summary: image-to-image/masking 193 | tags: 194 | - v1beta/generation 195 | parameters: 196 | - example: stable-inpainting-512-v2-0 197 | in: path 198 | name: engine_id 199 | required: true 200 | schema: 201 | type: string 202 | - $ref: '#/components/parameters/accept' 203 | - $ref: '#/components/parameters/organization' 204 | requestBody: 205 | required: true 206 | content: 207 | multipart/form-data: 208 | schema: 209 | $ref: '#/components/schemas/MaskingRequestBody' 210 | examples: 211 | MASK_IMAGE_BLACK: 212 | value: 213 | mask_source: 'MASK_IMAGE_BLACK' 214 | init_image: '' 215 | mask_image: '' 216 | text_prompts[0][text]: A dog space commander 217 | text_prompts[0][weight]: 1 218 | cfg_scale: 7 219 | clip_guidance_preset: FAST_BLUE 220 | height: 512 221 | width: 512 222 | sampler: K_DPM_2_ANCESTRAL 223 | samples: 3 224 | steps: 20 225 | MASK_IMAGE_WHITE: 226 | value: 227 | mask_source: 'MASK_IMAGE_WHITE' 228 | init_image: '' 229 | mask_image: '' 230 | text_prompts[0][text]: A dog space commander 231 | text_prompts[0][weight]: 1 232 | cfg_scale: 7 233 | clip_guidance_preset: FAST_BLUE 234 | height: 512 235 | width: 512 236 | sampler: K_DPM_2_ANCESTRAL 237 | samples: 3 238 | steps: 20 239 | INIT_IMAGE_ALPHA: 240 | value: 241 | mask_source: 'INIT_IMAGE_ALPHA' 242 | init_image: '' 243 | text_prompts[0][text]: A dog space commander 244 | text_prompts[0][weight]: 1 245 | cfg_scale: 7 246 | clip_guidance_preset: FAST_BLUE 247 | height: 512 248 | width: 512 249 | sampler: K_DPM_2_ANCESTRAL 250 | samples: 3 251 | steps: 20 252 | responses: 253 | '200': 254 | description: OK response. 255 | content: 256 | application/json: 257 | schema: 258 | description: The result of the generation request, containing one or more images as base64 encoded strings. 259 | items: 260 | $ref: '#/components/schemas/Image' 261 | type: array 262 | image/png: 263 | example: PNG bytes, what did you expect? 264 | schema: 265 | description: The bytes of the generated image 266 | format: binary 267 | type: string 268 | headers: 269 | Content-Length: 270 | $ref: '#/components/headers/Content-Length' 271 | Content-Type: 272 | $ref: '#/components/headers/Content-Type' 273 | Finish-Reason: 274 | $ref: '#/components/headers/Finish-Reason' 275 | Seed: 276 | $ref: '#/components/headers/Seed' 277 | '400': 278 | $ref: '#/components/responses/400FromGeneration' 279 | '401': 280 | $ref: '#/components/responses/401' 281 | '403': 282 | $ref: '#/components/responses/403' 283 | '404': 284 | $ref: '#/components/responses/404' 285 | '500': 286 | $ref: '#/components/responses/500' 287 | security: 288 | - STABILITY_API_KEY: [] 289 | x-codeSamples: 290 | - lang: Python 291 | source: 292 | $ref: '../examples/python/code/v1beta/masking.py' 293 | - label: TypeScript 294 | lang: Javascript 295 | source: 296 | $ref: '../examples/ts/code/v1beta/masking.ts' 297 | - lang: Go 298 | source: 299 | $ref: '../examples/go/code/v1beta/masking.go' 300 | - lang: cURL 301 | source: 302 | $ref: '../examples/curl/code/v1beta/masking.sh' 303 | /engines/list: 304 | get: 305 | description: List all engines available to your organization/user - deprecated, use v1/engines/list instead 306 | operationId: listEngines 307 | summary: list 308 | tags: 309 | - v1beta/engines 310 | parameters: 311 | - $ref: '#/components/parameters/organization' 312 | responses: 313 | '200': 314 | content: 315 | application/json: 316 | schema: 317 | $ref: '#/components/schemas/ListEnginesResponseBody' 318 | description: OK response. 319 | '401': 320 | $ref: '#/components/responses/401' 321 | '500': 322 | $ref: '#/components/responses/500' 323 | security: 324 | - STABILITY_API_KEY: [] 325 | x-codeSamples: 326 | - lang: Python 327 | source: 328 | $ref: '../examples/python/code/v1beta/list_engines.py' 329 | - label: TypeScript 330 | lang: Javascript 331 | source: 332 | $ref: '../examples/ts/code/v1beta/list_engines.ts' 333 | - lang: Go 334 | source: 335 | $ref: '../examples/go/code/v1beta/list_engines.go' 336 | - lang: cURL 337 | source: 338 | $ref: '../examples/curl/code/v1beta/list_engines.sh' 339 | /user/account: 340 | get: 341 | description: Get information about the account associated with the provided API key - deprecated, use v1/user/account instead 342 | operationId: userAccount 343 | summary: account 344 | tags: 345 | - v1beta/user 346 | responses: 347 | '200': 348 | content: 349 | application/json: 350 | schema: 351 | $ref: '#/components/schemas/AccountResponseBody' 352 | description: OK response. 353 | '401': 354 | $ref: '#/components/responses/401' 355 | '500': 356 | $ref: '#/components/responses/500' 357 | security: 358 | - STABILITY_API_KEY: [] 359 | x-codeSamples: 360 | - lang: Python 361 | source: 362 | $ref: '../examples/python/code/v1beta/get_account.py' 363 | - label: TypeScript 364 | lang: Javascript 365 | source: 366 | $ref: '../examples/ts/code/v1beta/get_account.ts' 367 | - lang: Go 368 | source: 369 | $ref: '../examples/go/code/v1beta/get_account.go' 370 | - lang: cURL 371 | source: 372 | $ref: '../examples/curl/code/v1beta/get_account.sh' 373 | /user/balance: 374 | get: 375 | description: Get the credit balance of the account/organization associated with the API key - deprecated, use v1/user/balance instead 376 | operationId: userBalance 377 | summary: balance 378 | tags: 379 | - v1beta/user 380 | parameters: 381 | - $ref: '#/components/parameters/organization' 382 | responses: 383 | '200': 384 | content: 385 | application/json: 386 | example: 387 | credits: 0.6336833840314097 388 | schema: 389 | $ref: '#/components/schemas/BalanceResponseBody' 390 | description: OK response. 391 | '401': 392 | $ref: '#/components/responses/401' 393 | '500': 394 | $ref: '#/components/responses/500' 395 | security: 396 | - STABILITY_API_KEY: [] 397 | x-codeSamples: 398 | - lang: Python 399 | source: 400 | $ref: '../examples/python/code/v1beta/get_balance.py' 401 | - label: TypeScript 402 | lang: Javascript 403 | source: 404 | $ref: '../examples/ts/code/v1beta/get_balance.ts' 405 | - lang: Go 406 | source: 407 | $ref: '../examples/go/code/v1beta/get_balance.go' 408 | - lang: cURL 409 | source: 410 | $ref: '../examples/curl/code/v1beta/get_balance.sh' 411 | components: 412 | securitySchemes: 413 | STABILITY_API_KEY: 414 | type: apiKey 415 | name: Authorization 416 | in: header 417 | parameters: 418 | engineID: 419 | example: stable-diffusion-512-v2-0 420 | in: path 421 | name: engine_id 422 | required: true 423 | schema: 424 | example: stable-diffusion-512-v2-0 425 | type: string 426 | organization: 427 | allowEmptyValue: false 428 | description: "Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used." 429 | example: org-123456 430 | in: header 431 | name: Organization 432 | x-go-name: OrganizationID 433 | schema: 434 | type: string 435 | accept: 436 | allowEmptyValue: false 437 | in: header 438 | name: Accept 439 | description: "The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image." 440 | schema: 441 | default: application/json 442 | enum: 443 | - application/json 444 | - image/png 445 | type: string 446 | headers: 447 | Content-Length: 448 | required: true 449 | schema: 450 | type: integer 451 | Content-Type: 452 | required: true 453 | schema: 454 | enum: 455 | - application/json 456 | - image/png 457 | type: string 458 | Finish-Reason: 459 | schema: 460 | $ref: '#/components/schemas/FinishReason' 461 | Seed: 462 | example: 3817857576 463 | schema: 464 | example: 787078103 465 | type: integer 466 | description: The seed used to generate the image. This header is only present when the `Accept` is set to `image/png`. Otherwise it is returned in the response body. 467 | schemas: 468 | Engine: 469 | type: object 470 | properties: 471 | description: 472 | type: string 473 | id: 474 | type: string 475 | x-go-name: ID 476 | description: Unique identifier for the engine 477 | example: stable-diffusion-v1-5 478 | name: 479 | type: string 480 | description: Name of the engine 481 | example: Stable Diffusion v1.5 482 | type: 483 | type: string 484 | description: The type of content this engine produces 485 | example: PICTURE 486 | enum: 487 | - AUDIO 488 | - CLASSIFICATION 489 | - PICTURE 490 | - STORAGE 491 | - TEXT 492 | - VIDEO 493 | required: 494 | - id 495 | - name 496 | - description 497 | - type 498 | Error: 499 | type: object 500 | x-go-name: RESTError 501 | properties: 502 | id: 503 | x-go-name: ID 504 | type: string 505 | description: A unique identifier for this particular occurrence of the problem. 506 | example: 296a972f-666a-44a1-a3df-c9c28a1f56c0 507 | name: 508 | type: string 509 | description: The short-name of this class of errors e.g. `bad_request`. 510 | example: bad_request 511 | message: 512 | type: string 513 | description: A human-readable explanation specific to this occurrence of the problem. 514 | example: Header parameter Authorization is required, but not found 515 | required: 516 | - name 517 | - id 518 | - message 519 | - status 520 | CfgScale: 521 | type: number 522 | description: How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt) 523 | default: 7 524 | example: 7 525 | minimum: 0 526 | maximum: 35 527 | ClipGuidancePreset: 528 | type: string 529 | default: NONE 530 | example: FAST_BLUE 531 | enum: 532 | - FAST_BLUE 533 | - FAST_GREEN 534 | - NONE 535 | - SIMPLE 536 | - SLOW 537 | - SLOWER 538 | - SLOWEST 539 | Height: 540 | x-go-type: uint64 541 | type: integer 542 | description: |- 543 | Height of the image in pixels. Must be in increments of 64 and pass the following validation: 544 | - For 768 engines: 589,824 `height * width` 1,048,576 545 | - All other engines: 262,144 `height * width` 1,048,576 546 | multipleOf: 64 547 | default: 512 548 | example: 512 549 | minimum: 128 550 | Width: 551 | x-go-type: uint64 552 | type: integer 553 | description: |- 554 | Width of the image in pixels. Must be in increments of 64 and pass the following validation: 555 | - For 768 engines: 589,824 `height * width` 1,048,576 556 | - All other engines: 262,144 `height * width` 1,048,576 557 | multipleOf: 64 558 | default: 512 559 | example: 512 560 | minimum: 128 561 | Sampler: 562 | type: string 563 | description: Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you. 564 | example: K_DPM_2_ANCESTRAL 565 | enum: 566 | - DDIM 567 | - DDPM 568 | - K_DPMPP_2M 569 | - K_DPMPP_2S_ANCESTRAL 570 | - K_DPM_2 571 | - K_DPM_2_ANCESTRAL 572 | - K_EULER 573 | - K_EULER_ANCESTRAL 574 | - K_HEUN 575 | - K_LMS 576 | Samples: 577 | x-go-type: uint64 578 | type: integer 579 | description: Number of images to generate 580 | default: 1 581 | example: 1 582 | minimum: 1 583 | maximum: 10 584 | Seed: 585 | type: integer 586 | x-go-type: uint32 587 | description: Random noise seed (omit this option or use `0` for a random seed) 588 | default: 0 589 | example: 0 590 | minimum: 0 591 | maximum: 4294967295 592 | Steps: 593 | x-go-type: uint64 594 | type: integer 595 | description: Number of diffusion steps to run 596 | default: 50 597 | example: 75 598 | minimum: 10 599 | maximum: 150 600 | TextPrompt: 601 | type: object 602 | properties: 603 | text: 604 | type: string 605 | description: The prompt itself 606 | example: A lighthouse on a cliff 607 | maxLength: 2000 608 | weight: 609 | type: number 610 | description: Weight of the prompt (use negative numbers for negative prompts) 611 | example: 0.8167237 612 | format: float 613 | description: Text prompt for image generation 614 | required: 615 | - text 616 | TextPromptsForTextToImage: 617 | title: TextPrompts 618 | type: array 619 | items: 620 | $ref: '#/components/schemas/TextPrompt' 621 | minItems: 1 622 | description: |- 623 | An array of text prompts to use for generation. 624 | 625 | Given a text prompt with the text `A lighthouse on a cliff` and a weight of `0.5`, it would be represented as: 626 | 627 |
 628 |         "text_prompts": [
 629 |           {
 630 |             "text": "A lighthouse on a cliff",
 631 |             "weight": 0.5
 632 |           }
 633 |         ]
 634 |         
635 | TextPrompts: 636 | description: |- 637 | An array of text prompts to use for generation. 638 | 639 | Due to how arrays are represented in `multipart/form-data` requests, prompts must adhear to the format `text_prompts[index][text|weight]`, 640 | where `index` is some integer used to tie the text and weight together. While `index` does not have to be sequential, duplicate entries 641 | will override previous entries, so it is recommended to use sequential indices. 642 | 643 | Given a text prompt with the text `A lighthouse on a cliff` and a weight of `0.5`, it would be represented as: 644 | ``` 645 | text_prompts[0][text]: "A lighthouse on a cliff" 646 | text_prompts[0][weight]: 0.5 647 | ``` 648 | 649 | To add another prompt to that request simply provide the values under a new `index`: 650 | 651 | ``` 652 | text_prompts[0][text]: "A lighthouse on a cliff" 653 | text_prompts[0][weight]: 0.5 654 | text_prompts[1][text]: "land, ground, dirt, grass" 655 | text_prompts[1][weight]: -0.9 656 | ``` 657 | type: array 658 | items: 659 | $ref: '#/components/schemas/TextPrompt' 660 | minItems: 1 661 | InitImage: 662 | x-go-type: '[]byte' 663 | type: string 664 | description: Image used to initialize the diffusion process, in lieu of random noise. 665 | example: 666 | format: binary 667 | InitImageStrength: 668 | type: number 669 | description: > 670 | How much influence the `init_image` has on the diffusion process. Values close to `1` will yield images very similar to the `init_image` while values close to `0` will yield images wildly different than the `init_image`. The behavior of this is meant to mirror DreamStudio's "Image Strength" slider. 671 |

672 | This parameter is just an alternate way to set `step_schedule_start`, which is done via the calculation `1 - image_strength`. For example, passing in an Image Strength of 35% (`0.35`) would result in a `step_schedule_start` of `0.65`. 673 | example: 0.4 674 | minimum: 0 675 | maximum: 1 676 | format: float 677 | default: 0.35 678 | InitImageMode: 679 | type: string 680 | description: Whether to use `image_strength` or `step_schedule_*` to control how much influence the `init_image` has on the result. 681 | enum: 682 | - IMAGE_STRENGTH 683 | - STEP_SCHEDULE 684 | default: IMAGE_STRENGTH 685 | StepScheduleStart: 686 | type: number 687 | description: Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of `0` would simply return you the init_image, where a value of `1` would return you a completely different image.) 688 | default: 0.65 689 | example: 0.4 690 | minimum: 0 691 | maximum: 1 692 | StepScheduleEnd: 693 | type: number 694 | description: Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. 695 | example: 0.01 696 | minimum: 0 697 | maximum: 1 698 | MaskImage: 699 | x-go-type: '[]byte' 700 | type: string 701 | description: 'Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the `init_image`. Use the `mask_source` option to specify whether the white or black pixels should be inpainted.' 702 | example: 703 | format: binary 704 | MaskSource: 705 | type: string 706 | description: |- 707 | For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from: 708 | - `MASK_IMAGE_WHITE` will use the white pixels of the mask_image as the mask, where white pixels are completely replaced and black pixels are unchanged 709 | - `MASK_IMAGE_BLACK` will use the black pixels of the mask_image as the mask, where black pixels are completely replaced and white pixels are unchanged 710 | - `INIT_IMAGE_ALPHA` will use the alpha channel of the init_image as the mask, where fully transparent pixels are completely replaced and fully opaque pixels are unchanged 711 | GenerationRequestOptionalParams: 712 | type: object 713 | description: Represents the optional parameters that can be passed to any generation request. 714 | properties: 715 | cfg_scale: 716 | $ref: '#/components/schemas/CfgScale' 717 | clip_guidance_preset: 718 | $ref: '#/components/schemas/ClipGuidancePreset' 719 | height: 720 | $ref: '#/components/schemas/Height' 721 | width: 722 | $ref: '#/components/schemas/Width' 723 | sampler: 724 | $ref: '#/components/schemas/Sampler' 725 | samples: 726 | $ref: '#/components/schemas/Samples' 727 | seed: 728 | $ref: '#/components/schemas/Seed' 729 | steps: 730 | $ref: '#/components/schemas/Steps' 731 | ImageToImageRequestBody: 732 | type: object 733 | properties: 734 | text_prompts: 735 | $ref: '#/components/schemas/TextPrompts' 736 | init_image: 737 | $ref: '#/components/schemas/InitImage' 738 | init_image_mode: 739 | $ref: '#/components/schemas/InitImageMode' 740 | image_strength: 741 | $ref: '#/components/schemas/InitImageStrength' 742 | step_schedule_start: 743 | $ref: '#/components/schemas/StepScheduleStart' 744 | step_schedule_end: 745 | $ref: '#/components/schemas/StepScheduleEnd' 746 | 747 | # Everything below was taken from OptionalGenerationRequestBody but due to a bug in the OpenAPI generator, we can't use allOf here 748 | cfg_scale: 749 | $ref: '#/components/schemas/CfgScale' 750 | clip_guidance_preset: 751 | $ref: '#/components/schemas/ClipGuidancePreset' 752 | height: 753 | $ref: '#/components/schemas/Height' 754 | width: 755 | $ref: '#/components/schemas/Width' 756 | sampler: 757 | $ref: '#/components/schemas/Sampler' 758 | samples: 759 | $ref: '#/components/schemas/Samples' 760 | seed: 761 | $ref: '#/components/schemas/Seed' 762 | steps: 763 | $ref: '#/components/schemas/Steps' 764 | required: 765 | - text_prompts 766 | - init_image 767 | discriminator: 768 | propertyName: init_image_mode 769 | mapping: 770 | IMAGE_STRENGTH: '#/components/schemas/ImageToImageUsingImageStrengthRequestBody' 771 | STEP_SCHEDULE: '#/components/schemas/ImageToImageUsingStepScheduleRequestBody' 772 | ImageToImageUsingImageStrengthRequestBody: 773 | allOf: 774 | - type: object 775 | properties: 776 | text_prompts: 777 | $ref: '#/components/schemas/TextPrompts' 778 | init_image: 779 | $ref: '#/components/schemas/InitImage' 780 | init_image_mode: 781 | $ref: '#/components/schemas/InitImageMode' 782 | image_strength: 783 | $ref: '#/components/schemas/InitImageStrength' 784 | required: 785 | - text_prompts 786 | - init_image 787 | - $ref: '#/components/schemas/GenerationRequestOptionalParams' 788 | ImageToImageUsingStepScheduleRequestBody: 789 | allOf: 790 | - type: object 791 | properties: 792 | text_prompts: 793 | $ref: '#/components/schemas/TextPrompts' 794 | init_image: 795 | $ref: '#/components/schemas/InitImage' 796 | init_image_mode: 797 | $ref: '#/components/schemas/InitImageMode' 798 | step_schedule_start: 799 | $ref: '#/components/schemas/StepScheduleStart' 800 | step_schedule_end: 801 | $ref: '#/components/schemas/StepScheduleEnd' 802 | required: 803 | - text_prompts 804 | - init_image 805 | - $ref: '#/components/schemas/GenerationRequestOptionalParams' 806 | MaskingRequestBody: 807 | type: object 808 | properties: 809 | init_image: 810 | $ref: '#/components/schemas/InitImage' 811 | mask_source: 812 | $ref: '#/components/schemas/MaskSource' 813 | mask_image: 814 | $ref: '#/components/schemas/MaskImage' 815 | 816 | # Everything below was taken from OptionalGenerationRequestBody but due to a bug in the OpenAPI generator, we can't use allOf here 817 | text_prompts: 818 | $ref: '#/components/schemas/TextPrompts' 819 | cfg_scale: 820 | $ref: '#/components/schemas/CfgScale' 821 | clip_guidance_preset: 822 | $ref: '#/components/schemas/ClipGuidancePreset' 823 | height: 824 | $ref: '#/components/schemas/Height' 825 | width: 826 | $ref: '#/components/schemas/Width' 827 | sampler: 828 | $ref: '#/components/schemas/Sampler' 829 | samples: 830 | $ref: '#/components/schemas/Samples' 831 | seed: 832 | $ref: '#/components/schemas/Seed' 833 | steps: 834 | $ref: '#/components/schemas/Steps' 835 | required: 836 | - text_prompts 837 | - init_image 838 | - mask_source 839 | discriminator: 840 | propertyName: mask_source 841 | mapping: 842 | MASK_IMAGE_BLACK: '#/components/schemas/MaskingUsingMaskImageRequestBody' 843 | MASK_IMAGE_WHITE: '#/components/schemas/MaskingUsingMaskImageRequestBody' 844 | INIT_IMAGE_ALPHA: '#/components/schemas/MaskingUsingInitImageAlphaRequestBody' 845 | 846 | MaskingUsingMaskImageRequestBody: 847 | allOf: 848 | - type: object 849 | properties: 850 | text_prompts: 851 | $ref: '#/components/schemas/TextPrompts' 852 | init_image: 853 | $ref: '#/components/schemas/InitImage' 854 | mask_source: 855 | $ref: '#/components/schemas/MaskSource' 856 | mask_image: 857 | $ref: '#/components/schemas/MaskImage' 858 | required: 859 | - init_image 860 | - mask_image 861 | - text_prompts 862 | - mask_source 863 | - $ref: '#/components/schemas/GenerationRequestOptionalParams' 864 | MaskingUsingInitImageAlphaRequestBody: 865 | allOf: 866 | - type: object 867 | properties: 868 | text_prompts: 869 | $ref: '#/components/schemas/TextPrompts' 870 | init_image: 871 | $ref: '#/components/schemas/InitImage' 872 | mask_source: 873 | $ref: '#/components/schemas/MaskSource' 874 | required: 875 | - init_image 876 | - text_prompts 877 | - mask_source 878 | - $ref: '#/components/schemas/GenerationRequestOptionalParams' 879 | 880 | TextToImageRequestBody: 881 | type: object 882 | allOf: 883 | - type: object 884 | properties: 885 | text_prompts: 886 | $ref: '#/components/schemas/TextPromptsForTextToImage' 887 | required: 888 | - text_prompts 889 | - $ref: '#/components/schemas/GenerationRequestOptionalParams' 890 | example: 891 | cfg_scale: 7 892 | clip_guidance_preset: FAST_BLUE 893 | height: 512 894 | sampler: K_DPM_2_ANCESTRAL 895 | samples: 1 896 | seed: 0 897 | steps: 75 898 | text_prompts: 899 | - text: A lighthouse on a cliff 900 | weight: 1 901 | width: 512 902 | required: 903 | - text_prompts 904 | AccountResponseBody: 905 | type: object 906 | properties: 907 | email: 908 | type: string 909 | description: The user's email 910 | example: example@stability.ai 911 | format: email 912 | id: 913 | type: string 914 | description: The user's ID 915 | example: user-1234 916 | x-go-name: ID 917 | organizations: 918 | type: array 919 | example: 920 | - id: org-5678 921 | name: Another Organization 922 | role: MEMBER 923 | is_default: true 924 | - id: org-1234 925 | name: My Organization 926 | role: MEMBER 927 | is_default: false 928 | items: 929 | $ref: '#/components/schemas/OrganizationMembership' 930 | description: The user's organizations 931 | profile_picture: 932 | type: string 933 | description: The user's profile picture 934 | example: https://api.stability.ai/example.png 935 | format: uri 936 | required: 937 | - id 938 | - email 939 | - organizations 940 | BalanceResponseBody: 941 | type: object 942 | properties: 943 | credits: 944 | type: number 945 | description: The balance of the account/organization associated with the API key 946 | example: 0.41122252265928866 947 | format: double 948 | example: 949 | credits: 0.07903292496944721 950 | required: 951 | - credits 952 | ListEnginesResponseBody: 953 | type: object 954 | properties: 955 | engines: 956 | type: array 957 | items: 958 | $ref: '#/components/schemas/Engine' 959 | description: The engines available to your user/organization 960 | example: 961 | engines: 962 | - description: Stability-AI Stable Diffusion v1.5 963 | id: stable-diffusion-v1-5 964 | name: Stable Diffusion v1.5 965 | type: PICTURE 966 | - description: Stability-AI Stable Diffusion v2.1 967 | id: stable-diffusion-512-v2-1 968 | name: Stable Diffusion v2.1 969 | type: PICTURE 970 | - description: Stability-AI Stable Diffusion 768 v2.1 971 | id: stable-diffusion-768-v2-1 972 | name: Stable Diffusion v2.1-768 973 | type: PICTURE 974 | required: 975 | - engines 976 | FinishReason: 977 | type: string 978 | description: |- 979 | The result of the generation process. 980 | - `SUCCESS` indicates success 981 | - `ERROR` indicates an error 982 | - `CONTENT_FILTERED` indicates the result affected by the content filter and may be blurred. 983 | 984 | This header is only present when the `Accept` is set to `image/png`. Otherwise it is returned in the response body. 985 | enum: 986 | - SUCCESS 987 | - ERROR 988 | - CONTENT_FILTERED 989 | Image: 990 | type: object 991 | properties: 992 | base64: 993 | type: string 994 | description: Image encoded in base64 995 | example: Sed corporis modi et. 996 | finishReason: 997 | type: string 998 | example: CONTENT_FILTERED 999 | enum: 1000 | - SUCCESS 1001 | - ERROR 1002 | - CONTENT_FILTERED 1003 | seed: 1004 | type: number 1005 | description: The seed associated with this image 1006 | example: 1229191277 1007 | example: 1008 | - base64: ...very long string... 1009 | finishReason: SUCCESS 1010 | seed: 1050625087 1011 | - base64: ...very long string... 1012 | finishReason: CONTENT_FILTERED 1013 | seed: 1229191277 1014 | OrganizationMembership: 1015 | type: object 1016 | properties: 1017 | id: 1018 | type: string 1019 | example: org-123456 1020 | x-go-name: ID 1021 | is_default: 1022 | type: boolean 1023 | example: false 1024 | name: 1025 | type: string 1026 | example: My Organization 1027 | role: 1028 | type: string 1029 | example: MEMBER 1030 | required: 1031 | - id 1032 | - name 1033 | - role 1034 | - is_default 1035 | responses: 1036 | 400FromGeneration: 1037 | description: |- 1038 | bad_request: general error for invalid parameters

1039 | 1040 |

More specific errors:

1041 | 1042 | - invalid_samples: Sample count may only be greater than 1 when the accept header is set to `application/json` 1043 | - invalid_height_or_width: Height and width must be specified in increments of 64 1044 | - invalid_file_size: The file size of one or more of the provided files is invalid 1045 | - invalid_mime_type: The mime type of one or more of the provided files is invalid 1046 | - invalid_image_dimensions: The dimensions of the provided `init_image` and `mask_image` do not match 1047 | - invalid_mask_image: The parameter `mask_source` was set to `MASK_IMAGE_WHITE` or `MASK_IMAGE_BLACK` but no `mask_image` was provided 1048 | - invalid_prompts: One or more of the prompts contains filtered words 1049 | - invalid_pixel_count: Incorrect number of pixels specified. Requirements: 1050 | - For 768 engines : 589,824 `height * width` 1,048,576 1051 | - All other engines: 262,144 `height * width` 1,048,576\n 1052 | content: 1053 | application/json: 1054 | schema: 1055 | $ref: '#/components/schemas/Error' 1056 | example: 1057 | id: 296a972f-666a-44a1-a3df-c9c28a1f56c0 1058 | name: bad_request 1059 | message: 'init_image: is required' 1060 | 401: 1061 | description: 'unauthorized: API key missing or invalid' 1062 | content: 1063 | application/json: 1064 | schema: 1065 | $ref: '#/components/schemas/Error' 1066 | example: 1067 | id: 9160aa70-222f-4a36-9eb7-475e2668362a 1068 | name: unauthorized 1069 | message: 'missing authorization header' 1070 | 403: 1071 | description: 'permission_denied: You lack the necessary permissions to perform this action' 1072 | content: 1073 | application/json: 1074 | schema: 1075 | $ref: '#/components/schemas/Error' 1076 | example: 1077 | id: 5cf19777-d17f-49fe-9bd9-39ff0ec6bb50 1078 | name: permission_denied 1079 | message: 'You do not have permission to access this resource' 1080 | 404: 1081 | description: 'not_found: The requested resource was not found (e.g. specifing a model that does not exist)' 1082 | content: 1083 | application/json: 1084 | schema: 1085 | $ref: '#/components/schemas/Error' 1086 | example: 1087 | id: 92b19e7f-22a2-4e71-a821-90edda229293 1088 | name: not_found 1089 | message: 'The specified engine (ID some-fake-engine) was not found.' 1090 | 500: 1091 | description: 'server_error: Some unexpected server error occurred' 1092 | content: 1093 | application/json: 1094 | schema: 1095 | $ref: '#/components/schemas/Error' 1096 | example: 1097 | id: f81964d6-619b-453e-97bc-9fd7ac3f04e7 1098 | name: server_error 1099 | message: 'An unexpected server error occurred, please try again.' 1100 | tags: 1101 | - name: v1beta/user 1102 | description: Manage your Stability.ai account, and view account/organization balances - deprecated, use v1/user instead 1103 | - name: v1beta/engines 1104 | description: Enumerate available engines - deprecated, use v1/engines instead 1105 | - name: v1beta/generation 1106 | description: Generate images from text, existing images, or both - deprecated, use v1/generation instead 1107 | --------------------------------------------------------------------------------