Enhance Your Applications with Image Generation Using hijaek/obok Cognitive Actions

23 Apr 2025
Enhance Your Applications with Image Generation Using hijaek/obok Cognitive Actions

In today's digital landscape, the demand for high-quality, customized images is ever-increasing. The hijaek/obok API offers a powerful set of Cognitive Actions designed to facilitate image generation and manipulation, particularly through its Generate Image with Inpainting action. This action allows developers to create stunning images by using inpainting techniques, providing flexibility in customization and output quality. In this post, we will explore how to leverage this action effectively in your applications.

Prerequisites

Before you can start using the Cognitive Actions provided by the hijaek/obok API, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of sending HTTP requests and handling JSON data.

Authentication typically involves including your API key in the request headers, which will allow you to access the various actions available within the API.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action enables users to generate images through a powerful inpainting mode. This functionality allows for precise image manipulation and enhancement by utilizing a mask. You can choose between two inference models: dev for detailed generation and schnell for faster processing. The action also supports a variety of customization options, including aspect ratio, output quality, and additional stylization via LoRA weights.

Input

The input for this action is structured as follows:

{
  "prompt": "string (required)",
  "mask": "string (optional, uri)",
  "image": "string (optional, uri)",
  "width": "integer (optional, 256 to 1440)",
  "height": "integer (optional, 256 to 1440)",
  "goFast": "boolean (optional, default: false)",
  "seed": "integer (optional)",
  "numOutputs": "integer (optional, 1 to 4, default: 1)",
  "guidanceScale": "number (optional, 0 to 10, default: 3)",
  "outputQuality": "integer (optional, 0 to 100, default: 80)",
  "inferenceModel": "string (optional, enum: ['dev', 'schnell'], default: 'dev')",
  "promptStrength": "number (optional, 0 to 1, default: 0.8)",
  "imageMegapixels": "string (optional, enum: ['1', '0.25'], default: '1')",
  "imageAspectRatio": "string (optional, enum: [...], default: '1:1')",
  "imageOutputFormat": "string (optional, enum: ['webp', 'jpg', 'png'], default: 'webp')",
  "numInferenceSteps": "integer (optional, 1 to 50, default: 28)",
  "disableSafetyChecker": "boolean (optional, default: false)"
}
Example Input

Here’s an example of the JSON payload you might use to invoke this action:

{
  "goFast": false,
  "prompt": "WTRCLR, watercolor, obok painting of white dog running on garden of flowers",
  "extraLora": "https://huggingface.co/gokaygokay/Flux-Watercolor-Strokes-LoRA/resolve/main/watercolor_strokes.safetensors",
  "loraScale": 1,
  "numOutputs": 4,
  "guidanceScale": 3,
  "outputQuality": 100,
  "extraLoraScale": 1.5,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28
}

Output

Upon successful execution, this action returns an array of URLs pointing to the generated images. For instance:

[
  "https://assets.cognitiveactions.com/invocations/1730d474-43cc-48e7-b011-a87aefe18b0b/664eee66-233b-42a0-95ec-e6f7faa4fd73.jpg",
  "https://assets.cognitiveactions.com/invocations/1730d474-43cc-48e7-b011-a87aefe18b0b/50fcd2f5-b6ca-4792-b1ca-34fc9b7af249.jpg",
  "https://assets.cognitiveactions.com/invocations/1730d474-43cc-48e7-b011-a87aefe18b0b/580b62d5-8b3e-4d2d-ba21-8e679f3d541d.jpg",
  "https://assets.cognitiveactions.com/invocations/1730d474-43cc-48e7-b011-a87aefe18b0b/c0ceb5d5-a898-403f-8829-3e04e6f6b7d4.jpg"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how you might call the Generate Image with Inpainting 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 = "94786e54-51dd-445b-b2ef-acf3051dc3e4"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "WTRCLR, watercolor, obok painting of white dog running on garden of flowers",
    "extraLora": "https://huggingface.co/gokaygokay/Flux-Watercolor-Strokes-LoRA/resolve/main/watercolor_strokes.safetensors",
    "loraScale": 1,
    "numOutputs": 4,
    "guidanceScale": 3,
    "outputQuality": 100,
    "extraLoraScale": 1.5,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "jpg",
    "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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for Generate Image with Inpainting is used to specify which action to execute. The input payload is constructed according to the schema, and the response is managed to handle potential errors gracefully.

Conclusion

The hijaek/obok Cognitive Actions, particularly the Generate Image with Inpainting action, opens up exciting possibilities for developers looking to integrate robust image generation capabilities into their applications. By utilizing this action, you can create custom images tailored to your needs, enhancing the visual appeal of your projects.

Next steps could include experimenting with different input parameters to fine-tune image quality or exploring additional actions within the hijaek/obok suite to expand your application's functionality. Happy coding!