Generate Stunning Custom Images with Loyote/Tomtepojke Cognitive Actions

23 Apr 2025
Generate Stunning Custom Images with Loyote/Tomtepojke Cognitive Actions

In the realm of digital creativity, the Loyote/Tomtepojke Cognitive Actions offer developers a powerful API to generate custom images. These actions leverage advanced image generation models, enabling users to create visually appealing content with ease. From transforming existing images to creating completely new visuals based on detailed prompts, these capabilities unlock endless possibilities for developers looking to integrate image generation into their applications.

Prerequisites

To begin utilizing the Loyote/Tomtepojke Cognitive Actions, you'll need to ensure a few prerequisites are in place:

  • API Key: Access to the Cognitive Actions platform typically requires an API key for authentication. This key should be included in the request headers to authenticate your requests.
  • Basic Knowledge of JSON: Familiarity with JSON format will help you structure your requests correctly.

Authentication is generally handled by passing your API key in the headers of your requests, ensuring secure and authorized access to the Cognitive Actions.

Cognitive Actions Overview

Generate Custom Images

The Generate Custom Images action allows you to create custom images using the 'dev' or 'schnell' models. This action supports a variety of features like image-to-image transformation, inpainting, and several customizable parameters.

Purpose

This action is designed to generate images based on textual prompts, with options for controlling image quality, aspect ratio, and more. It’s particularly useful for developers looking to automate the creation of illustrations or visual content from descriptions.

Input

The input schema for generating custom images is as follows:

  • Required Fields:
    • prompt (string): The descriptive text that guides the image generation.
  • Optional Fields:
    • mask (string): URI for an image mask used in inpainting mode.
    • seed (integer): A random seed for reproducibility.
    • image (string): URI for an input image if using image-to-image transformation.
    • model (string): Choose between "dev" or "schnell" (default is "dev").
    • width (integer): Width of the generated image (if aspect ratio is custom).
    • height (integer): Height of the generated image (if aspect ratio is custom).
    • aspectRatio (string): Aspect ratio for the generated image.
    • outputFormat (string): Specify the format of the output image (webp, jpg, png).
    • guidanceScale (number): Scale for the diffusion process.
    • outputQuality (integer): Quality of the output images (0-100).
    • ...and several others for fine-tuning.

Example Input:

{
  "model": "dev",
  "prompt": "Tomtepojke, a small figurine boy, walks down a narrow dirt path surrounded by a mix of pine and leafy trees. The figurine gnome boy has round cheeks, a red mittens, and a simple gray outfit, giving him an earthy, handcrafted appearance. Behind him, the cabin glows with warm light...",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "outputFormat": "jpg",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 28
}

Output

Upon successful execution, the action returns a URL to the generated image. The output is typically structured as an array of URLs pointing to the created image files.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/4bef12eb-6b3f-4511-92ac-3acab35776b8/0249cb33-80c3-4712-9b4c-5c053f112f98.jpg"
]

Conceptual Usage Example (Python)

Here's how you might call the Generate Custom Images action using a hypothetical endpoint in 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 = "7f68d8fb-3bd5-4888-8ba9-d463214ec3e9" # Action ID for Generate Custom Images

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "Tomtepojke, a small figurine boy, walks down a narrow dirt path surrounded by a mix of pine and leafy trees...",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "outputFormat": "jpg",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 28
}

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 the COGNITIVE_ACTIONS_API_KEY and the endpoint URL with your actual credentials. The payload variable contains the input structure as defined in the schema, illustrating how to formulate the request.

Conclusion

The Loyote/Tomtepojke Cognitive Actions provide a robust framework for generating custom images, making it an excellent tool for developers looking to enhance their applications with creative visual content. By leveraging the power of AI-driven image generation, you can automate artwork creation, enhance user experiences, and explore new dimensions in digital storytelling. Explore these actions today and see how they can transform your projects!