Generate Stunning Images with the Efratai Cognitive Actions

21 Apr 2025
Generate Stunning Images with the Efratai Cognitive Actions

In the world of AI-driven creativity, the Efratai Cognitive Actions provide a powerful toolset for developers looking to generate images tailored to specific parameters. These pre-built actions allow you to create visuals with remarkable detail by leveraging advanced models and customizable settings. Whether you need fast results or intricate designs, integrating these actions into your applications can significantly enhance user experiences and streamline workflows.

Prerequisites

Before diving into the integration of Efratai Cognitive Actions, make sure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with making HTTP requests in your programming language of choice.
  • Basic understanding of JSON format for structuring your requests.

Authentication typically involves passing your API key in the headers of your requests, ensuring secure access to the actions.

Cognitive Actions Overview

Generate Image with Custom Parameters

This action generates images using a variety of input parameters, including image masks, dimensions, and text prompts. It supports different models for detailed or fast image generation, allowing for versatility in output quality and speed.

Input

The input for this action is structured as follows:

{
  "prompt": "efratai woman looking to the camera",
  "goFast": false,
  "outputCount": 1,
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1
}

The required fields include:

  • prompt: The text prompt that guides the image generation.

Optional fields provide flexibility in customization:

  • mask: URI for image mask used in inpainting.
  • seed: For reproducible results.
  • width and height: To specify dimensions.
  • goFast: For optimized speed.
  • outputCount: How many images to generate (1-4).
  • guidanceScale: To influence image realism (0-10).
  • inferenceModel: Choose between 'dev' and 'schnell'.

Output

When the action is executed successfully, it returns a link to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/24b75f21-65f7-4cde-939f-8ed5251b0a11/30bcd1c2-c8a5-4df1-b3a5-3ea3733d92e7.webp"
]

This URL points to the image generated based on the provided parameters.

Conceptual Usage Example (Python)

Here’s how you can call this 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 = "2d258367-0645-48bd-bf8c-0e15b64770e2" # Action ID for Generate Image with Custom Parameters

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "efratai woman looking to the camera",
    "goFast": False,
    "outputCount": 1,
    "guidanceScale": 3,
    "mainLoraScale": 1,
    "outputQuality": 80,
    "inferenceModel": "dev",
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "webp",
    "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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed based on the action's required and optional parameters, ensuring the right format for the request.

Conclusion

The Efratai Cognitive Actions provide developers with a robust framework for generating customized images effortlessly. By leveraging the flexibility of various parameters and models, you can create stunning visuals tailored to your application's needs. Start integrating these actions today and explore the endless possibilities they offer for your projects!