> ## Documentation Index
> Fetch the complete documentation index at: https://chatbase.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# REST API Integration

> Complete guide to integrating Chatbase AI Agents using our REST API for custom integrations and applications.

<Note>
  **Looking for API v2?** The new Chatbase API v2 features structured error codes, cursor-based pagination, and SSE streaming. Note that API v2 is available starting from the Standard Plan. [Check out the API v2 Reference →](/api-v2/overview)
</Note>

## Overview

The Chatbase REST API enables you to integrate AI-powered conversations into any application or workflow. Build custom chat experiences, automate customer interactions, and manage your AI agents programmatically.

<CardGroup cols={3}>
  <Card title="Send Messages" icon="message-dots">
    Chat with your AI agents and handle real-time streaming responses
  </Card>

  <Card title="Manage Agents" icon="robot">
    Create, configure, and update AI agents with custom training data
  </Card>

  <Card title="Access Data" icon="database">
    Retrieve conversations, leads, and analytics from your AI interactions
  </Card>
</CardGroup>

## Quick Start

<Steps>
  <Step title="Get Your API Key">
    <Frame>
      <img src="https://mintcdn.com/chatbase/-HHbinxDlwZUQ3Jt/developer-guides/images/api-integration/create-api-key.png?fit=max&auto=format&n=-HHbinxDlwZUQ3Jt&q=85&s=b612070a227667e9fd54a4047bcf2f9e" alt="Creating API key in Chatbase dashboard" width="1920" height="936" data-path="developer-guides/images/api-integration/create-api-key.png" />
    </Frame>

    1. Visit your [Chatbase Dashboard](https://www.chatbase.co/dashboard)
    2. Navigate to **Workspace Settings** → **API Keys**
    3. Click **Create API Key** and copy the generated key

    <Warning>
      Store your API key securely and never expose it in client-side code.
    </Warning>
  </Step>

  <Step title="Get Your Agent ID">
    <Frame>
      <img src="https://mintcdn.com/chatbase/-HHbinxDlwZUQ3Jt/developer-guides/images/api-integration/get-agent-id.png?fit=max&auto=format&n=-HHbinxDlwZUQ3Jt&q=85&s=8c6dd8d9516be295e68c89746b973c8a" alt="Finding Agent ID in Chatbase settings" width="1924" height="934" data-path="developer-guides/images/api-integration/get-agent-id.png" />
    </Frame>

    1. Select your AI Agent in the dashboard
    2. Go to **Settings** → **General**
    3. Copy the **Chatbot ID** (UUID format)
  </Step>

  <Step title="Send Your First Message">
    Test your integration with a simple chat request:

    ```bash theme={null}
    curl -X POST 'https://www.chatbase.co/api/v1/chat' \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      -H 'Content-Type: application/json' \
      -d '{
        "messages": [{"content": "Hello! How can you help me?", "role": "user"}],
        "chatbotId": "your-chatbot-id-here"
      }'
    ```

    **Expected Response:**

    ```json theme={null}
    {
      "text": "Hello! I'm here to help answer your questions and assist with any information you need. What can I help you with today?"
    }
    ```
  </Step>
</Steps>

### Chat API Streaming

The [chat API](/api-reference/chat) supports real-time streaming responses for better user experience.

<CodeGroup>
  ```javascript Node.js theme={null}
  // streamer.js

  const axios = require('axios')
  const {Readable} = require('stream')

  const apiKey = '<Your-Secret-Key>'
  const chatId = '<Your Chatbot ID>'
  const apiUrl = 'https://www.chatbase.co/api/v1/chat'

  const messages = [{content: '<Your query here>', role: 'user'}]

  const authorizationHeader = `Bearer ${apiKey}`

  async function readChatbotReply() {
    try {
      const response = await axios.post(
        apiUrl,
        {
          messages,
          chatId,
          stream: true,
          temperature: 0,
        },
        {
          headers: {
            Authorization: authorizationHeader,
            'Content-Type': 'application/json',
          },
          responseType: 'stream',
        }
      )

      const readable = new Readable({
        read() {},
      })

      response.data.on('data', (chunk) => {
        readable.push(chunk)
      })

      response.data.on('end', () => {
        readable.push(null)
      })

      const decoder = new TextDecoder()
      let done = false

      readable.on('data', (chunk) => {
        const chunkValue = decoder.decode(chunk)

        // Process the chunkValue as desired
        // Here we just output it as in comes in without \n
        process.stdout.write(chunkValue)
      })

      readable.on('end', () => {
        done = true
      })
    } catch (error) {
      console.log('Error:', error.message)
    }
  }

  readChatbotReply()
  ```

  ```python Python theme={null}
  ## streamer.py

  import requests

  api_url = 'https://www.chatbase.co/api/v1/chat'
  api_key = '<Your-Secret-Key>'
  chat_id = '<Your Chatbot ID>'

  messages = [
      { 'content': '<Your query here>', 'role': 'user' }
  ]

  authorization_header = f'Bearer {api_key}'

  def read_chatbot_reply():
      try:
          headers = {
              'Authorization': authorization_header,
              'Content-Type': 'application/json'
          }

          data = {
              'messages': messages,
              'chatId': chat_id,
              'stream': True,
              'temperature': 0
          }

          response = requests.post(api_url, json=data, headers=headers, stream=True)
          response.raise_for_status()

          decoder = response.iter_content(chunk_size=None)
          for chunk in decoder:
              chunk_value = chunk.decode('utf-8')
              print(chunk_value, end='', flush=True)

      except requests.exceptions.RequestException as error:
          print('Error:', error)

  read_chatbot_reply()
  ```
</CodeGroup>

## Performance Best Practices

<Tip>
  **Optimization Strategies:**

  * Use streaming for chat responses to improve perceived performance
  * Cache agent responses when appropriate
  * Batch multiple operations when possible
  * Monitor and optimize conversation context length
</Tip>

## 🚀 Try It Live!

Ready to see the magic in action? Dive straight into our interactive playground where you can test every API endpoint, experiment with real responses, and build your integration in real-time.

<CardGroup cols={1}>
  <Card title="🎮 Launch Interactive Playground" icon="play" href="/api-reference">
    Test APIs instantly • No setup required • Real-time responses • Copy working code snippets
  </Card>
</CardGroup>

### Key API Endpoints

<CardGroup cols={2}>
  <Card title="Chat API" icon="message-dots" href="/api-reference/chat/chat-with-a-chatbot">
    Send messages and receive AI responses with streaming support
  </Card>

  <Card title="Agent Management" icon="robot" href="/api-reference/chatbots/create-a-new-chatbot">
    Create, update, and configure AI agents programmatically
  </Card>

  <Card title="Conversations" icon="messages" href="/api-reference/conversations/get-conversations-for-a-chatbot">
    Access chat history and conversation analytics
  </Card>

  <Card title="Contacts" icon="users" href="/api-reference/contacts/create-contacts-for-a-chatbot">
    Create and manage contacts for your AI agents
  </Card>
</CardGroup>
