API Reference

Integrate Code Huddle chatbot into your website using either our default widget or by building a custom widget.

Integration Methods

Code Huddle offers two ways to integrate: use our ready-made default widget for quick setup, or build a custom widget for complete design control.

Default Widget

Quick integration with Code Huddle's pre-built widget. Perfect for most websites.

Best for: Quick deployment, minimal development

Custom Widget

Build your own widget using Code Huddle's API. Full design control.

Best for: Custom designs, framework-specific needs

Method 1: Default Widget Integration

Use Code Huddle's pre-built widget by adding the widget script to your website. The widget handles all API calls automatically.

What You Need

  • Widget Script URL: The URL where Code Huddle hosts the widget JavaScript file
  • API Key: Generated from your Code Huddle dashboard

Implementation

Add the Code Huddle widget script to your HTML. The widget will automatically fetch your chatbot settings and handle all API communication.

<script src="https://huddle-chatbot-frontend.vercel.app/widget.js"></script>
<script>
  CodeHuddleWidget.init({
    accessToken: 'YOUR_API_KEY',
    position: 'bottom-right',
    primaryColor: '#3b82f6'
  });
</script>

Note: The widget script URL is configured from your environment settings. Make sure NEXT_PUBLIC_WIDGET_SCRIPT_URL is set correctly in your environment variables.

How It Works

Once you add the script tag and initialize the widget:

  • • The widget automatically calls GET /api/v1/settings to fetch your chatbot configuration
  • • When users send messages, the widget calls POST /api/v1/chat/stream to get streaming AI responses
  • • All API calls are handled automatically by the widget
  • • No additional API integration code needed

Method 2: Custom Widget Integration

Build your own widget design by integrating directly with Code Huddle's API. You'll need to implement API calls to two endpoints.

What You Need

  • API Key: Generated from your Code Huddle dashboard
  • API Integration: Implement calls to the two endpoints below

Required API Endpoints

GET

/api/v1/settings

Fetch your chatbot configuration including name, welcome message, and avatar URL.

Headers
X-API-Key: {your_api_key}
Example Request
fetch('https://api.codehuddle.com/api/v1/settings', {
  method: 'GET',
  headers: {
    'X-API-Key': 'sk_live_your_api_key_here',
    'Content-Type': 'application/json'
  }
})
.then(response => response.json())
.then(data => {
  console.log(data.chatbot_name);
  console.log(data.welcome_message);
  console.log(data.avatar_url);
});
Response Example
{
  "chatbot_name": "Your Chatbot Name",
  "welcome_message": "Hello! How can I help?",
  "avatar_url": "https://example.com/avatar.png",
  "personality_tone": "Friendly & Helpful",
  ...
}
POST

/api/v1/chat/stream

Send user messages and receive streaming AI-powered responses from your knowledge base. Responses are delivered in real-time using Server-Sent Events (SSE).

Headers
X-API-Key: {your_api_key}
Content-Type: application/json
Request Body
{
  "message": "User's message",
  "conversation_id": "optional-uuid"
}

message (string, required): The user's message or question

conversation_id (string, optional): ID for continuing a conversation thread

Example Request
const response = await fetch('https://api.codehuddle.com/api/v1/chat/stream', {
  method: 'POST',
  headers: {
    'X-API-Key': 'sk_live_your_api_key_here',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    message: "What is your refund policy?",
    conversation_id: "optional-uuid"
  })
});

// Stream response using ReadableStream
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  
  const chunk = decoder.decode(value, { stream: true });
  // Parse SSE events: data: {"type":"token","message":"..."}
  // Handle event.type: 'token', 'complete', 'status', 'error'
}

Note: This endpoint returns Server-Sent Events (SSE). Parse data: lines and handle event types: token (streaming tokens), complete (final answer with conversation_id), status (status updates), and error (errors).

Getting Your API Key

Both integration methods require an API key for authentication. Generate your API key from the Code Huddle dashboard.

  1. Log in to your Code Huddle dashboard
  2. Navigate to API Keys in the sidebar
  3. Click Generate New Key
  4. Provide a name for your key and set expiration (optional)
  5. Copy the full API key immediately (you'll only see it once)
  6. Use this key in your widget configuration or API requests

⚠️ Important: Store your API key securely. Never expose it in publicly accessible client-side code. Use environment variables or server-side proxies in production.