Skip to main content

AiSafe API Documentation

General Information

  • Title: AI Safe API
  • Version: 1.0
  • Base URL: /mdp/ai-safe/

Authentication

  • Type: API Key
  • Key Name: Authorization
  • Location: Header
  • Description: JWT token for authorization

Endpoints

1. Fetch Chat History

  • Method: GET
  • URL: /history
  • Description: Retrieves the list of chat names and their ids of the user.
  • Responses:
  • 200:
    • Description: List of chat names and ids retrieved successfully.

    • Example:

      {
      "success": true,
      "message": "History fetched successfully",
      "data": {
      "chat id 1": "chat name 1",
      "chat id 2": "chat name 2",
      "chat id 3": "chat name 3",
      "chat id 4": "chat name 4"
      }
      }

2. Fetch Chat History by Chat ID

  • Method: GET
  • URL: /history/{chat_id}
  • Description: Retrieves the prompts for a specific chat for a user.
  • Parameters:
    • chat_id (path, string, required): Chat ID to fetch history for.
  • Responses:
  • 200:
    • Description: Chat history retrieved successfully.

    • Example:

      {
      "success": true,
      "message": "History fetched successfully",
      "response_code": 200,
      "data": {
      "anonymized_values": {
      "Emails": ["Email1", "Email2"],
      "Names": ["Name1", "Name2"],
      "Phone": ["ph number 1", "ph number 2"]
      },
      "prompts": [
      {
      "responseType": "text",
      "originalPrompt": "Original prompt 1",
      "anonymizedPrompt": "Anonymized prompt 1",
      "response": "Anonymized response 1"
      }
      {
      "responseType": "text",
      "originalPrompt": "Original prompt 1",
      "anonymizedPrompt": "Anonymized prompt 1",
      "response": "Anonymized response 1"
      }
      ]
      }
      }

3. Upload a File

  • Method: POST
  • URL: /upload
  • Header should contain the name of the file in the key File-Name
  • Description: Endpoint to upload files to the LLM.
  • Responses:
    • 200:
      • Description: File uploaded successfully.

      • Example:

        {
        "success": true,
        "message": "File uploaded successfully."
        "data" : "(Sample file id)"
        }
    400: Invalid file.

4. Anonymize Text

  • Method: POST
  • URL: /anonymize
  • Description: Anonymizes sensitive entities in a given prompt.
  • Parameters:
    • lang (body, string, required): Language for anonymization.

    • prompt (body, string, required): Input text.

    • choices (body, array of strings, required): Entities to anonymize.

    • model (body, string, required): Model to use.

    • anonymized (body, boolean, required): Flag to determine anonymization type.

      {
      "lang" : "eng",
      "prompt" : "(Name1 Sample prompt 1)",
      "choices" : ["Names", "Emails"],
      "model" : "llama3.1",
      "anonymized" : false
      }
  • Responses:
    • 200: Text anonymized successfully.

    • Data:

      {
      "anonymized_prompt": "(Prompt after replacement of detected PII)",
      "anonymized_values": {
      "Emails": ["anon_email1", "anon_email2"],
      "Names": ["Anonymized Name1"],
      "Phone": ["Anonymized phone number1"]
      }
      "detected_values": {
      "Emails": ["anon_email1", "anon_email2"],
      "Names": ["Detected Name1"],
      "Phone": ["Detected phone number1"]
      }
      }

5. Send Chat

  • Method: POST
  • URL: /chat
  • Description: Sends the anonymized prompt to the LLM and returns the response after replacement from the LLM.
  • Parameters:
    • lang (body, string, required): Language for Name detection (eng, ger).

    • prompt (body, string, required): Prompt that is meant to be sent.

    • choices (body, array of strings, required): Entities to anonymize (Name, Email, Phone).

    • model (body, string, required): Model to use.

    • chat_id(body, string, optional): Chat_id for the prompt, assumed a new chat if empty.

    • doc (body, string, optional): Document id of the uploaded file.

    • anonymized (body, boolean, required): Flag to determine if anonymization is required.

      {
      "lang" : "eng",
      "prompt" : "(Sample prompt 1)",
      "choices" : ["Names", "Emails"],
      "model" : "llama3.1",
      "chat_id" : "", // Considered a new chat
      "doc" : "(Sample doc id)", //empty if document is uploaded
      "anonymize" : false //boolean
      }
  • Responses:
    • 200: Text anonymized successfully.

    • Data:

      {
      "session_id": "(session id or chat id)",
      "anonymized_prompt": "(Prompt by the user after anonymization)",
      "replaced_response": "(Response from LLM after replacement)",
      "anonymized_values": {
      "Emails": ["anon_email1", "anon_email2"],
      "Names": ["Anonymized Name1"],
      "Phone": ["Anonymized phone number1"]
      },
      "total_tokens": "34" //tokens consumed for the prompt
      }

6. Delete a Session

  • Method: DELETE
  • URL: /delete-session/{session_id}
  • Description: Delete a session/chat by its ID.
  • Parameters:
    • session_id (path, string, required): ID of the session/chat to be deleted.
  • Responses:
    • 200: Session deleted successfully.
    • 400: Invalid session ID.

7. Rename a Session

  • Method: POST
  • URL: /rename-session
  • Description: Rename an existing session/chat.
  • Parameters:
    • session_id (body, string, required): ID of the session to rename.

    • new_name (body, string, required): New name for the session.

      {
      "session_id" : "(session id to be renamed)",
      "new_name" : "(new name for this session)"
      }
  • Responses:
    • 200: Session renamed successfully.
    • 400: Invalid session ID or name.

8. Get Token Usage

  • Method: POST
  • URL: /get-token-usage
  • Description: Retrieve token usage data based on a date range for an organization.
  • Parameters:
    • start_date (body, string, required): Start date for the usage data (format: Unix timestamp in milliseconds).

    • end_date (body, string, required): End date for the usage data (format: Unix timestamp in milliseconds).

      {
      "start_date" : "2024-12-18T12:52:00Z",
      "end_date" : "2024-12-18T12:52:00Z"
      }
  • Responses:
    • 200: Token usage count retrieved successfully.
    • 400: Invalid date range.

9. Generate Image

  • Method: POST
  • URL: /generate-image
  • Description: Generate image based on prompt provided by user.
  • Parameters:
    • chat_id (body, string, optional): Chat id for image generation.

    • prompt (body, string, required): Prompt for image generation.

      {
      "chat_id" : "(Sample Chat id)",
      "prompt" : "Sample prompt for img gen"
      }
  • Responses:
    • 200: Token usage count retrieved successfully.

    • 400: Invalid date range.

      {     "chat_id" : "(Chat id provided)",
      "image_url" : "(Link to generated image)"
      }

Additional Notes:

  • session id and chat id are referring to the same entity and can be used interchangeably.
  • User specific data like email id and organization id are extracted from the authentication token itself.