Generate Customized Images with the Geradon/Moi Cognitive Actions

23 Apr 2025
Generate Customized Images with the Geradon/Moi Cognitive Actions

In the world of image generation, the ability to create customized and high-quality images on demand can be a game changer for developers. The Geradon/Moi spec provides a powerful Cognitive Action designed specifically for this purpose. The Generate Customized Image action allows developers to generate images using specified models, including options for image inpainting, resolution, and various settings that cater to diverse use cases. By leveraging these pre-built actions, developers can save time while enhancing the capabilities of their applications.

Prerequisites

To get started with the Geradon/Moi Cognitive Actions, you'll need to ensure you have the following:

  • API Key: Obtain an API key from the Cognitive Actions platform.
  • Setup: Familiarize yourself with how to structure API calls, particularly how to include your API key for authentication. Typically, the API key is passed in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Customized Image

The Generate Customized Image action enables users to create images based on a descriptive prompt. It supports image inpainting, allows for adjustments to resolution, aspect ratio, and LoRA intensity settings, and offers both fast and high-quality generation modes.

Input: The required and optional fields for this action are defined in the schema below:

{
  "prompt": "An image of LEMPIKA, a bald man",
  "goFast": false,
  "loraScale": 1,
  "megapixels": "1",
  "imageFormat": "webp",
  "imageQuality": 80,
  "denoisingSteps": 28,
  "inferenceModel": "dev",
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "imageAspectRatio": "1:1",
  "diffusionGuidance": 3,
  "secondaryLoraIntensity": 1
}

Output: Upon a successful call, the action returns a URL to the generated image:

[
  "https://assets.cognitiveactions.com/invocations/f84ed8e0-a706-4cbd-8040-a797bfceba7f/b4f43ecc-df99-430d-ae55-f08e1785e2d9.webp"
]

This output provides a direct link to the newly created image, which can be used in various applications or displayed to end-users.

Conceptual Usage Example (Python):

Below is a conceptual example of how to invoke the Generate Customized Image 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 = "162c1138-d763-4202-b1b1-ccdde9cf3e7a"  # Action ID for Generate Customized Image

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "An image of LEMPIKA, a bald man",
    "loraScale": 1,
    "megapixels": "1",
    "imageFormat": "webp",
    "imageQuality": 80,
    "denoisingSteps": 28,
    "inferenceModel": "dev",
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "imageAspectRatio": "1:1",
    "diffusionGuidance": 3,
    "secondaryLoraIntensity": 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, you'll notice how the action ID and input payload are structured for the API request. It’s crucial to adjust the COGNITIVE_ACTIONS_API_KEY and the endpoint URL to match your credentials and setup.

Conclusion

The Generate Customized Image action from the Geradon/Moi spec is a powerful tool for developers looking to integrate image generation capabilities into their applications. By utilizing this action, you can create customized images tailored to specific prompts, enhancing user experience and expanding functionality.

As you explore this action further, consider experimenting with various prompt details, image formats, and quality settings to see how they impact the generated images. Happy coding!