Enhance Image Creation with the kevsjh/ink-sdxl Cognitive Actions

24 Apr 2025
Enhance Image Creation with the kevsjh/ink-sdxl Cognitive Actions

In the world of digital creativity, the kevsjh/ink-sdxl API elevates image generation capabilities through its powerful Cognitive Actions. Among these, the Generate Image with Inpainting action stands out by allowing developers to create stunning images with enhanced features like inpainting, guided prompts, and more. This article will walk you through the capabilities of this action and how to integrate it into your applications seamlessly.

Prerequisites

Before diving into the use of the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and RESTful API concepts.
  • A programming environment set up with Python and the requests library for making API calls.

Authentication typically involves passing your API key in the request headers to access the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action utilizes the Ink SDXL model to create images with the ability to inpaint areas based on user-defined masks. This action supports img2img transformations and includes various parameters for customization, such as guidance scales and scheduler algorithms. Key features include the ability to apply masks for inpainting, use text prompts for image direction, and watermark generated content for verification.

Input

This action requires a structured input payload with the following fields:

  • mask (string, optional): URI of the input mask used in inpaint mode.
  • seed (integer, optional): Random seed for generating images.
  • image (string, optional): URI of the input image for img2img or inpaint mode processing.
  • width (integer, default: 1024): Width of the output image in pixels.
  • height (integer, default: 1024): Height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): The text prompt guiding the image generation.
  • refine (string, default: "no_refiner"): Technique for refinement.
  • loraScale (number, default: 0.6): Scale factor for the LoRA additive.
  • scheduler (string, default: "K_EULER"): Strategy for scheduling denoising steps.
  • guidanceScale (number, default: 7.5): Scale for classifier-free guidance.
  • applyWatermark (boolean, default: true): Whether to apply a watermark.
  • negativePrompt (string, optional): Influences generation away from certain themes.
  • promptStrength (number, default: 0.8): Strength of the input prompt.
  • numberOfOutputs (integer, default: 1): Number of images to output.
  • highNoiseFraction (number, default: 0.8): Fraction of noise for refining.
  • numberOfInferenceSteps (integer, default: 50): Steps for denoising during inference.
Example Input
{
  "width": 1024,
  "height": 1024,
  "prompt": "astronaut riding a horse, INKSDXL,",
  "refine": "no_refiner",
  "loraScale": 0.8,
  "scheduler": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

Output

Upon successful execution, this action returns an array containing the URIs of the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/d174f984-d2dc-441a-8af2-2b42f5d3636f/48f542d1-ac3e-421a-a67e-acab30e0deb8.png"
]

Conceptual Usage Example (Python)

Here's how you might call the Generate Image with Inpainting action using Python:

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 = "d548ae23-0cd7-4964-93b2-8f001d40a10d" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "astronaut riding a horse, INKSDXL,",
    "refine": "no_refiner",
    "loraScale": 0.8,
    "scheduler": "K_EULER",
    "guidanceScale": 7.5,
    "applyWatermark": true,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "numberOfInferenceSteps": 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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured to match the required input schema for the action. The hypothetical endpoint and request structure exemplify how to integrate the action into your application.

Conclusion

The Generate Image with Inpainting action from the kevsjh/ink-sdxl API provides developers with powerful tools for creating and refining images through AI. With its rich feature set, you can take your image generation projects to the next level. Now that you understand how to use this action, consider exploring other potential use cases, such as integrating it into creative applications, enhancing graphic design workflows, or automating content generation for various media. Happy coding!