Create Stunning Custom Images with the Image Generation API

10 May 2025
Create Stunning Custom Images with the Image Generation API

In today's digital landscape, visual content is more important than ever. The Image Generation and Prediction API provides developers with the ability to create high-quality, customized images tailored to specific artistic needs. This powerful tool leverages advanced models and techniques to transform simple prompts into vivid, detailed visuals, enabling applications across various industries. Whether you're designing a game character, generating artwork for marketing, or simply exploring your creative ideas, this API simplifies the process of image creation and prediction, saving time and enhancing your projects' quality.

Prerequisites

Before diving into the API, ensure you have a valid Cognitive Actions API key and a basic understanding of how to make API calls.

Generate Scene Hair Image

The Generate Scene Hair Image action allows you to create a customized and high-definition image featuring a character styled in the 'SceneKid' aesthetic. By utilizing advanced LoRA models and image-to-image inpainting techniques, this action can produce visually striking images that cater to specific artistic requirements.

Input Requirements: To use this action, you'll need to provide a text prompt that guides the image generation. Additionally, you can specify parameters such as image dimensions, aspect ratio, output format, and more. Here’s a brief overview of the required inputs:

  • Prompt: A descriptive text that outlines the characteristics of the image you want to generate.
  • Width and Height: Dimensions of the generated image (if aspect ratio is custom).
  • Aspect Ratio: The desired aspect ratio for the output image.
  • Output Format: Choose from formats like webp, jpg, or png.
  • Go Fast: An optional flag to enable faster predictions.

Expected Output: This action will return one or more high-definition images based on your specifications. For instance, you might receive URLs linking to the generated images in the chosen format.

Use Cases for this specific action:

  • Game Development: Create unique character designs that resonate with specific themes or aesthetics.
  • Graphic Design: Generate custom illustrations for marketing materials, social media, or websites.
  • Art Projects: Explore creative ideas by generating visuals that match your artistic vision without the need for advanced design skills.
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 = "9bcc0b3e-d55b-46d8-a2af-ede3e1efd329" # Action ID for: Generate Scene Hair Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 727,
  "goFast": true,
  "height": 1374,
  "prompt": "SceneKid, petite, ashen-skinned, innocent, 18yo, 1girl, short crop top, daisy dukes, blue eyes, flawless skin, high definition",
  "loraScale": 1,
  "aspectRatio": "9:16",
  "outputFormat": "png",
  "guidanceScale": 2.21,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numberOfOutputs": 4,
  "numberOfInferenceSteps": 33
}

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 Image Generation and Prediction API empowers developers to create stunning, customized images with ease. By harnessing advanced technology, you can streamline your creative processes, enhance visual content, and bring your imaginative ideas to life. Whether you’re in gaming, marketing, or any other creative field, this API opens up a world of possibilities for generating unique imagery. Start integrating this powerful tool today and elevate your projects with high-quality visuals!