Generate Stunning Images with Cognitive Actions from fewjative

25 Apr 2025
Generate Stunning Images with Cognitive Actions from fewjative

Integrating advanced image generation capabilities into your applications has never been easier with the Cognitive Actions provided by the fewjative API. With the Generate Custom Image action, developers can create high-quality custom images based on user-defined prompts and parameters. This action offers flexibility in terms of models, aspect ratios, dimensions, and more, allowing for tailored image outputs that fit a variety of use cases.

Prerequisites

Before you begin integrating the Cognitive Actions into your application, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform. This key will be used for authentication.
  • Familiarity with making HTTP requests in your programming language of choice, as well as JSON formatting.

Generally, authentication involves including your API key in the request headers like so:

headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}",
    "Content-Type": "application/json"
}

Cognitive Actions Overview

Generate Custom Image

The Generate Custom Image action allows you to create a custom image based on specific prompts and parameters. You can choose between two models: the dev model for optimal quality with more inference steps or the schnell model for faster processing.

Input

The input for this action is defined in the CompositeRequest schema, which includes several properties:

  • prompt (required): Text prompt for generating the image.
  • model (optional): Choose between "dev" (default) and "schnell".
  • aspectRatio (optional): Predefined aspect ratios or "custom".
  • width and height (optional): Dimensions for the image if aspect ratio is set to "custom".
  • imageFormat (optional): The format of the output image (default is "webp").
  • outputCount (optional): Number of images to generate (default is 1).
  • imageQuality (optional): Quality level from 0 to 100 (default is 80).
  • inferenceSteps (optional): Number of denoising steps (default is 28).
  • additionalWeightsScale (optional): Adjusts strength for additional LoRA weights.

Here’s an example input payload for this action:

{
  "model": "dev",
  "prompt": "a car photoshoot of a ferrari in the style of RLLRSTYL",
  "aspectRatio": "1:1",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 90,
  "weightsScale": 1,
  "guidanceScale": 3.5,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "additionalWeightsScale": 1
}

Output

The output of the Generate Custom Image action returns a list of URLs pointing to the generated images. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/aae7443f-9e9d-41d9-85e4-25d15bf8207c/4070e799-3007-479e-b883-0e7061a688bc.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how you might call this action through a hypothetical Cognitive Actions execution endpoint:

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 = "8666ba4c-8818-4464-95da-99f995d8cafb" # Action ID for Generate Custom Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "a car photoshoot of a ferrari in the style of RLLRSTYL",
    "aspectRatio": "1:1",
    "imageFormat": "webp",
    "outputCount": 1,
    "imageQuality": 90,
    "weightsScale": 1,
    "guidanceScale": 3.5,
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "additionalWeightsScale": 1
}

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}")

This example shows how to set up the request, including the action ID and input payload. Remember, the endpoint URL and request structure are illustrative and should be adjusted according to your actual integration details.

Conclusion

The Generate Custom Image action from the fewjative Cognitive Actions suite empowers developers to seamlessly integrate robust image generation capabilities into their applications. Whether you need high-quality images for marketing materials, creative projects, or anything in between, this action provides the tools to meet your needs.

Consider exploring additional use cases, such as customizing the image outputs or integrating this functionality into user-facing applications, to fully leverage the power of these Cognitive Actions. Happy coding!