Transform Your Images with the cgkio/chip_and_sarah Cognitive Actions

23 Apr 2025
Transform Your Images with the cgkio/chip_and_sarah Cognitive Actions

In the ever-evolving world of image processing, the cgkio/chip_and_sarah API provides a powerful toolset for developers aiming to enhance their applications with advanced image generation capabilities. Among its offerings, the Generate Inpainted Image action stands out by leveraging sophisticated inpainting techniques that allow for creative image manipulation. This blog post will guide you through understanding and integrating this action, enabling you to create visually compelling content effortlessly.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will be used to authenticate your requests.
  • Familiarity with sending HTTP requests and handling JSON data in your preferred programming language.

Authentication typically involves passing the API key in the request headers, allowing you to securely access the available actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action is designed to create images using advanced inpainting techniques. This action offers options for image masking, aspect ratio selection, and various quality settings, providing flexibility for developers to tailor their image generation to specific needs. Notably, it includes two inference models: the 'dev' model, which prioritizes quality, and the 'schnell' model, which focuses on speed.

Input

The input schema for this action requires the following fields:

  • prompt (string, required): A detailed textual description of the desired image.
  • mask (string, optional): URI for the image mask used in inpainting.
  • image (string, optional): URI for an input image used in image-to-image mode.
  • width (integer, optional): Width of the generated image.
  • height (integer, optional): Height of the generated image.
  • goFast (boolean, optional): Enables faster processing.
  • seed (integer, optional): Seed for randomization.
  • numOutputs (integer, optional): Number of images to be generated.
  • guidanceScale (number, optional): Influence of the guidance scale.
  • outputQuality (integer, optional): Quality of the output image.
  • inferenceModel (string, optional): Model to run inference with ('dev' or 'schnell').
  • Other optional fields include extraLora, loraScale, promptStrength, imageAspectRatio, imageOutputFormat, numInferenceSteps, etc.

Here’s an example of the JSON payload needed to invoke this action:

{
  "prompt": "Render an image of _chip&sarah, showing the two people—a bald 40-year-old male and a 40-year-old female—standing side by side in a vibrant, outdoor urban setting. The male is dressed in a casual, button-up shirt with rolled-up sleeves, while the female wears a summer dress with floral patterns. Both are smiling warmly at the camera, capturing a moment of friendly and cheerful connection. The background features a lively city street with pedestrians and storefronts, bathed in the golden light of late afternoon. Ensure their facial features are clearly visible and accurately rendered, with emphasis on their expressions and natural poses.",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 28
}

Output

Upon successful execution, this action typically returns a URL to the generated image. For instance:

[
  "https://assets.cognitiveactions.com/invocations/683cfcf7-86d3-482f-8f7b-88d6167bc4a1/573a889d-db3e-496f-9944-bfdfaeb3441a.webp"
]

This URL points to the generated image based on the provided prompt and settings.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Inpainted Image 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 = "6513936f-9104-4020-8e91-e4a6648c8085" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Render an image of _chip&sarah, showing the two people—a bald 40-year-old male and a 40-year-old female—standing side by side in a vibrant, outdoor urban setting. The male is dressed in a casual, button-up shirt with rolled-up sleeves, while the female wears a summer dress with floral patterns. Both are smiling warmly at the camera, capturing a moment of friendly and cheerful connection. The background features a lively city street with pedestrians and storefronts, bathed in the golden light of late afternoon. Ensure their facial features are clearly visible and accurately rendered, with emphasis on their expressions and natural poses.",
    "loraScale": 1,
    "numOutputs": 1,
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "numInferenceSteps": 28
}

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, you'll notice that the action ID and input payload are structured according to the requirements of the Generate Inpainted Image action. The endpoint URL and request structure are illustrative and should be adjusted based on your actual API setup.

Conclusion

The cgkio/chip_and_sarah Cognitive Actions provide developers with powerful tools for image generation and manipulation. By utilizing the Generate Inpainted Image action, you can create stunning visuals tailored to your application's needs. As you explore these capabilities, consider the various parameters available for fine-tuning your outputs, and don't hesitate to experiment with different prompts and settings to unleash your creativity. Happy coding!