Create Stunning Images with Razzar's Custom Parameters

25 Apr 2025
Create Stunning Images with Razzar's Custom Parameters

In today’s visually-driven world, the ability to generate unique and captivating images is invaluable for developers. Razzar provides a powerful set of Cognitive Actions that enable seamless image generation with customizable parameters. This service offers developers the flexibility to create images tailored to specific needs, whether for marketing campaigns, content creation, or artistic projects. By leveraging Razzar, you can enhance your applications with stunning visuals quickly and easily, saving time and resources while improving user engagement.

Prerequisites

To get started with Razzar, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Generate Image with Custom Parameters

This action allows you to generate images by specifying various customizable parameters. It addresses the need for unique visual content by enabling image-to-image transformation, inpainting, and the selection of different output formats.

Input Requirements

The input for this action is a structured JSON object that requires a "prompt" to define the content of the image. Additional optional parameters include:

  • mask: URI for image masking in inpainting mode.
  • seed: Integer for reproducibility.
  • image: URI of the input image for transformations.
  • model: Choose between "dev" or "schnell" for the inference model.
  • width and height: Dimensions for the image, applicable with custom aspect ratios.
  • fastMode: A boolean to enable faster predictions.
  • outputCount: Number of images to generate.
  • outputFormat: Format of the output (webp, jpg, png).
  • guidanceScale: Adjusts the guidance during the diffusion process.

Expected Output

The output will be a URI link to the generated image, which can be used directly in your applications.

Use Cases for this specific action

  • Content Creation: Ideal for marketers and content creators who need customized visuals quickly.
  • Artistic Projects: Artists can experiment with different styles and concepts by adjusting parameters to generate unique artworks.
  • Prototyping: Developers can use image generation in prototypes to visualize ideas without the need for extensive graphic design resources.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "49f549f4-c4f5-4b98-a70b-4bd2c556606d" # Action ID for: Generate Image with Custom Parameters

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "prompt": "razzar a man sitting on a lion",
  "fastMode": false,
  "loraScale": 1,
  "megapixels": "1",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "inferenceStepCount": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

Razzar's image generation capabilities empower developers to create high-quality, customized images with minimal effort. Whether you're enhancing a product's appeal or bringing creative concepts to life, this action simplifies the process of generating stunning visuals. Start integrating Razzar into your applications today and unlock the potential for engaging content that captures attention and drives interaction.