Enhance Your Applications with Image Generation: Integrating zaktechgis/flux-pro-16 Cognitive Actions

24 Apr 2025
Enhance Your Applications with Image Generation: Integrating zaktechgis/flux-pro-16 Cognitive Actions

In the rapidly evolving world of application development, integrating advanced image generation capabilities can significantly enhance user experiences. The zaktechgis/flux-pro-16 API offers a powerful Cognitive Action called Generate Inpainted Image, which utilizes the fine-tuned FLUX.1 model to create stunning images with inpainting capabilities. This action not only optimizes for speed and quality but also allows for customizable dimensions, making it extremely versatile for various applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and Python programming.
  • Familiarity with making HTTP requests to RESTful APIs.

Authentication is typically handled by including your API key in the request headers, ensuring secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action is designed to create images based on specified prompts and options. It allows users to perform inpainting, where they can fill in missing parts of an image or alter existing sections creatively.

Category: Image Generation

Input

This action accepts a variety of parameters encapsulated within a JSON object. Below are the key fields you can provide:

  • prompt (required): A text prompt guiding the image generation.
  • mask: URI of an image mask for inpainting mode.
  • image: URI of an input image for image modification.
  • model: Choose between "dev" or "schnell" for inference.
  • width: Specifies the width of the output image.
  • height: Specifies the height of the output image.
  • goFast: Boolean to enable speed optimization.
  • numOutputs: Number of images to generate (1 to 4).
  • guidanceScale: Controls the diffusion guidance scale.
  • outputQuality: Image quality from 0 to 100.
  • imageAspectRatio: Selects the aspect ratio of the output image.
  • imageOutputFormat: Format for the output image (webp, jpg, png).

Example Input:

{
  "model": "dev",
  "prompt": "portrait  proffessionel",
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "mainLoraScale": 1,
  "outputQuality": 90,
  "inferenceSteps": 28,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1,
  "imagePromptStrength": 0.8
}

Output

The output of the action typically consists of a URI pointing to the generated image. Here's an example of what you might receive:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/b856c83f-b008-4b1b-89dd-53d938829f23/06bdee8a-c24d-40e9-a13e-65d41993029f.webp"
]

Conceptual Usage Example (Python)

To call the Generate Inpainted Image action, you can use the following Python code snippet. This example illustrates how to structure the input payload and make a request to the hypothetical Cognitive Actions execution endpoint.

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 = "e58d9cd3-e9d4-4414-bac9-434f4dd37ef5" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "portrait  proffessionel",
    "numOutputs": 1,
    "guidanceScale": 3.5,
    "mainLoraScale": 1,
    "outputQuality": 90,
    "inferenceSteps": 28,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "additionalLoraScale": 1,
    "imagePromptStrength": 0.8
}

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 placeholder for your API key and ensure the action ID corresponds to the Generate Inpainted Image action. The input JSON is structured according to the action's requirements, and the endpoint URL is illustrative.

Conclusion

The Generate Inpainted Image action from the zaktechgis/flux-pro-16 API provides developers with a straightforward way to enhance their applications with sophisticated image generation capabilities. By leveraging this action, you can create rich visual content tailored to your users' needs.

Explore further by experimenting with different parameters, and consider how this powerful image generation tool can elevate your projects to the next level!