Generate Stunning Images with the dribnet/pixray-api Cognitive Actions

22 Apr 2025
Generate Stunning Images with the dribnet/pixray-api Cognitive Actions

In the realm of image generation, the dribnet/pixray-api provides developers with powerful tools to create stunning visuals using customizable settings. The Cognitive Actions available under this spec allow you to harness the capabilities of Pixray, enabling you to define parameters such as palette selection, filters, prompts, quality preferences, and seed configuration. By leveraging these pre-built actions, developers can streamline the integration of advanced image generation features into their applications, enhancing user experiences and creativity.

Prerequisites

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

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform. This key should be included in the request headers.
  • Basic Knowledge of JSON: Understanding how to structure JSON payloads is essential for configuring your requests.

Authentication typically involves passing the API key in the headers of your HTTP requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Execute Pixray with Raw Settings

Description: This action executes image generation using Pixray with customizable raw settings. It allows you to specify various parameters such as palette selection, filters, prompts, quality preferences, and seed configuration, providing flexibility in how images are generated.

Category: Image Generation

Input: The input for this action requires a YAML formatted string containing configuration settings. The schema is as follows:

  • configurationSettings: A string that includes settings for your image generation. This can include options like palette URL, filters, prompts, quality settings, and a seed for randomization.

Example Input:

{
  "configurationSettings": "# find palettes at https://lospec.com/palette-list\npalette: https://lospec.com/palette-list/cl8uds-32x.png\nfilters: lookup\nprompts: \"robots at sunset\"\nquality: better\nseed: god_mode\n"
}

Output: The action typically returns an array of URLs pointing to the generated images. Below is an example of what you might receive:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/457ea0cd-77ca-42ce-94b2-789e9e0f6b83/4a90954b-6464-4172-96f6-b2bf83bce125.png",
  "https://assets.cognitiveactions.com/invocations/457ea0cd-77ca-42ce-94b2-789e9e0f6b83/4b5c627b-47f1-4daf-b227-bdf5c66b1675.png",
  ...
]

Conceptual Usage Example (Python): Here’s how you might call the Execute Pixray with Raw Settings action using 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 = "550d1966-c67c-475b-b87d-4f3e327aa75e"  # Action ID for Execute Pixray with Raw Settings

# Construct the input payload based on the action's requirements
payload = {
    "configurationSettings": "# find palettes at https://lospec.com/palette-list\npalette: https://lospec.com/palette-list/cl8uds-32x.png\nfilters: lookup\nprompts: \"robots at sunset\"\nquality: better\nseed: god_mode\n"
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for Execute Pixray with Raw Settings is specified, and the input payload is structured according to the required schema. This example demonstrates how to send a request to the Cognitive Actions endpoint and handle the response.

Conclusion

The dribnet/pixray-api provides a robust mechanism for generating images tailored to your specific needs through its Cognitive Actions. By utilizing these actions, developers can quickly implement creative image generation features into their applications, enhancing engagement and functionality. Explore the possibilities of image generation with customizable settings and take your projects to the next level!