Elevate Your Applications with Image Generation Using prunaai/flux.1-cheetah Actions

22 Apr 2025
Elevate Your Applications with Image Generation Using prunaai/flux.1-cheetah Actions

In the rapidly evolving landscape of AI, integrating image generation capabilities into your applications can enhance user experience and engagement. The prunaai/flux.1-cheetah spec offers a powerful Cognitive Action that allows developers to generate images from descriptive text prompts. This article will explore how to effectively use the "Generate Image from Prompt" action, detailing its inputs, outputs, and providing a conceptual Python code example to help you get started.

Prerequisites

Before diving into the integration, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic familiarity with JSON structures and Python programming.
  • Understanding of how to make HTTP requests.

Authentication typically involves passing your API key in the request headers, ensuring secure access to the Cognitive Actions services.

Cognitive Actions Overview

Generate Image from Prompt

Description: This action enables you to generate an image based on a descriptive text prompt. You can customize various parameters including speed, guidance level, image size, and output format, making it a versatile tool for creating tailored visuals.

  • Category: Image Generation

Input

The input for this action is defined by the following schema:

{
  "seed": 0,
  "prompt": "black forest gateau cake spelling out the words \"FLUX DEV\", tasty, food photography, dynamic shot",
  "goFaster": true,
  "guidance": 3.5,
  "imageSize": 1024,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "outputQuality": 80,
  "goFastAtFullSpeed": false,
  "numInferenceSteps": 28
}
  • Required Fields:
    • prompt: A descriptive string that guides the image generation process.
  • Optional Fields:
    • seed: Integer for random number generation (default is -1).
    • goFaster: Boolean to prioritize speed over precision (default is false).
    • guidance: Float to balance creativity and adherence to the prompt (default is 7.5).
    • imageSize: Integer for the size of the longest side of the output image in pixels (default is 1024).
    • aspectRatio: String to define the aspect ratio (default is "1:1").
    • outputFormat: String for the image format, options include 'png', 'jpg', 'webp' (default is 'png').
    • outputQuality: Integer for image quality, applicable to 'jpg' and 'webp' formats (default is 80).
    • goFastAtFullSpeed: Boolean to maximize processing speed without compromise (default is false).
    • numInferenceSteps: Integer for the number of inference steps (default is 28).

Output

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

https://assets.cognitiveactions.com/invocations/f39b117b-d4ed-4e60-b8de-bbce2fb11355/02575322-84d1-4f61-b259-8c7d5a3799b8.webp

This URL points to the generated image, which can be used directly in your applications.

Conceptual Usage Example (Python)

Here’s how you might call the "Generate Image from Prompt" action using Python. Remember, the endpoint URL and request structure are illustrative:

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 = "36a2614f-a817-4a50-aeff-eaf553b4068d"  # Action ID for Generate Image from Prompt

# Construct the input payload based on the action's requirements
payload = {
    "seed": 0,
    "prompt": "black forest gateau cake spelling out the words \"FLUX DEV\", tasty, food photography, dynamic shot",
    "goFaster": True,
    "guidance": 3.5,
    "imageSize": 1024,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "outputQuality": 80,
    "goFastAtFullSpeed": False,
    "numInferenceSteps": 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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The payload is constructed using the example input schema, ensuring all required fields are included.
  • The response is handled to check for success and print the resulting image URL.

Conclusion

The prunaai/flux.1-cheetah Cognitive Action for generating images from prompts opens up exciting possibilities for developers looking to enhance their applications with visual content. By leveraging the customizable parameters, you can create unique images tailored to your users' needs. Explore this action further and consider how it can fit into your projects to create engaging and dynamic experiences!