Unlocking Image Generation: A Developer's Guide to the Hadasadler/Hertai Cognitive Actions

24 Apr 2025
Unlocking Image Generation: A Developer's Guide to the Hadasadler/Hertai Cognitive Actions

In the world of image processing and generation, the Hadasadler/Hertai API offers powerful Cognitive Actions that enable developers to create stunning visuals with ease. Among these capabilities is the ability to generate inpainting images, allowing for creative and customizable outputs. This blog post will guide you through the integration of these actions into your applications, providing a clear understanding of their functionalities and how to use them effectively.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic understanding of JSON and how to make HTTP requests in your preferred programming language.

For authentication, you will typically pass your API key in the headers of your requests in the following manner:

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

Cognitive Actions Overview

Generate Inpainting Images

The Generate Inpainting Images action is designed to create inpainting images with various customizable options. Developers can specify dimensions, quality, and model settings, making it highly versatile for different use cases in image generation.

  • Category: Image Generation
  • Description: Generate inpainting images with customizable dimensions, quality, and model settings. Supports various image input modes for optimized processing speed and output quality.

Input

The input schema for this action requires the following:

  • Required:
    • prompt: A text prompt dictating the generated image content. Example: "\n hertai A man with a long beard face to the the camera and talking to the audience"
  • Optional:
    • mask: URI of the image mask for inpainting mode.
    • seed: Seed for reproducibility.
    • image: URI of the input image for transformation.
    • width: Custom width (256-1440).
    • height: Custom height (256-1440).
    • loraScale: Intensity of the main LoRA application (default: 1).
    • megapixels: Estimated number of megapixels for optimization (default: "1").
    • aspectRatio: Aspect ratio setting (default: "1:1").
    • outputFormat: Defines the image file format (default: "webp").
    • guidanceScale: Influences the diffusion process (default: 3).
    • outputQuality: Image quality setting (default: 80).
    • additionalLora: Apply additional LoRA weights.
    • inferenceModel: Select the inference model (default: "dev").
    • promptStrength: Sets the prompt intensity (default: 0.8).
    • numberOfOutputs: Specifies how many variations to generate (default: 1).
    • additionalLoraScale: Sets the intensity for additional LoRA application (default: 1).
    • bypassSafetyChecker: Toggle to bypass the safety checker (default: false).
    • acceleratedInference: Enable a speed-optimized model (default: false).
    • numberOfInferenceSteps: Number of denoising steps (default: 28).

Example Input:

{
  "prompt": "\n hertai  A man with a long beard face to the the camera and talking to the audience",
  "loraScale": 1,
  "megapixels": "1",
  "aspectRatio": "16:9",
  "outputFormat": "jpg",
  "guidanceScale": 3,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "additionalLoraScale": 1,
  "acceleratedInference": false,
  "numberOfInferenceSteps": 28
}

Output

The output of this action typically returns a list of URLs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/d5a91d06-8f57-4c90-a31f-1263bd645b5b/6b7d8bb7-089b-448f-938f-c5d7adfb0b71.jpg"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to invoke the Generate Inpainting Images 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 = "9676f511-7ec7-4c7b-ac87-3fdfb709f16f" # Action ID for Generate Inpainting Images

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "\n hertai  A man with a long beard face to the the camera and talking to the audience",
    "loraScale": 1,
    "megapixels": "1",
    "aspectRatio": "16:9",
    "outputFormat": "jpg",
    "guidanceScale": 3,
    "outputQuality": 80,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "additionalLoraScale": 1,
    "acceleratedInference": false,
    "numberOfInferenceSteps": 28
}

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 the placeholder for the API key and action ID accordingly. The input payload is structured to meet the action's requirements, and the specified endpoint is illustrative, focusing on how to format your request.

Conclusion

The Hadasadler/Hertai Cognitive Actions empower developers to generate high-quality images with customizable settings. By leveraging the Generate Inpainting Images action, you can create tailored visuals that meet your specific needs. Explore these capabilities in your projects, and consider experimenting with different parameters to achieve desired results. Happy coding!