Generate Stunning Images with the Konstantin Image Cognitive Actions

23 Apr 2025
Generate Stunning Images with the Konstantin Image Cognitive Actions

In the realm of AI-driven creativity, the Konstantin Image Cognitive Actions provide developers with powerful tools to generate and manipulate images intelligently. These pre-built actions allow you to create stunning visuals tailored to your specifications, making it easier than ever to integrate advanced image generation capabilities into your applications.

Prerequisites

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

  • API Key: To access the Cognitive Actions platform, you will need an API key for authentication. This key should be included in the headers of your API requests.
  • Basic Understanding of JSON: Familiarity with JSON will help you structure the input and handle the output effectively.

The authentication typically involves passing the API key in the request headers, ensuring secure access to the actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create an image using specified parameters, including an image mask, dimensions, quality levels, and stylistic guidance. This action supports various models and optimizations for rapid generation.

Input

The input for this action is structured as follows:

{
  "prompt": "Your descriptive text here",
  "mask": "http://example.com/mask.png",
  "image": "http://example.com/input_image.png",
  "model": "dev",
  "width": 512,
  "height": 512,
  "goFast": false,
  "seed": 12345,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "numOutputs": 1,
  "numInferenceSteps": 28,
  "megapixels": "1"
}

Here’s a practical example of a JSON payload:

{
  "model": "dev",
  "goFast": false,
  "prompt": "Konstantin LinkedIn Profile Picture in black t-shirt and very photo realistic",
  "loraScale": 1,
  "megapixels": "1",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "promptStrength": 0.8,
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

Output

Upon successful execution, the action returns a URL pointing to the generated image. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/424ae5f9-6e41-438a-afce-73fe3efa0c10/8ec2cf80-596d-4657-8eaf-2a4a63cf3f36.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call this 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 = "d833f1be-b1ce-4e99-a0e4-5edeca68870b"  # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
  "model": "dev",
  "goFast": False,
  "prompt": "Konstantin LinkedIn Profile Picture in black t-shirt and very photo realistic",
  "loraScale": 1,
  "megapixels": "1",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "promptStrength": 0.8,
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

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 example, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured based on the action's requirements, ensuring the request is properly formatted for the Cognitive Actions API.

Conclusion

The Konstantin Image Cognitive Actions open up a world of possibilities for developers looking to incorporate advanced image generation features into their applications. By leveraging these pre-built actions, you can create customized images that meet your specific needs quickly and efficiently.

Explore these capabilities further and consider various use cases, such as generating marketing materials, personalizing content, or enhancing user experiences with custom visuals. Happy coding!