Generate Stunning Images with Inpainting: A Developer's Guide to bethanywork/joshfancy Cognitive Actions

24 Apr 2025
Generate Stunning Images with Inpainting: A Developer's Guide to bethanywork/joshfancy Cognitive Actions

In today's fast-paced digital landscape, the ability to generate high-quality images programmatically has become an essential skill for developers. The bethanywork/joshfancy API offers powerful Cognitive Actions that leverage advanced inpainting techniques to create stunning images from textual prompts. This guide will walk you through the key capabilities of the "Generate Image with Inpainting" action and how to integrate it into your applications seamlessly.

Prerequisites

To get started with the Cognitive Actions in the bethanywork/joshfancy API, you'll need:

  • An API key for the Cognitive Actions platform to authenticate your requests. This key will be passed in the headers of your API calls.
  • Basic knowledge of JSON structures and Python programming for crafting your requests.

Cognitive Actions Overview

Generate Image with Inpainting

Description: This action allows you to generate high-quality images using inpainting techniques. You can customize aspects like image masking, aspect ratio, and even toggle a fast mode for quicker results. The action supports two models: 'dev' for detailed generation and 'schnell' for rapid inference.

Category: Image Generation

Input

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

  • prompt (required): A text prompt that guides the image generation.
  • mask (optional): A URI for an image mask used in inpainting mode.
  • image (optional): A URI for an input image to modify or use inpainting.
  • model (optional): The model to use for inference, defaults to "dev".
  • width (optional) and height (optional): Dimensions for the generated image, applicable only when 'aspect_ratio' is set to 'custom'.
  • goFast (optional): Enables a faster prediction mode.
  • numberOfOutputs (optional): Specifies how many output images to generate.
  • imageAspectRatio (optional): Defines the aspect ratio of the generated image.
  • imageOutputFormat (optional): Format of the output images (e.g., webp, jpg, png).
  • imageGuidanceScale (optional): Adjusts the guidance scale for the diffusion process.
  • imageOutputQuality (optional): Specifies image quality ranging from 0 to 100.

Example Input:

{
  "model": "dev",
  "prompt": "a photo of JOSHFANCY, a man scowling as a waiter spills food on him at a restaurant.",
  "loraScale": 1,
  "numberOfOutputs": 1,
  "imageAspectRatio": "4:3",
  "imageOutputFormat": "webp",
  "imageGuidanceScale": 3.5,
  "imageOutputQuality": 90,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28,
  "inputPromptStrength": 0.8
}

Output

The action typically returns a JSON array containing the URIs of generated images. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/7e399741-b5a6-4a4f-a1c0-e7e5dfeb6842/3fa0c91a-96e1-476c-a32a-21190af7fd58.webp"
]

Conceptual Usage Example (Python)

Here’s how you can call the Generate Image with Inpainting 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 = "fa032ddd-cf34-4740-a7c5-27ce2f124bba" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "a photo of JOSHFANCY, a man scowling as a waiter spills food on him at a restaurant.",
    "loraScale": 1,
    "numberOfOutputs": 1,
    "imageAspectRatio": "4:3",
    "imageOutputFormat": "webp",
    "imageGuidanceScale": 3.5,
    "imageOutputQuality": 90,
    "additionalLoraScale": 1,
    "inferenceStepsCount": 28,
    "inputPromptStrength": 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 example:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action ID and input payload are structured correctly to invoke the action.

Conclusion

The Generate Image with Inpainting action in the bethanywork/joshfancy API provides developers with an incredibly powerful tool for creating high-quality images from text prompts. With its customizable options, you can generate unique visuals tailored to your needs. Whether you're building an application that requires dynamic image generation or enhancing media content, the Cognitive Actions offered in this spec can significantly elevate your project's capabilities.

Explore the possibilities and get started with your image generation journey today!