Enhance Your Applications with the markots/nad Cognitive Actions for Image Generation

24 Apr 2025
Enhance Your Applications with the markots/nad Cognitive Actions for Image Generation

In the realm of AI-driven creativity, the markots/nad specification offers a powerful set of Cognitive Actions that allow developers to generate images with remarkable precision and customization. One of the standout capabilities within this spec is the ability to perform inpainting—an essential feature for applications that require image modification or enhancement. By leveraging these pre-built actions, developers can integrate advanced image generation functionalities into their applications seamlessly.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform. This key will be required to authenticate your requests.
  • Familiarity with making HTTP requests in your chosen programming language (we'll provide a Python example).

To authenticate your calls, you will typically pass your API key in the request headers.

Cognitive Actions Overview

Generate Inpainting Image

The Generate Inpainting Image action is designed to create images by utilizing inpainting capabilities. This action allows users to specify various parameters, enabling a high degree of customization for the output images.

  • Category: Image Generation

Input

The input for this action is structured as follows:

{
  "prompt": "Original MONAD logo with shape and color intact, set in a futuristic cityscape",
  "model": "dev",
  "goFast": false,
  "loraScale": 1,
  "megapixels": "1",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "promptStrength": 0.8,
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

Required Fields:

  • prompt: The textual description that guides the image generation.

Optional Fields:

  • mask: URI for an image mask (overrides dimensions).
  • seed: Integer for reproducible results.
  • image: Input image for inpainting.
  • model: Select between dev and schnell.
  • width, height: Dimensions of the generated image (only if aspect ratio is custom).
  • goFast: Boolean to enable faster predictions.
  • aspectRatio: Set the aspect ratio for the output image.
  • outputFormat: Specify format as webp, jpg, or png.
  • And many more for further customization.

Output

The action returns a list of image URLs as output. For example:

[
  "https://assets.cognitiveactions.com/invocations/923d781f-0383-4c02-a208-7728d2fc15e4/04ad3f63-4f1f-468b-b509-9654d1f0bd94.webp"
]

This output contains the generated image's URL, which can be used directly in applications.

Conceptual Usage Example (Python)

Here’s how a developer might invoke this action using a hypothetical Cognitive Actions API endpoint:

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 = "1ae96ec8-f20e-432a-9f3a-ed126c4f0352"  # Action ID for Generate Inpainting Image

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Original MONAD logo with shape and color intact, set in a futuristic cityscape",
    "model": "dev",
    "goFast": False,
    "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 code snippet, developers will replace YOUR_COGNITIVE_ACTIONS_API_KEY with their actual API key. The payload is constructed based on the required and optional fields for the action, ensuring that the input JSON is structured correctly. The endpoint URL and request structure are illustrative and should be adapted to the actual API specifications.

Conclusion

The markots/nad Cognitive Actions provide developers with a robust toolkit for integrating advanced image generation capabilities into their applications. By leveraging the Generate Inpainting Image action, you can create visually stunning and customized images tailored to your specific needs. Next steps could involve experimenting with different prompts, models, and parameters to unlock the full potential of these Cognitive Actions in your projects. Happy coding!