Generate Stunning Images with the PlanetNesa Cognitive Actions

22 Apr 2025
Generate Stunning Images with the PlanetNesa Cognitive Actions

In the realm of image generation, the PlanetNesa Cognitive Actions provide a powerful API for developers looking to create and customize images using advanced inpainting techniques. This spec is designed to harness the capabilities of image synthesis, enabling users to generate images based on textual prompts while offering a variety of adjustable parameters for fine-tuning the output. By leveraging these pre-built actions, developers can streamline the image creation process and focus on building innovative applications.

Prerequisites

Before integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Familiarity with making HTTP requests to API endpoints.
  • Basic understanding of JSON structure for input and output data.

Authentication typically involves passing your API key in the request headers, ensuring that only authorized users can access the service.

Cognitive Actions Overview

Generate Image Using Inpainting

The Generate Image Using Inpainting action allows developers to create images based on user-defined prompts, utilizing sophisticated inpainting techniques. This action supports various parameters to customize the output, including aspect ratio, resolution, and image format.

Input

The input for this action is structured as follows:

{
  "prompt": "alien outer space hues of green matrix like space",
  "modelType": "dev",
  "outputCount": 4,
  "loraIntensity": 1,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "webp",
  "extraLoraIntensity": 1,
  "imageOutputQuality": 90,
  "imagePromptStrength": 0.58,
  "inferenceStepsCount": 44,
  "diffusionGuidanceScale": 3.5
}

Required Fields:

  • prompt: A text string that describes what the image should depict.

Optional Fields:

  • modelType: Specifies the model for inference (dev or schnell).
  • outputCount: Number of images to generate (1-4).
  • loraIntensity: Strength of the main LoRA application.
  • imageAspectRatio: Aspect ratio of the generated image.
  • imageOutputFormat: Desired output image format (e.g., webp, jpg, png).
  • Other parameters for fine-tuning image quality and generation speed.

Output

The output of this action will typically return an array of URLs pointing to the generated images, such as:

[
  "https://assets.cognitiveactions.com/invocations/8127f63a-47f8-4096-af17-951c89e3be10/9bb81bc1-827f-4be3-859b-d1367a5e6cab.webp",
  "https://assets.cognitiveactions.com/invocations/8127f63a-47f8-4096-af17-951c89e3be10/21a46fcd-15e2-4afc-b65d-0023c4a13b50.webp",
  "https://assets.cognitiveactions.com/invocations/8127f63a-47f8-4096-af17-951c89e3be10/1636d52f-75af-43c9-8f36-d3ad6de6a040.webp",
  "https://assets.cognitiveactions.com/invocations/8127f63a-47f8-4096-af17-951c89e3be10/5e304364-1de2-4883-a1e2-9cf8a97b0542.webp"
]

Conceptual Usage Example (Python)

Below is a conceptual example of how to invoke the Generate Image Using Inpainting 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 = "6c94099c-01d4-4a87-b813-fc7bb14b9a5a" # Action ID for Generate Image Using Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "alien outer space hues of green matrix like space",
    "modelType": "dev",
    "outputCount": 4,
    "loraIntensity": 1,
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "webp",
    "extraLoraIntensity": 1,
    "imageOutputQuality": 90,
    "imagePromptStrength": 0.58,
    "inferenceStepsCount": 44,
    "diffusionGuidanceScale": 3.5
}

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, the action ID and input payload are structured according to the requirements of the Generate Image Using Inpainting action. The endpoint URL and request structure are illustrative and may vary in your application.

Conclusion

The PlanetNesa Cognitive Actions empower developers to generate stunning images with customizable parameters, enhancing creativity and productivity in image synthesis. By utilizing the Generate Image Using Inpainting action, you can easily integrate advanced image generation capabilities into your applications. Explore various use cases, experiment with different parameters, and unlock the full potential of image creation!