API Endpoints

POST /chat | /askcarti

Tags: Machine Learning

Description

Handles AI chat requests.

Request

Content-Type: application/json

Request Body:

{
    "prompt": "string",
    "web": "boolean"
}

Parameters:

  • prompt (string): The input prompt for the AI model.

  • web (boolean, optional): Optional flag to indicate if web search is enabled. (default: False)

Response

Content-Type: application/json

Response Body:

{
    "llama": {
        "content": [],
        "short": "Ohio is a very interesting state ...",
        "extra": "...",
        "raw": "...",
        "sources": [
            {
                "title": "Essay About Ohio - 475 Words | Bartleby",
                "link": "https://www.bartleby.com/essay/Essay-About-Ohio-CBAA6629959B906F",
                "snippet": "Ohio is a very interesting state! It has many unique facts like the highest point in ohio! Ohio has lots and lots of history and some sad history."
            }
            // ... additional source objects
        ]
    }
}

Error Responses

  • 401 Unauthorized: Unauthorized access.

  • 400 Bad Request: Missing required prompt field.

  • 500 Internal Server Error: GPU is offline.

Example Error Response:

{
    "error": "Unauthorized"
}

Notes

  • The Authorization header must be present with a valid token.

  • If the prompt is missing or if there is an exception during the AI processing, appropriate error messages will be returned.


POST /image2text

Tags: Machine Learning

Description

Converts an image to text.

Request

Content-Type: application/octet-stream

Request Body:

  • Body: Raw image bytes.

Response

Content-Type: application/json

Response Body:

{
    "text": "string"
}

Error Responses:

  • 400 Bad Request: Image is required.

  • 401 Unauthorized: Content is NSFW.

  • 500 Internal Server Error: Error message detailing the issue.

Example Error Response:

{
    "error": "Image is required"
}

Notes

  • The request body must contain raw image bytes.

  • The endpoint checks for NSFW content and will return an error if the content is deemed inappropriate.

  • The text extracted from the image will be returned in the response.


POST /image/classify

Tags: Machine Learning

Description

Classifies the content of an image.

Request

Content-Type: application/octet-stream

Request Body:

  • Body: Raw image bytes.

Response

Content-Type: application/json

Response Body:

{
    "classification": "string"
}

Error Responses:

  • 400 Bad Request: Image is required.

  • 401 Unauthorized: Content is NSFW.

  • 500 Internal Server Error: Error message detailing the issue.

Example Error Response:

{
    "error": "Image is required"
}

Notes

  • The request body must contain raw image bytes.

  • The endpoint checks for NSFW content and will return an error if the content is deemed inappropriate.

  • The classification result of the image will be returned in the response.


POST /image

Tags: Machine Learning

Description

Handles image generation requests. This endpoint receives a JSON request containing a prompt, generates an image based on the prompt, adds a watermark, and returns the watermarked image.

Request

Content-Type: application/json

Request Body:

{
    "prompt": "string"
}

Parameters:

  • prompt (string): The input prompt for generating the image.

Response

Success Response:

Content-Type: image/jpeg

  • The response will be a streaming image file with a JPEG format.

Error Responses:

  • 400 Bad Request: Missing prompt field.

Example Error Response:

{
    "error": "Prompt is required"
}
  • 500 Internal Server Error: Error occurred during image generation.

Example Error Response:

{
    "error": "Error message detailing the issue"
}

Notes

  • The prompt field is required in the request body. If it is missing, a 400 Bad Request error will be returned.

  • The endpoint processes the prompt to generate an image, applies a watermark, and then returns the image as a streaming response in JPEG format.

  • If an error occurs during image generation or watermarking, a 500 Internal Server Error with a detailed error message will be returned.


POST /ocr

Tags: Machine Learning

Description

Extracts text from an image using Optical Character Recognition (OCR). This endpoint receives an image, processes it to extract text, and returns the text as a plain text response.

Request

Content-Type: application/octet-stream

Request Body:

  • Body: Raw image bytes.

Response

Success Response:

Content-Type: text/plain

  • The response will contain the extracted text from the image.

Error Responses:

  • 400 Bad Request: Image is required.

Example Error Response:

{
    "error": "Image is required"
}
  • 500 Internal Server Error: Error occurred during OCR processing.

Example Error Response:

{
    "error": "Error message detailing the issue"
}

Notes

  • The request body must contain raw image bytes.

  • If the image is not provided, a 400 Bad Request error will be returned.

  • The text extracted from the image will be returned as plain text in the response.

  • In case of any processing errors, a 500 Internal Server Error with a detailed error message will be returned.


POST /chat/image

Tags: Machine Learning

Description

Chats with an AI using both a text prompt and an image. The endpoint receives a prompt and an image (in base64 format), processes them, and returns the AI's response.

Request

Content-Type: application/json

Request Body:

{
    "prompt": "string",
    "image": "string"  // Base64 encoded image
}

Parameters:

  • prompt (string): The text prompt to send to the AI.

  • image (string): The image to send to the AI in base64 format.

Response

Content-Type: application/json

Success Response:

{
    "llama": {
        "short": "string",
        "extra": "...",
        "raw": "...",
        "sources": [
            {
                "title": "string",
                "link": "string",
                "snippet": "string"
            }
        ]
    }
}

Error Responses:

  • 400 Bad Request: Missing prompt or image.

Example Error Response:

{
    "error": "Prompt and image are required"
}
  • 500 Internal Server Error: Error occurred during processing.

Example Error Response:

{
    "error": "Error message detailing the issue"
}

Notes

  • Both prompt and image fields are required in the request body. If either is missing, a 400 Bad Request error will be returned.

  • The image should be in base64 encoded format.

  • The AI's response will be returned in the JSON format specified in the success response.

  • If an error occurs during processing, a 500 Internal Server Error with a detailed error message will be returned.


Here’s the Markdown documentation for the /screenshot endpoint, formatted for GitBook:


GET /screenshot

Tags: Scraping

Description

Takes a screenshot of a specified website. This endpoint requires a URL as a query parameter and optionally accepts a delay before capturing the screenshot. It returns the screenshot image if the URL is valid and not blocked. If the content is NSFW, an error response is returned.

Request

Query Parameters:

  • url (string): The URL of the website to capture. This should include the scheme (http or https).

  • delay (integer, optional): The number of seconds to wait before taking the screenshot.

Example Request:

GET /screenshot?url=https://example.com&delay=5

Response

Success Response:

Content-Type: image/jpeg

  • Returns a JPEG image of the screenshot.

Error Responses:

  • 400 Bad Request: Invalid URL scheme or URL is malformed.

Example Error Response:

{
    "detail": "Scheme is not supported or URL is invalid."
}
  • 403 Forbidden: URL is blocked by the block list.

Example Error Response:

{
    "detail": "URL is blocked by block list"
}
  • 401 Unauthorized: Content is NSFW.

Example Error Response:

{
    "error": "Content is NSFW"
}
  • 500 Internal Server Error: An error occurred during screenshot capture.

Example Error Response:

{
    "detail": "Error message detailing the issue"
}

Notes

  • The url parameter must include the scheme (http or https). URLs with other schemes will result in a 400 Bad Request error.

  • The delay parameter, if provided, specifies how long to wait before capturing the screenshot. If not provided, the default behavior is to capture the screenshot immediately.

  • URLs in the blocked_urls list are not allowed and will return a 403 Forbidden error.

  • If the content of the screenshot is detected as NSFW, a 401 Unauthorized response will be returned.

  • In case of processing errors, a 500 Internal Server Error will be returned with details about the issue.

Last updated