Create Stunning Images with the Cybertruck Cognitive Actions

22 Apr 2025
Create Stunning Images with the Cybertruck Cognitive Actions

In the world of artificial intelligence, image generation has opened up endless possibilities for creativity and design. The hudsongraeme/cybertruck API offers a powerful Cognitive Action that allows developers to generate Cybertruck-inspired images using the SDXL model. This action provides a range of customizable parameters, making it easy to create unique visuals tailored to your specific needs. Let’s dive into the details of this action and how you can integrate it into your applications.

Prerequisites

To use the Cognitive Actions offered by the Cybertruck API, you will need:

  • An API key for authentication. This key should be included in the request headers to ensure secure access to the service.
  • Basic knowledge of JSON and Python programming to construct the request payload and handle responses.

Cognitive Actions Overview

Generate Cybertruck-Inspired Image

The Generate Cybertruck-Inspired Image action allows you to create images based on a textual prompt. Its flexibility in parameters enables you to fine-tune the output, including dimensions, guidance, and refinement styles.

Input: The input schema consists of various fields that you can customize:

  • seed (integer): Specifies the random seed for reproducibility. Leave blank for a random seed.
  • width (integer): Width of the output image in pixels (default: 1024).
  • height (integer): Height of the output image in pixels (default: 1024).
  • prompt (string): The text prompt for generating the image (default: "An astronaut riding a rainbow unicorn").
  • inputMask (string, URI): URI of the input mask for inpaint mode.
  • loraScale (number): LoRA additive scaling factor (default: 0.6).
  • scheduler (string): Scheduling algorithm (default: "K_EULER").
  • inputImage (string, URI): Input image for img2img or inpaint mode.
  • loraWeights (string): Specifies the LoRA weights (optional).
  • refineStyle (string): Determines the refinement style (default: "no_refiner").
  • guidanceScale (number): Classifier-free guidance scale (default: 7.5).
  • applyWatermark (boolean): Whether to apply a watermark (default: true).
  • promptStrength (number): Defines prompt strength for img2img or inpaint mode (default: 0.8).
  • numberOfOutputs (integer): Specifies the number of images to generate (default: 1, max: 4).
  • refinementSteps (integer): Number of steps for refinement (optional).
  • highNoiseFraction (number): Fraction of high noise used (default: 0.8).
  • inputNegativePrompt (string): Specifies aspects to avoid (optional).
  • numberOfInferenceSteps (integer): Number of denoising steps (default: 50).
  • disableImageSafetyChecker (boolean): Allows disabling the safety checker (default: false).

Example Input: Here is an example JSON payload to invoke the action:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A photo of TOK drifting",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "highNoiseFraction": 0.8,
  "inputNegativePrompt": "",
  "numberOfInferenceSteps": 50
}

Output: Upon successful execution, the action returns an array of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/aac62aba-ec3d-462a-b464-ffc9028cbe0f/5d4e3db0-e15e-4e1a-a7b0-f3b6fdb91cff.png",
  "https://assets.cognitiveactions.com/invocations/aac62aba-ec3d-462a-b464-ffc9028cbe0f/2e00a004-c4c1-4d3c-8dcd-dd93cfb7087e.png",
  "https://assets.cognitiveactions.com/invocations/aac62aba-ec3d-462a-b464-ffc9028cbe0f/1ab4a86d-0831-493d-9c2c-b8af25ac0cef.png",
  "https://assets.cognitiveactions.com/invocations/aac62aba-ec3d-462a-b464-ffc9028cbe0f/f5af2f4d-be45-4182-9652-cae033e4c8b6.png"
]

Conceptual Usage Example (Python):

To illustrate how to call this action, here’s a conceptual Python code snippet:

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 = "41a07c3c-ea88-44a3-a9ed-0a9e96da0ed6"  # Action ID for Generate Cybertruck-Inspired Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A photo of TOK drifting",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "highNoiseFraction": 0.8,
    "inputNegativePrompt": "",
    "numberOfInferenceSteps": 50
}

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 COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. The payload is structured to meet the action's requirements, ensuring you customize it according to your needs.

Conclusion

The Cybertruck Cognitive Actions enable developers to easily generate unique images based on customizable prompts. By leveraging the parameters available, you can create diverse visual content that meets your project's requirements. Explore the potential of image generation in your applications, and consider integrating this action for innovative solutions. Happy coding!