Generate Stunning Images with FLUX 1.1 Pro Cognitive Actions

In the realm of AI-driven creativity, the black-forest-labs/flux-1.1-pro API stands out with its impressive ability to generate high-quality images from text prompts. The Cognitive Actions offered by this API provide developers with powerful, pre-built functionalities that simplify the process of image generation. With features like faster generation times, enhanced image quality, and the ability to customize image aspects, integrating these actions into your applications can elevate user experiences and open up new creative possibilities.
Prerequisites
Before you start utilizing the FLUX 1.1 Pro Cognitive Actions, ensure you have the following:
- API Key: You will need an API key from the Cognitive Actions platform to authenticate your requests.
- Basic Setup: Familiarity with making HTTP requests and handling JSON payloads in your programming environment.
To authenticate, you will typically pass your API key in the headers of your requests.
Cognitive Actions Overview
Generate Image with FLUX 1.1 Pro
The Generate Image with FLUX 1.1 Pro action allows you to create diverse and high-quality images based on textual prompts. This action is ideal for developers looking to implement visual content generation in their applications. Key features include custom aspect ratios, various output formats, and safety tolerances, ensuring that the generated images meet your specific requirements.
Input
The input schema for this action requires the following fields:
- prompt (required): The text input that drives the image generation.
- seed (optional): An integer to ensure consistent image generation across requests.
- aspectRatio (optional): Defines the width-to-height ratio of the generated image (default is
1:1). - imageWidth (optional): Width in pixels (256 to 1440) when aspectRatio is set to
custom. - imageHeight (optional): Height in pixels (256 to 1440) when aspectRatio is set to
custom. - imageFormat (optional): Format of the output images (default is
webp). - imageQuality (optional): Quality level (0 to 100, default is 80).
- referenceImage (optional): A URI to an image that influences the composition.
- safetyTolerance (optional): Strength of content filtering (default is 2).
- promptUpsampling (optional): Enhances the creativity of the prompt during generation (default is false).
Example Input:
{
"prompt": "black forest gateau cake spelling out the words \"FLUX 1 . 1 Pro\", tasty, food photography",
"aspectRatio": "1:1",
"imageFormat": "webp",
"imageQuality": 80,
"safetyTolerance": 2,
"promptUpsampling": true
}
Output
The typical output from this action will be a URL pointing to the generated image. Here’s what you might expect:
Example Output:
https://assets.cognitiveactions.com/invocations/5a06a2c1-64b3-46b3-b8ef-2dad3795085a/4b5e3205-d366-45a4-b6b9-0e0be25ec6aa.webp
Conceptual Usage Example (Python)
Here's how you might call the Generate Image with FLUX 1.1 Pro action using Python. This snippet demonstrates the structure of the request:
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 = "f8d8cdb0-7fd6-4eb5-bcee-48a94ddd18bb" # Action ID for Generate Image with FLUX 1.1 Pro
# Construct the input payload based on the action's requirements
payload = {
"prompt": "black forest gateau cake spelling out the words \"FLUX 1 . 1 Pro\", tasty, food photography",
"aspectRatio": "1:1",
"imageFormat": "webp",
"imageQuality": 80,
"safetyTolerance": 2,
"promptUpsampling": True
}
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, replace the placeholders with your actual API key and ensure you call the appropriate endpoint. The payload variable is structured according to the action's input schema, enabling you to generate images based on your text prompts.
Conclusion
The FLUX 1.1 Pro Cognitive Actions offer developers a robust and flexible way to generate stunning images from textual prompts. With the ability to customize various parameters such as aspect ratio, image quality, and format, you can create tailored visual content that meets your application's needs. As you explore the potential of these actions, consider how they can enhance user engagement and creativity in your projects. Happy coding!