Generate Stunning Images with the Steven-Altitude/Toniflux Cognitive Actions

24 Apr 2025
Generate Stunning Images with the Steven-Altitude/Toniflux Cognitive Actions

The Steven-Altitude/Toniflux API provides developers with powerful Cognitive Actions for generating high-quality images. With capabilities like inpainting, aspect ratio customization, and multiple output formats, these actions streamline the image creation process. This blog post will guide you through the "Generate and Inpaint Image" action, detailing its functionality, input requirements, and how to implement it in your applications.

Prerequisites

To get started with the Cognitive Actions, you'll need an API key from the Toniflux platform. This key should be passed in the HTTP headers when making requests. Ensure you have the necessary setup to authenticate your requests.

Cognitive Actions Overview

Generate and Inpaint Image

The Generate and Inpaint Image action allows you to create detailed images based on a prompt while providing options for inpainting existing images. You can customize the aspect ratio, choose different output formats, and select between high-quality or speed-optimized image generation models.

Input

The input for this action is structured as a JSON object. Here's a breakdown of the required and optional fields:

  • Required:
    • prompt: A detailed description of what you want the generated image to depict.
  • Optional:
    • mask: (URI) An image mask to specify areas for inpainting.
    • seed: (Integer) For reproducible results, set a random seed.
    • image: (URI) An input image for image-to-image transformation or inpainting.
    • model: (String) Select "dev" for high detail or "schnell" for speed.
    • width: (Integer) Define the width of the generated image.
    • height: (Integer) Define the height of the generated image.
    • goFast: (Boolean) Enable faster predictions with a speed-optimized model.
    • imageFormat: (String) Choose the output format ('webp', 'jpg', 'png').
    • outputCount: (Integer) Specify how many images to generate (1 to 4).
    • imageQuality: (Integer) Set the quality of the output images (0 to 100).
    • modelWeights: (String) Load LoRA weights from specific URLs.
    • loraIntensity: (Number) Control the strength of the LoRA application.
    • Other optional fields include additionalLora, denoisingSteps, imageResolution, and more.

Here is an example input JSON payload:

{
  "model": "dev",
  "goFast": false,
  "prompt": "A high-resolution, romantic product photograph of LECHETONI, a premium semi-skimmed milk in a red and white carton, elegantly placed on a beautifully set Valentine's Day table.",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 80,
  "loraIntensity": 1,
  "denoisingSteps": 28,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "diffusionGuidance": 3,
  "directiveIntensity": 0.8,
  "additionalLoraIntensity": 1
}

Output

The output of the action will typically return a URL pointing to the generated image. Here’s an example of what the output might look like:

[
  "https://assets.cognitiveactions.com/invocations/2bf56aa3-515e-406d-b5c7-b6e84858a786/2c287895-e842-4ea2-b034-a7d1f7d75480.webp"
]

Conceptual Usage Example (Python)

Here's a conceptual example of how to invoke the Generate and Inpaint Image 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 = "7ba709ee-0191-4e43-abd4-e271b3f2b5ab" # Action ID for Generate and Inpaint Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "A high-resolution, romantic product photograph of LECHETONI, a premium semi-skimmed milk in a red and white carton, elegantly placed on a beautifully set Valentine's Day table.",
    "imageFormat": "webp",
    "outputCount": 1,
    "imageQuality": 80,
    "loraIntensity": 1,
    "denoisingSteps": 28,
    "imageResolution": "1",
    "imageAspectRatio": "1:1",
    "diffusionGuidance": 3,
    "directiveIntensity": 0.8,
    "additionalLoraIntensity": 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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the action's requirements, including the prompt for the image generation.

Conclusion

The Steven-Altitude/Toniflux Cognitive Actions offer powerful tools for image generation and inpainting, making it easier for developers to create stunning visuals tailored to their needs. By following the guidelines in this post, you can effectively integrate these actions into your applications. Explore other potential use cases, such as creating marketing materials or enhancing creative projects, to fully leverage the capabilities of this API. Happy coding!