CloudBrowserAISharp

Overview

The CloudBrowserAISharp client provides access to our /api/v1/ai endpoint for interacting with OpenAI's API to perform various tasks.

Note: Currently, only OpenAI is supported as the AI provider. In the future, we may support other providers.


General Requirements

Headers

All requests must include an API authentication token in the header:

Authorization: Bearer {YourAPIToken}

Common Request Body

Every request must include an openAIConfiguration object in the body:

{
  "openAIConfiguration": {
    "apiKey": "string",
    "model": "string"
  },
  // Operation-specific body below
}

Where:

  • apiKey: Your OpenAI API key.

  • model: The OpenAI model to use (e.g., gpt-4).

Response Format

All requests return a standard response structure:

{
  "status": "ResponseStatus",
  "response": "string",
  "openAiError": "AIError (optional)"
}
  • status: The request status (see the ResponseStatus enum).

  • response: The output generated by OpenAI.

  • openAiError (optional): Any OpenAI-specific error (see the AIError enum).

Enums

ResponseStatus

public enum ResponseStatus {
    Unknown = 0,
    Success = 200,
    AuthorizationError = 401,
    NoSubscription = 402,
    NoUnits = 403,
    BrowserLimit = 404,
    AIError = 405,
    LabelInUse = 406
}

AIError

public enum AIError : byte {
    UNKNOWN = 0,
    CONTENT_FLAGGED = 1,
    TOO_LONG = 2,
    INVALID_API_KEY = 3
}

Available Endpoints

1. query

Send an HTML document and a prompt to OpenAI for processing.

Request Body

{
  "html": "string",
  "promt": "string",
  "responseFormat": "string"
}

Example Usage

Send an HTML document and a custom prompt for processing:

{
  "html": "<html>...</html>",
  "promt": "Extract the title and summarize the content",
  "responseFormat": "text"
}

2. summarize

Generate a summary from an HTML document or text.

Request Body

{
  "html": "string",
  "isoLang": "string (optional)",
  "responseFormat": "string"
}

Example Usage

Summarize HTML content in Spanish:

{
  "html": "<html>...</html>",
  "isoLang": "es",
  "responseFormat": "text"
}

3. optimize

Optimize a given text based on specific instructions.

Request Body

{
  "text": "string",
  "instruction": "string",
  "responseFormat": "string"
}

Example Usage

Optimize a headline for SEO:

{
  "text": "10 Tips for Gardening",
  "instruction": "Make the title more engaging for SEO",
  "responseFormat": "text"
}

4. translate

Translate a text into a specified language.

Request Body

{
  "text": "string",
  "isoLang": "string",
  "responseFormat": "string"
}

Example Usage

Translate text into French:

{
  "text": "Hello, world!",
  "isoLang": "fr",
  "responseFormat": "text"
}

5. describe

Answer questions or describe an image provided in base64 or URL format.

Request Body

{
  "question": "string",
  "base64Image": "string",
  "imageUrl": "string",
  "responseFormat": "string"
}

Notes

  • Either base64Image or imageUrl must be provided, but not both.


6. ToJSON

Convert an HTML document into a structured JSON object.

Request Body

{
  "html": "string",
  "responseFormat": "string"
}

Example Usage

Convert HTML to JSON:

{
  "html": "<html>...</html>",
  "responseFormat": "json"
}

7. ToCSV

Convert an HTML document into a CSV file.

Request Body

{
  "html": "string",
  "headers": "string (optional)",
  "responseFormat": "string"
}

Example Usage

Generate a CSV from an HTML table with custom headers:

{
  "html": "<table>...</table>",
  "headers": "Name,Email,Phone",
  "responseFormat": "csv"
}

8. ToMarkdown

Convert an HTML document into Markdown format.

Request Body

{
  "html": "string"
}

Notes

This is the only endpoint that does not require a responseFormat.

Last updated