Enhance Your Applications with Image Generation Using timho1047/design-generation-1-flux Actions

23 Apr 2025
Enhance Your Applications with Image Generation Using timho1047/design-generation-1-flux Actions

In the rapidly evolving world of artificial intelligence, the ability to generate images programmatically can transform applications across various industries. The timho1047/design-generation-1-flux API offers a powerful Cognitive Action that allows developers to generate images with customizable settings. This capability not only enhances creativity but also provides flexibility for diverse use cases—from artistic design to product visualization.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Basic knowledge of JSON and Python to structure your requests and handle responses.
  • Familiarity with HTTP requests will be helpful, as you will be sending requests to an API endpoint.

Authentication typically involves passing your API key in the request headers for each call you make.

Cognitive Actions Overview

Generate Image with Customizable Settings

Description: This action generates images based on user-defined settings using various models and parameters, including image-to-image and inpainting modes. It offers features such as aspect ratio control, prompt intensity adjustments, and fast mode optimization for quicker predictions.

Category: Image Generation

Input

The input for this action requires a JSON object with the following schema:

{
  "prompt": "string (required)",
  "model": "string (default: 'dev')",
  "width": "integer (optional, between 256 and 1440)",
  "height": "integer (optional, between 256 and 1440)",
  "image": "string (optional, format: uri)",
  "mask": "string (optional, format: uri)",
  "goFast": "boolean (default: false)",
  "outputCount": "integer (default: 1, between 1 and 4)",
  "imageQuality": "integer (default: 80, between 0 and 100)",
  "guidanceScale": "number (default: 3, between 0 and 10)",
  "promptStrength": "number (default: 0.8, between 0 and 1)",
  "imageAspectRatio": "string (default: '1:1')",
  "imageOutputFormat": "string (default: 'webp')",
  "inferenceStepsCount": "integer (default: 28, between 1 and 50)"
}

Example Input:

{
  "model": "dev",
  "width": 1024,
  "height": 1024,
  "prompt": "In GARPRORD style. A pair of blue leggings. White background.",
  "loraScale": 1,
  "outputCount": 3,
  "imageQuality": 90,
  "guidanceScale": 3.5,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "jpg",
  "inferenceStepsCount": 28
}

Output

The action will return an array of URLs pointing to the generated images. Here’s an example of a successful output:

[
  "https://assets.cognitiveactions.com/invocations/01093d3a-e87e-4e93-8523-6a005c96f325/648758c9-c473-4b19-a016-64f9a471d464.jpg",
  "https://assets.cognitiveactions.com/invocations/01093d3a-e87e-4e93-8523-6a005c96f325/2eb80b7c-265d-4afa-b683-0dc90c4796cd.jpg",
  "https://assets.cognitiveactions.com/invocations/01093d3a-e87e-4e93-8523-6a005c96f325/011046c5-3baa-43f3-9dbc-bf1bbd6690da.jpg"
]

Conceptual Usage Example (Python)

Here is a conceptual Python snippet to demonstrate how to call the Generate Image with Customizable Settings action:

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 = "ad2048cb-0282-48e9-ad77-3c8c432c4c46" # Action ID for Generate Image with Customizable Settings

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 1024,
    "height": 1024,
    "prompt": "In GARPRORD style. A pair of blue leggings. White background.",
    "outputCount": 3,
    "imageQuality": 90,
    "guidanceScale": 3.5,
    "promptStrength": 0.8,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "jpg",
    "inferenceStepsCount": 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, replace the COGNITIVE_ACTIONS_API_KEY and endpoint URL with your actual key and endpoint. The action ID is set for the Generate Image with Customizable Settings, and the input payload is structured according to the action's requirements.

Conclusion

The timho1047/design-generation-1-flux Cognitive Action provides a versatile tool for developers looking to integrate image generation capabilities into their applications. By leveraging customizable settings, you can produce high-quality images that meet specific requirements, enhancing the user experience in your projects.

Consider exploring further use cases, such as integrating this action with design tools or developing creative applications that require dynamic image content. The possibilities are endless!