Harnessing Image Generation with the kazdatahelp/azhrq Cognitive Actions

25 Apr 2025
Harnessing Image Generation with the kazdatahelp/azhrq Cognitive Actions

In the ever-evolving landscape of artificial intelligence, the ability to generate images based on text prompts has unlocked new creative possibilities. The kazdatahelp/azhrq spec provides a powerful Cognitive Action that enables developers to leverage sophisticated image generation techniques through its Generate Image with Inpainting action. This action utilizes advanced models to create high-quality images, offering a range of customizable parameters to fine-tune the output. In this article, we'll explore how to effectively integrate this action into your applications.

Prerequisites

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

  • API Key: You will need an API key for the Cognitive Actions platform. This key is essential for authenticating your requests.
  • Setup: Familiarize yourself with how to pass the API key in the headers of your requests.

Conceptually, you will use your API key as a Bearer token in the authorization header of your HTTP requests.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create high-quality images by utilizing image inpainting techniques. Through the selection of different models and adjustable parameters, developers can influence the image's aspect ratio, quality, and other dynamics.

Input

The input schema for this action requires a prompt, with various optional fields available for further customization. Below is an example of the expected input:

{
  "model": "dev",
  "prompt": "a photo of AZHRQ as a woman doctor in central hospital ",
  "loraStrength": 1,
  "guidanceScale": 3.5,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "imageAspectRatio": "4:5",
  "imageOutputFormat": "png",
  "imageOutputQuality": 90,
  "additionalLoraStrength": 1
}

Key properties include:

  • prompt (string, required): Describes the desired image content.
  • model (string, optional): Specifies the model for inference, with options such as 'dev' or 'schnell'.
  • numberOfOutputs (integer, optional): Defines how many images to generate (up to 4).
  • imageOutputFormat (string, optional): Chooses the format of the output image (e.g., png, jpg).

Output

The action returns a URL pointing to the generated image. Here’s an example of a successful output:

[
  "https://assets.cognitiveactions.com/invocations/3b8d6166-3bce-4e92-a882-db824c807646/0d318c30-0a08-428c-807a-5bda8bdbb204.png"
]

This URL can be used to access the generated image directly.

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet illustrating how to call the Generate Image with Inpainting action. This example focuses on structuring the input JSON payload correctly:

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 = "95c478a0-8808-4ce0-8d3d-21274f88dedb"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "a photo of AZHRQ as a woman doctor in central hospital ",
    "loraStrength": 1,
    "guidanceScale": 3.5,
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "imageAspectRatio": "4:5",
    "imageOutputFormat": "png",
    "imageOutputQuality": 90,
    "additionalLoraStrength": 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 code snippet:

  • Replace the placeholder for the API key with your actual key.
  • The payload is structured according to the action's input schema.
  • The response is handled to check for successful execution.

Conclusion

The Generate Image with Inpainting action from the kazdatahelp/azhrq spec provides a robust solution for developers looking to integrate image generation capabilities into their applications. By customizing parameters such as model selection, output format, and quality settings, you can create stunning images tailored to your needs. As you explore this action further, consider experimenting with different prompts and settings to unlock its full potential. Happy coding!