📄 MyAI Builder API Documentation

#Jump to Getting Started Section#MyAI Builder Dashboard

Base URL

https://snugly.cloud/services/aibuilder/api

Authentication

All requests require an API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

You can find your API key in your MyAI Builder dashboard.

1. Chat with an Agent

Endpoint: POST https://snugly.cloud/services/aibuilder/api/

Request Parameters:
Field Type Required Description
messagestring✅ YesThe text prompt you want the AI to respond to.
sessionidstring✅ YesUnique session identifier for keeping conversation memory.
max_tokensintegerOptionalMaximum tokens in the AI’s response (default: 512).
Example Request:
curl -X POST https://snugly.cloud/services/aibuilder/api/ \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello AI!", "sessionid": "unique-session-id"}'
<?php
$ch = curl_init('https://snugly.cloud/services/aibuilder/api/');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer YOUR_API_KEY',
  'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
  'message' => 'Hello AI!',
  'sessionid' => 'unique-session-id'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
fetch('https://snugly.cloud/services/aibuilder/api/', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ message: 'Hello AI!', sessionid: 'unique-session-id' })
})
.then(res => res.json())
.then(data => console.log(data));
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
}

data = {
    'message': 'Hello AI!',
    'sessionid': 'unique-session-id'
}

response = requests.post('https://snugly.cloud/services/aibuilder/api/', headers=headers, json=data)
print(response.json())
Example Response:
{
  "status": "success",
  "reply": "Hello! How can I assist you today?",
  "credit_used": "0.50000000"
}
Error Responses:
Code Meaning
400Invalid request format
401Missing or invalid API key
429Rate limit exceeded
500Server error

Rate Limits

Best Practices


You can use Simple API Tester (our tool) to test api call

Getting Started with MyAI Builder

Welcome! This guide will help you quickly integrate your AI assistant using MyAI Builder’s API. Whether you’re a beginner or an experienced developer, you’ll find ready-to-use code snippets in JavaScript and PHP to get you started fast.

Step 1: Get Your API Credentials

Before you begin, make sure you have your API Key. You’ll need to replace the placeholders in the example code with your actual credentials.

Step 2: JavaScript (Browser) Quick Start

Use this JavaScript example to add your AI assistant to any web page. It works directly in the browser with no extra setup.


  <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>MyAI Builder - Chat Example</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body { background-color: #f8f9fa; }
    .chat-box { max-width: 600px; margin: 30px auto; background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); }
    .chat-messages { height: 400px; overflow-y: auto; padding: 15px; border-bottom: 1px solid #dee2e6; }
    .message { padding: 10px 15px; border-radius: 15px; margin-bottom: 10px; max-width: 80%; }
    .user-msg { background-color: #d1e7dd; align-self: flex-end; }
    .ai-msg { background-color: #e2e3e5; align-self: flex-start; }
    .message-container { display: flex; flex-direction: column; }
  </style>
</head>
<body>

<div class="chat-box">
  <div class="p-3 border-bottom bg-primary text-white rounded-top">
    <h4 class="mb-0">MyAI Builder Assistant</h4>
  </div>

  <div id="chatMessages" class="chat-messages message-container"></div>

  <div class="p-3">
    <div class="input-group">
      <input type="text" id="userInput" class="form-control" placeholder="Type your message...">
      <button id="sendBtn" class="btn btn-primary">Send</button>
    </div>
  </div>
</div>

<!-- Bootstrap JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

<script>
  // ===== CONFIGURATION =====
  const API_URL = "https://snugly.cloud/services/aibuilder/api/"; // Replace with your actual endpoint
  const API_KEY = "YOUR_API_KEY"; // Replace with your real API key
   const SESSION_ID = "example-session-123"; // Optional: use your own session ID for memory

  const chatMessages = document.getElementById("chatMessages");
  const userInput = document.getElementById("userInput");
  const sendBtn = document.getElementById("sendBtn");

  // Helper: add message to chat UI
  function addMessage(text, isUser = false) {
    const msg = document.createElement("div");
    msg.classList.add("message", isUser ? "user-msg" : "ai-msg");
    msg.classList.add("message", isUser ? "align-self-end" : "align-self-start");
    msg.textContent = text;
    chatMessages.appendChild(msg);
    chatMessages.scrollTop = chatMessages.scrollHeight;
  }

  // Send message to API
  async function sendMessage() {
    const text = userInput.value.trim();
    if (!text) return;

    addMessage(text, true);
    userInput.value = "";

    // Temporary "thinking" message
    const thinkingMsg = document.createElement("div");
    thinkingMsg.classList.add("message", "ai-msg");
    thinkingMsg.textContent = "Thinking...";
    chatMessages.appendChild(thinkingMsg);
    chatMessages.scrollTop = chatMessages.scrollHeight;

    try {
      const res = await fetch(API_URL, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        },
        body: JSON.stringify({
          message: text,
          sessionid: SESSION_ID
        })
      });

      const data = await res.json();
      thinkingMsg.remove();
      addMessage(data.reply || "(No reply received)");
    } catch (err) {
      thinkingMsg.remove();
      addMessage("Error: " + err.message);
    }
  }

  // Event listeners
  sendBtn.addEventListener("click", sendMessage);
  userInput.addEventListener("keypress", (e) => {
    if (e.key === "Enter") sendMessage();
  });
</script>

</body>
</html>
  

How it works


Step 3: PHP Quick Start

This PHP example is perfect if you want to run your AI assistant from a server or embed it in a backend-powered website.


  <?php
// ===== CONFIGURATION =====
$API_URL   = "https://snugly.cloud/services/aibuilder/api/"; // Replace with your actual endpoint
$API_KEY   = "YOUR_API_KEY"; // Replace with your real API key
$SESSION_ID = "example-session-123"; // Optional: use your own session ID for memory

$responseText = "";
$userMessage  = "";

// Handle form submit
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['message'])) {
    $userMessage = trim($_POST['message']);

    // Prepare payload
    $payload = json_encode([
        "message"   => $userMessage,
        "sessionid" => $SESSION_ID
    ]);

    // cURL to API
    $ch = curl_init($API_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Content-Type: application/json",
        "Authorization: Bearer {$API_KEY}"
    ]);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

    $apiResult = curl_exec($ch);
    $error     = curl_error($ch);
    curl_close($ch);

    if ($error) {
        $responseText = "Error: $error";
    } else {
        $data = json_decode($apiResult, true);
        if (isset($data['reply'])) {
            $responseText = is_array($data['reply']) ? implode("\n", $data['reply']) : $data['reply'];
        } elseif (isset($data['message'])) {
            $responseText = $data['message'];
        } else {
            $responseText = "(No reply received)";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyAI Builder - PHP Chat Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
    body { background-color: #f8f9fa; }
    .chat-box { max-width: 700px; margin: 30px auto; background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); }
    .chat-messages { min-height: 200px; padding: 15px; border-bottom: 1px solid #dee2e6; }
    .message { padding: 10px 15px; border-radius: 15px; margin-bottom: 10px; max-width: 80%; }
    .user-msg { background-color: #d1e7dd; margin-left: auto; }
    .ai-msg { background-color: #e2e3e5; margin-right: auto; }
</style>
</head>
<body>

<div class="chat-box">
    <div class="p-3 border-bottom bg-primary text-white rounded-top">
        <h4 class="mb-0">MyAI Builder Assistant (PHP)</h4>
    </div>

    <div class="chat-messages">
        <?php if ($userMessage): ?>
            <div class="message user-msg"><?php echo htmlspecialchars($userMessage); ?></div>
        <?php endif; ?>

        <?php if ($responseText): ?>
            <div class="message ai-msg"><?php echo nl2br(htmlspecialchars($responseText)); ?></div>
        <?php endif; ?>
    </div>

    <div class="p-3">
        <form method="post" class="d-flex">
            <input type="text" name="message" class="form-control me-2" placeholder="Type your message..." autocomplete="off" required>
            <button type="submit" class="btn btn-primary">Send</button>
        </form>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
  

How it works


Next Steps

Once you have the basics working, you can:

For more detailed guides and sample projects, visit our Code Samples page.