Generate Stunning Custom Images with expa-ai/cloudflare-hack Cognitive Actions

24 Apr 2025
Generate Stunning Custom Images with expa-ai/cloudflare-hack Cognitive Actions

In the realm of artificial intelligence, the ability to generate custom images based on text prompts has become a game-changer for developers and creators alike. The expa-ai/cloudflare-hack API provides powerful Cognitive Actions that allow you to create unique images tailored to your specifications. By leveraging these pre-built actions, you can save time and resources while enhancing the visual capabilities of your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and HTTP requests.

Authentication typically involves passing your API key in the headers of your requests, ensuring secure and authorized access to the API.

Cognitive Actions Overview

Generate Custom Images

The Generate Custom Images action allows developers to create custom images from text prompts while offering options for refinement, watermark application, and background branding. This action is categorized under image generation.

Input

The input schema for this action is detailed below, showcasing required and optional parameters:

{
  "image": "https://replicate.delivery/pbxt/KtyErKSr4GYg3VUiPO3cEgsjJLxDUIsPORgit8VA2XJMmomV/Image%20%2810%29.jpeg",
  "width": 1080,
  "height": 1280,
  "prompt": "30 year old woman, tousled pixie cut with long side fringe, silver-grey hair, blue-green eyes, delicate features, fair skin with freckles, warm smile, fuzzy light pink sweater, blurred pastel background, natural window lighting, ultra hd portrait photo, carefree feminine style",
  "refine": "base_image_refiner",
  "scheduler": "K_EULER",
  "applyWatermark": false,
  "negativePrompt": "low quality, jpeg artifacts, blurry ,poorly drawn, ugly, worst quality, face asymmetry, eyes asymmetry, deformed eyes, open mouth, octane render, render, drawing, anime, bad photo, bad photography, worst quality, low quality, blurry, bad teeth, deformed teeth, deformed lips, bad anatomy, bad proportions, deformed iris, deformed pupils, deformed eyes, bad eyes, deformed face, ugly face, bad face, deformed hands, bad hands, fused fingers, morbid, mutilated, mutation, disfigured",
  "guidanceScaling": 7.5,
  "numberOfOutputs": 1,
  "refinementSteps": 10,
  "applyBrandBackground": true,
  "numberOfInferenceSteps": 30
}
  • Required Fields:
    • image: URI of the input image.
    • prompt: Text prompt guiding the image generation.
    • width and height: Dimensions of the output image.
  • Optional Fields:
    • seed: Random seed for reproducibility.
    • refine: Style for image refinement (default is no_refiner).
    • scheduler: Algorithm for scheduling denoising steps.
    • applyWatermark: Boolean to indicate watermark application.
    • negativePrompt: Text to specify undesirable image features.
    • guidanceScaling: Scale for classifier-free guidance.
    • numberOfOutputs: How many images to generate (1 to 4).
    • refinementSteps: Steps for refining the image.
    • applyBrandBackground: Boolean to apply a brand background.
    • numberOfInferenceSteps: Steps to denoise the image.

Output

Upon successful execution, the action returns an array of image URLs. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/919385d4-44b3-42b6-aff4-fba9dd79b553/9c24e237-1600-4f16-9106-722711d5f4ff.jpeg"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to invoke the Generate Custom Images 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 = "db74e28c-d379-4df0-9ffc-cafe1936b698"  # Action ID for Generate Custom Images

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/KtyErKSr4GYg3VUiPO3cEgsjJLxDUIsPORgit8VA2XJMmomV/Image%20%2810%29.jpeg",
    "width": 1080,
    "height": 1280,
    "prompt": "30 year old woman, tousled pixie cut with long side fringe, silver-grey hair, blue-green eyes, delicate features, fair skin with freckles, warm smile, fuzzy light pink sweater, blurred pastel background, natural window lighting, ultra hd portrait photo, carefree feminine style",
    "refine": "base_image_refiner",
    "scheduler": "K_EULER",
    "applyWatermark": False,
    "negativePrompt": "low quality, jpeg artifacts, blurry ,poorly drawn, ugly, worst quality, face asymmetry...",
    "guidanceScaling": 7.5,
    "numberOfOutputs": 1,
    "refinementSteps": 10,
    "applyBrandBackground": True,
    "numberOfInferenceSteps": 30
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and ensure the URL points to the correct endpoint. The input payload is structured according to the action's requirements, demonstrating how to utilize the various options available.

Conclusion

The Generate Custom Images action from the expa-ai/cloudflare-hack API opens up a world of possibilities for developers looking to integrate image generation capabilities into their applications. By leveraging the flexibility of the input parameters, you can create tailored images that fit your project's needs. Start experimenting with these Cognitive Actions today and unlock new creative potential in your applications!