Generating Custom Images with codelace/model5today Cognitive Actions

25 Apr 2025
Generating Custom Images with codelace/model5today Cognitive Actions

In today's digital landscape, the ability to generate high-quality images programmatically opens up a wealth of creative possibilities for developers. The codelace/model5today API provides a robust set of Cognitive Actions that make it easy to create detailed images using customizable parameters. This blog post will guide you through using the Generate Custom Images action, detailing its capabilities and how to integrate it into your applications.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for accessing the codelace/model5today service.
  • Familiarity with JSON and basic programming concepts.

For authentication, you will typically pass your API key in the request headers as follows:

Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY

Cognitive Actions Overview

Generate Custom Images

The Generate Custom Images action allows you to create detailed images using either image-to-image or inpainting modes. It offers a variety of customizable parameters such as image aspect ratio, resolution, and prompt strength, allowing you to tailor the output to your specific needs. You can leverage the 'dev' and 'schnell' models for optimal and fast-speed predictions.

Input

The input for this action is structured as a JSON object, with several required and optional fields. Here’s a breakdown of the input schema:

  • prompt (required): Text prompt for generating the image.
  • image (optional): URI of an input image for transformation.
  • mask (optional): URI for the image mask used in inpainting mode.
  • model (optional): Choose between 'dev' (default) and 'schnell'.
  • width (optional): Width of the generated image (256 to 1440).
  • height (optional): Height of the generated image (256 to 1440).
  • guidanceScale (optional): Scale for guiding the diffusion process.
  • numberOfOutputs (optional): Number of images to generate (1 to 4).

Here’s an example of the JSON payload for invoking this action:

{
  "image": "https://replicate.delivery/pbxt/MNdSPBQVQa76Hbm4TECAvU0b7S728PQ2qEUWlnGAu3fIdGsF/lady_000_lemonOG.jpeg",
  "model": "dev",
  "prompt": "Bespoke: 24x24 grid, Yellow (#F8E701) background...",
  "loraStrength": 1.24,
  "guidanceScale": 9.79,
  "enableFastMode": false,
  "imageResolution": "1",
  "numberOfOutputs": 1,
  "promptIntensity": 0.54,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "png",
  "imageOutputQuality": 51,
  "additionalLoraStrength": 1,
  "numberOfInferenceSteps": 50
}

Output

The output of the Generate Custom Images action will typically be a JSON array containing the URIs of the generated images. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/20a21e04-3aca-421d-afc9-11279e123cf3/f4a06a5b-3391-46a6-a7f1-83ca7c235d8a.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Custom Images action:

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 = "d71c1330-7664-4bfc-9502-65e63d29e50f" # Action ID for Generate Custom Images

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MNdSPBQVQa76Hbm4TECAvU0b7S728PQ2qEUWlnGAu3fIdGsF/lady_000_lemonOG.jpeg",
    "model": "dev",
    "prompt": "Bespoke: 24x24 grid, Yellow (#F8E701) background...",
    "loraStrength": 1.24,
    "guidanceScale": 9.79,
    "enableFastMode": False,
    "imageResolution": "1",
    "numberOfOutputs": 1,
    "promptIntensity": 0.54,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "png",
    "imageOutputQuality": 51,
    "additionalLoraStrength": 1,
    "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, substitute YOUR_COGNITIVE_ACTIONS_API_KEY with your actual key. The action ID and input payload are structured to align with the action's requirements.

Conclusion

The Generate Custom Images action from the codelace/model5today API provides a powerful tool for developers to create customized images tailored to their specific needs. By utilizing the wide range of parameters available, you can produce stunning visuals that enhance your applications.

Explore the possibilities further by experimenting with different prompts, image formats, and models. Happy coding!