Transform Your Images with the asronline/sdxl-mk1-stages Cognitive Actions

21 Apr 2025
Transform Your Images with the asronline/sdxl-mk1-stages Cognitive Actions

In the digital age, the ability to generate and modify images with precision is invaluable. The asronline/sdxl-mk1-stages API offers powerful Cognitive Actions that allow developers to create stunning images using advanced techniques. With capabilities like inpainting and customizable image generation parameters, these pre-built actions simplify the integration of image processing features into your applications. Let’s dive into how you can harness the potential of these actions.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of making HTTP requests and handling JSON data.

Authentication can typically be achieved by including your API key in the request headers.

Cognitive Actions Overview

Generate Inpainted Images

This action allows you to create inpainted images using specified text prompts and adjustable parameters. You can define image dimensions, utilize seed values for deterministic outputs, and apply refinement techniques. It also supports input masks to preserve or modify specific areas of an image.

Input

The input for this action is structured as follows:

{
  "mask": "uri_to_mask_image", // Optional
  "seed": 12345, // Optional
  "image": "uri_to_input_image", // Required
  "width": 1920, // Optional, default is 1024
  "height": 1080, // Optional, default is 1024
  "prompt": "In the style of MK1, a Shaolin temple, with beautiful trees and lanterns", // Required
  "loraScale": 0.6, // Optional, default is 0.6
  "numOutputs": 1, // Optional, default is 1
  "refineSteps": 10, // Optional
  "refineStyle": "no_refiner", // Optional, default is "no_refiner"
  "guidanceScale": 7.5, // Optional, default is 7.5
  "applyWatermark": true, // Optional, default is true
  "negativePrompt": "", // Optional
  "promptStrength": 0.8, // Optional, default is 0.8
  "schedulingMethod": "K_EULER", // Optional, default is "K_EULER"
  "highNoiseFraction": 0.8, // Optional, default is 0.8
  "numInferenceSteps": 50, // Optional, default is 50
  "alternativeWeights": "uri_to_alternative_weights", // Optional
  "disableSafetyChecker": false // Optional, default is false
}

Example Input:

{
  "width": 1920,
  "height": 1080,
  "prompt": "In the style of MK1, a Shaolin temple, with beautiful trees and lanterns",
  "loraScale": 0.6,
  "numOutputs": 1,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "numInferenceSteps": 50
}

Output

Upon successful execution, the action returns a URL linking to the generated inpainted image:

[
  "https://assets.cognitiveactions.com/invocations/bc88471d-684e-41f5-ba31-4e17aca81e3c/5d0c5ee5-f0f5-42b3-9fea-e8aedbe7088c.png"
]

Conceptual Usage Example (Python)

Here’s how you might structure your Python code to call this action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "fa32e178-b065-4896-bec7-a82a97ffe8e7" # Action ID for Generate Inpainted Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 1920,
    "height": 1080,
    "prompt": "In the style of MK1, a Shaolin temple, with beautiful trees and lanterns",
    "loraScale": 0.6,
    "numOutputs": 1,
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "schedulingMethod": "K_EULER",
    "highNoiseFraction": 0.8,
    "numInferenceSteps": 50
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, you initialize the necessary parameters and construct the payload based on the action's requirements. The action ID and input payload are critical for executing the inpainting process.

Conclusion

The Generate Inpainted Images action from the asronline/sdxl-mk1-stages API provides a robust way to create and manipulate images directly from your applications. With customizable parameters and straightforward integration, developers can easily implement creative image generation features. Whether you're enhancing existing images or creating new artistic visuals, these Cognitive Actions empower you to bring your ideas to life. Explore further to discover how you can leverage these capabilities in your projects!