Create Stunning Images with the Image Generation and Manipulation API

The Image Generation and Manipulation API offers developers a powerful toolset to create and modify images using advanced techniques like inpainting and image-to-image transformation. This API simplifies the image creation process, allowing you to generate high-quality visuals quickly and efficiently. With customizable parameters, you can control aspects such as image dimensions, quality, and styles to suit your specific needs.
Imagine being able to automate the generation of unique graphics for your applications, marketing materials, or social media posts. Whether you need to create artwork from scratch, enhance existing images, or generate concept visuals, this API provides the capabilities you need to bring your ideas to life.
Prerequisites
To get started with the Image Generation and Manipulation API, you'll need an API key and a basic understanding of making API calls.
Generate Image Using Inpainting or Image-to-Image Mode
This operation creates images through inpainting or image-to-image transformation using specific model parameters. Users can control properties like image dimensions, model selection, and output quality. Employ the 'dev' model for detailed outputs with around 28 steps, or use 'schnell' for faster results. The process also supports external LoRA weights and fast-mode enhancements.
Input Requirements
To generate an image, you need to provide the following:
- Prompt: A text description of the desired image.
- Image (optional): The URI of an input image for inpainting or image-to-image transformation.
- Mask (optional): The URI of an image mask for inpainting mode.
- Model: Choose between 'dev' for detailed generation or 'schnell' for speed.
- Width & Height: Specify the dimensions of the image (if aspect ratio is set to 'custom').
- Denoising Steps: Number of steps to refine the image.
- Output Format: Choose between formats like 'webp', 'jpg', or 'png'.
Expected Output
The API will return a URI to the generated image, which can be accessed for further use.
Use Cases for this Specific Action
- Content Creation: Ideal for marketers and content creators who need unique images for blogs, social media, or advertising campaigns.
- Art and Design: Artists can utilize this API to generate concept art or enhance their digital portfolios.
- Prototyping and Visualization: Developers can create mockups or visual representations of ideas quickly during the design phase.
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 = "d9559074-9a57-4692-83f7-506967b5399c" # Action ID for: Generate Image Using Inpainting or Image-to-Image Mode
# 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": "Close-up headshot of Count Dooku holding a red lightsaber with a brilliant white core, glowing intensely. A vivid red aura surrounds him, casting a powerful light on his stern, focused face. The iconic silver chain holding his dark cape is clearly visible across his shoulders. The lighting is dramatic and cinematic, with realistic shadows and subtle Sith ambiance in the background. The image should have a photorealistic style with sharp detail and a moody, dark tone.",
"loraImpact": 1,
"promptImpact": 0.8,
"guidanceScale": 3,
"denoisingSteps": 28,
"enableFastMode": false,
"imageResolution": "1",
"numberOfOutputs": 1,
"aspectRatioOption": "21:9",
"imageOutputFormat": "jpg",
"imageOutputQuality": 80,
"additionalLoraImpact": 1
}
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
The Image Generation and Manipulation API empowers developers to create stunning visuals efficiently, streamlining the image generation process while offering extensive customization options. From marketing to art creation, the use cases are vast and varied. Start integrating this API into your projects today to unlock a world of creative possibilities!