Generate Stunning Images with the lukevink/dto Cognitive Action

24 Apr 2025
Generate Stunning Images with the lukevink/dto Cognitive Action

In the realm of artificial intelligence, image generation has made substantial strides, enabling developers to create stunning visuals with minimal effort. The lukevink/dto Cognitive Actions provide a powerful API for generating high-resolution images based on specified prompts. This blog post will guide you through the capabilities of these actions, showcasing how to leverage them to enrich your applications.

Prerequisites

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

  • API Key: You will need an API key to access the Cognitive Actions platform. This key should be included in the request headers for authentication.
  • Setup: Familiarity with making HTTP requests and handling JSON payloads will be beneficial.

Authentication is typically achieved by passing your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate AI Image

The Generate AI Image action creates high-resolution images based on a specified prompt and various adjustable parameters. This action falls under the image-generation category and supports features such as reproducibility through a seed and the ability to specify negative prompting to avoid undesired content.

Input

The input schema for this action is structured as follows:

  • seed (optional): An integer used to initialize the random number generator for reproducibility. If left blank, a random seed will be used.
  • width: Specifies the output image width (choices: 128, 256, 512, 768, 1024; default: 512).
  • height: Specifies the output image height (choices: 128, 256, 512, 768, 1024; default: 512).
  • prompt: A string that describes the desired content of the generated image (default: "a cjw cat in a bucket").
  • guidanceScale: A numerical value (1 to 20) that influences how closely the output adheres to the prompt (default: 7.5).
  • negativePrompt (optional): A string specifying content to avoid during generation.
  • numberOfOutputs: The number of images to generate (choices: 1, 4; default: 1).
  • numberOfInferenceSteps: Total denoising steps (1 to 500; default: 50).

Example Input:

{
  "width": 512,
  "height": 512,
  "prompt": "photograph of a beautiful woman wearing a DTo dress standing in the himalayas, half body, ((perfect face)), ((detailed face)), hyperrealism, hd quality, vogue, 8k resolution, Canon Eos 5D",
  "guidanceScale": 7.5,
  "negativePrompt": "(((painting))), (((ugly))), (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), ((long neck)))",
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

The output of this action is a URL pointing to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/7d636b6e-a47b-4ba8-aacd-7a5d2d36c780/c6ab43c2-6be5-4baf-bd99-a735865e14d9.png"
]

Conceptual Usage Example (Python)

Here’s how you can integrate the Generate AI Image action into your Python application:

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 = "adb43504-ad56-4434-963f-b221fc053671" # Action ID for Generate AI Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "photograph of a beautiful woman wearing a DTo dress standing in the himalayas, half body, ((perfect face)), ((detailed face)), hyperrealism, hd quality, vogue, 8k resolution, Canon Eos 5D",
    "guidanceScale": 7.5,
    "negativePrompt": "(((painting))), (((ugly))), (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), ((long neck)))",
    "numberOfOutputs": 1,
    "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 example, you can see how to construct the input payload based on the action's requirements. The action ID and payload are provided directly in the request body, which allows you to generate stunning images easily.

Conclusion

The Generate AI Image action from the lukevink/dto Cognitive Actions opens a world of possibilities for developers looking to create visually appealing content dynamically. By harnessing the power of AI, you can generate high-quality images tailored to your specifications. Explore this action further and consider integrating it into your next project to enhance user experience and engagement!