Enhance Your Creativity with Fooocus API Image Generation

26 Apr 2025
Enhance Your Creativity with Fooocus API Image Generation

The Fooocus API provides developers with a powerful toolset for generating and refining images using various techniques, including text prompts, image variations, and advanced inpainting/outpainting methods. By leveraging the capabilities of the Fooocus API, you can create stunning visuals that meet specific requirements, making it ideal for applications in gaming, advertising, content creation, and more. With features that allow for multiple styles and refining methods, the API simplifies the image generation process, enabling you to focus on your creative vision rather than the technical intricacies.

Imagine being able to generate a high-quality image based on a simple text prompt or refining an existing image to enhance its visual appeal. This functionality can dramatically speed up workflows for designers, artists, and developers who need to produce custom graphics quickly and efficiently. Whether you're looking to create unique art pieces, design marketing materials, or enhance user interfaces, the Fooocus API offers the flexibility and performance you need.

Generate and Refine Images with Fooocus

The "Generate and Refine Images with Fooocus" action allows you to create and enhance images based on textual descriptions and existing visuals. This action addresses the need for high-quality, customized imagery that can be tailored to specific use cases.

Input Requirements

To successfully utilize this action, you need to provide a variety of inputs:

  • prompt: A string describing the desired image (e.g., "forest elf").
  • imageSeed: An integer that acts as a seed for random image generation, or set to -1 for random generation.
  • sharpness: A number that adjusts the sharpness level of the generated image, with valid values ranging from 0 to 30.
  • imageNumber: An integer specifying how many images to generate (from 1 to 8).
  • guidanceScale: A number controlling how closely the generated image adheres to the prompt, with acceptable values from 1 to 30.
  • refinerSwitch: A number indicating the degree of refinement applied to the image, ranging from 0.1 to 1.
  • Additional parameters include negativePrompt, controlNetTypes, performanceMode, styleSelections, and more, which can be tailored to refine the output further.

Expected Output

The output will be a URL pointing to the generated image that matches the specifications provided in the input. For example, a successful response might yield:

  • "https://assets.cognitiveactions.com/invocations/407cd81e-bda1-41eb-9bbe-afa4d3d5c48a/5e66fd06-ac11-4d63-abc5-de1d5bebd7a5.png"

Use Cases for this Action

This action is particularly useful in various scenarios:

  • Content Creation: Quickly generate unique images for blog posts, social media, or marketing campaigns.
  • Game Development: Create character designs, backgrounds, or concept art based on narrative elements.
  • Advertising: Produce tailored visuals that resonate with specific target audiences or campaigns.
  • Artistic Exploration: Experiment with different styles and prompts to produce original artwork for portfolios or exhibitions.

By using the Fooocus API, developers can enhance their projects with visually compelling images that are generated and refined to meet precise needs.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "ae76520f-fe78-4d4c-b14c-17b9d557ad58" # Action ID for: Generate and Refine Images with Fooocus

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "forest elf",
  "imageSeed": 50403806253646856,
  "sharpness": 2,
  "imageNumber": 1,
  "guidanceScale": 4,
  "refinerSwitch": 0.5,
  "negativePrompt": "",
  "controlNetType1": "ImagePrompt",
  "controlNetType2": "ImagePrompt",
  "controlNetType3": "ImagePrompt",
  "controlNetType4": "ImagePrompt",
  "performanceMode": "Speed",
  "styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
  "aspectRatioSetting": "1152*896",
  "outpaintSelections": "",
  "outpaintDistanceTop": 0,
  "outpaintDistanceLeft": 0,
  "outpaintDistanceRight": 0,
  "outpaintDistanceBottom": 0,
  "inpaintAdditionalPrompt": "",
  "upscaleOrVariationMethod": "Disabled",
  "upscaleOrVariationUpscaleValue": 0
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Fooocus API offers a robust solution for image generation and refinement, enabling developers to produce high-quality visuals tailored to their specific needs. With its diverse input options and flexible output capabilities, this API can significantly enhance creative workflows across multiple domains.

To get started, ensure you have your Cognitive Actions API key and familiarize yourself with the API call structure. Explore the different parameters and experiment with various prompts to unlock the full potential of your creative projects. Whether you're looking to generate art for personal use or professional applications, the Fooocus API is a powerful ally in your creative journey.