Skip to main content

API Quickstart Guide

This guide will help you make your first API request to NeuralTalk AI in just a few minutes. Follow these steps to quickly integrate our conversational AI capabilities into your application.

Prerequisites

Before you begin, you'll need:

  • A NeuralTalk AI account (sign up at neuraltalk.ai if you don't have one)
  • Basic familiarity with RESTful APIs and JSON
  • A tool for making API requests (curl, Postman, or your preferred programming language)

Step 1: Get Your API Key

  1. Log in to your NeuralTalk AI Dashboard
  2. Navigate to Settings > API
  3. Click Generate API Key
  4. Copy and securely store your API key

Your API key should be kept confidential and not exposed in client-side code.

Step 2: Make Your First API Request

Let's start by getting a list of your chatbots. Open your terminal or API client and run:

curl -X GET "https://api.neuraltalk.ai/v1/chatbots" \
-H "Authorization: Bearer YOUR_API_KEY"

Replace YOUR_API_KEY with the API key you generated.

You should receive a response like this:

{
"status": "success",
"data": {
"chatbots": [
{
"id": "bot_123abc",
"name": "Customer Support Bot",
"created_at": "2023-04-15T10:30:45Z",
"status": "active"
}
],
"total": 1,
"page": 1,
"limit": 10
}
}

Step 3: Send a Message

Let's send a message to one of your chatbots:

  1. First, create a new conversation:
curl -X POST "https://api.neuraltalk.ai/v1/conversations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatbot_id": "bot_123abc",
"user_id": "user_456"
}'

This will return a new conversation ID:

{
"status": "success",
"data": {
"conversation_id": "conv_789xyz",
"created_at": "2023-06-20T14:22:33Z"
}
}
  1. Now, send a message to this conversation:
curl -X POST "https://api.neuraltalk.ai/v1/conversations/conv_789xyz/messages" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "What services do you offer?",
"user_id": "user_456"
}'

The API will respond with the bot's reply:

{
"status": "success",
"data": {
"message_id": "msg_abc123",
"conversation_id": "conv_789xyz",
"text": "We offer a range of services including web development, mobile app development, and digital marketing. Our team specializes in creating custom solutions tailored to your business needs. Would you like more information about any specific service?",
"sender_type": "bot",
"sent_at": "2023-06-20T14:22:45Z"
}
}

Step 4: Retrieve Conversation History

To get the full conversation history:

curl -X GET "https://api.neuraltalk.ai/v1/conversations/conv_789xyz/messages" \
-H "Authorization: Bearer YOUR_API_KEY"

This returns all messages in the conversation:

{
"status": "success",
"data": {
"messages": [
{
"message_id": "msg_def456",
"conversation_id": "conv_789xyz",
"text": "What services do you offer?",
"sender_type": "user",
"user_id": "user_456",
"sent_at": "2023-06-20T14:22:33Z"
},
{
"message_id": "msg_abc123",
"conversation_id": "conv_789xyz",
"text": "We offer a range of services including web development, mobile app development, and digital marketing. Our team specializes in creating custom solutions tailored to your business needs. Would you like more information about any specific service?",
"sender_type": "bot",
"sent_at": "2023-06-20T14:22:45Z"
}
],
"total": 2,
"page": 1,
"limit": 50
}
}

Step 5: Integrate into Your Application

Now that you've seen the basics, you can integrate the API into your application using your preferred programming language.

JavaScript/Node.js Example

const axios = require('axios');

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://api.neuraltalk.ai/v1';

async function sendMessage(conversationId, text, userId) {
try {
const response = await axios.post(
`${BASE_URL}/conversations/${conversationId}/messages`,
{
text,
user_id: userId
},
{
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
}
);
return response.data;
} catch (error) {
console.error('Error sending message:', error.response ? error.response.data : error.message);
throw error;
}
}

// Example usage
sendMessage('conv_789xyz', 'Tell me about your pricing', 'user_456')
.then(response => console.log('Bot response:', response.data.text))
.catch(err => console.error('Failed to send message:', err));

Python Example

import requests

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://api.neuraltalk.ai/v1'

def send_message(conversation_id, text, user_id):
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
payload = {
'text': text,
'user_id': user_id
}
response = requests.post(
f'{BASE_URL}/conversations/{conversation_id}/messages',
json=payload,
headers=headers
)
response.raise_for_status()
return response.json()

# Example usage
try:
result = send_message('conv_789xyz', 'Tell me about your pricing', 'user_456')
print(f"Bot response: {result['data']['text']}")
except requests.exceptions.RequestException as e:
print(f"Failed to send message: {e}")

Next Steps

Now that you've made your first API requests, you can:

  1. Explore our complete API reference for detailed information on all endpoints
  2. Learn about webhook integration for real-time notifications
  3. Check out our API use cases for inspiration

Need Help?

If you encounter any issues or have questions, our developer support team is ready to assist. Contact us at [email protected].