Enhance Your Applications with Image Inpainting Using Tosti-Vector Cognitive Actions

24 Apr 2025
Enhance Your Applications with Image Inpainting Using Tosti-Vector Cognitive Actions

The Tosti-Vector Cognitive Actions provide developers with powerful tools for generating and editing images using advanced inpainting techniques. This set of actions enables precise image manipulation, empowering applications to create custom visuals tailored to specific requirements. With options like adjustable output formats, aspect ratios, and fast processing modes, developers can seamlessly integrate these capabilities into their projects.

Prerequisites

Before you start using the Tosti-Vector Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON format, as the input and output data will be structured in JSON.
  • Familiarity with making HTTP requests through a programming language of your choice, such as Python.

To authenticate with the Cognitive Actions API, you will typically pass the API key in the headers of your request.

Cognitive Actions Overview

Generate Image Inpainting

The Generate Image Inpainting action allows users to create images using inpainting techniques. This action supports various attributes such as custom width and height, aspect ratios, and output formats. Additionally, it offers a 'schnell' model for fast image generation, perfect for developers looking to optimize performance.

Input

The input for this action requires a JSON object with the following properties:

  • prompt (required): A text prompt specifying the desired image features. For example:
    "prompt": "a dog vector illustration in the style of TSTVCTR"
    
  • model (optional): Selects the model for inference, either "dev" or "schnell". The default is "dev".
  • aspectRatio (optional): Specifies the aspect ratio for the output image, with options such as "1:1", "16:9", or "custom".
  • outputCount (optional): Defines the number of images to generate (1 to 4).
  • outputFormat (optional): The desired image file format, selectable from "webp", "jpg", or "png".
  • Additional properties allow for fine-tuning of image attributes, such as guidanceScale, outputQuality, inferenceStepCount, and more.

Example Input:

{
  "model": "schnell",
  "prompt": "a dog vector illustration in the style of TSTVCTR",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "loraIntensity": 1,
  "outputQuality": 90,
  "promptStrength": 0.8,
  "inferenceStepCount": 4,
  "additionalLoraScale": 1
}

Output

The output of the action will return a JSON array containing the URLs of the generated images. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/4cb5bef1-803f-454c-8803-476eed625452/81c2775d-45e4-4b23-9fcd-ab73c8a7c83a.webp"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to call the Generate Image Inpainting action using a hypothetical Cognitive Actions API 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 = "8e6617a6-f29b-4987-af14-082882dbda49"  # Action ID for Generate Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "schnell",
    "prompt": "a dog vector illustration in the style of TSTVCTR",
    "aspectRatio": "1:1",
    "outputCount": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "loraIntensity": 1,
    "outputQuality": 90,
    "promptStrength": 0.8,
    "inferenceStepCount": 4,
    "additionalLoraScale": 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}")

In this code snippet, you replace the placeholder API key and endpoint with your actual credentials. The action_id corresponds to the Generate Image Inpainting action. The input payload is structured according to the requirements outlined earlier.

Conclusion

The Tosti-Vector Cognitive Actions offer an efficient way to integrate image generation and editing capabilities into your applications, enhancing user experience and creativity. With options for fast processing and customizable attributes, developers can create visually stunning outputs tailored to their needs. Start experimenting with these actions today to unlock new possibilities in your projects!