bothive-sdk
v1.0.1
Published
The official BotHive SDK for building and deploying AI agents.
Downloads
16
Maintainers
Readme
bothive-sdk
Import your BotHive AI bots into any TypeScript or Node.js project.
Build bots with HiveLang on BotHive, deploy them, and use them anywhere.
Install
npm install bothive-sdkQuick Start
import { BothiveClient } from 'bothive-sdk';
const client = new BothiveClient({
apiKey: process.env.BOTHIVE_API_KEY!
});
// One-shot chat
const reply = await client.chat('What is HiveLang?', {
botId: 'your-bot-id'
});
console.log(reply.response);Multi-Turn Conversations
const bot = client.bot('your-bot-id');
const r1 = await bot.chat('My name is Alex');
console.log(r1.response); // "Nice to meet you, Alex!"
const r2 = await bot.chat('What is my name?');
console.log(r2.response); // "Your name is Alex!"
// Reset when needed
bot.clearHistory();Next.js API Route Example
// app/api/chat/route.ts
import { BothiveClient } from 'bothive-sdk';
import { NextRequest, NextResponse } from 'next/server';
const client = new BothiveClient({
apiKey: process.env.BOTHIVE_API_KEY!
});
export async function POST(req: NextRequest) {
const { message, botId } = await req.json();
const reply = await client.chat(message, { botId });
return NextResponse.json({ response: reply.response });
}React Component Example
'use client';
import { useState } from 'react';
export function ChatWidget({ botId }: { botId: string }) {
const [messages, setMessages] = useState<{ role: string; content: string }[]>([]);
const [input, setInput] = useState('');
const send = async () => {
setMessages(prev => [...prev, { role: 'user', content: input }]);
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: input, botId }),
});
const data = await res.json();
setMessages(prev => [...prev, { role: 'assistant', content: data.response }]);
setInput('');
};
return (
<div>
{messages.map((m, i) => (
<div key={i}>{m.role}: {m.content}</div>
))}
<input value={input} onChange={e => setInput(e.target.value)} />
<button onClick={send}>Send</button>
</div>
);
}List Your Bots
const bots = await client.listBots();
bots.forEach(bot => {
console.log(`${bot.name} (${bot.id}) - ${bot.status}`);
});Deploy a Bot Programmatically
const result = await client.deploy({
name: 'CustomerBot',
hivelangCode: `
bot CustomerBot {
instructions {
You are a friendly customer support agent.
Help users with their questions about billing and accounts.
}
capabilities [general.respond]
}
`,
description: 'Handles customer inquiries',
});
console.log(`Deployed! Bot ID: ${result.botId}`);API Reference
BothiveClient
| Method | Description |
|--------|-------------|
| chat(message, options?) | Send a one-shot message to a bot |
| bot(botId) | Get a Bot instance for multi-turn conversation |
| listBots() | List all your deployed bots |
| deploy(options) | Deploy a HiveLang bot |
Bot
| Method | Description |
|--------|-------------|
| chat(message) | Send a message (history tracked automatically) |
| clearHistory() | Reset conversation history |
| getHistory() | Get current conversation history |
Get Your API Key
- Sign in at bothive.cloud
- Go to Dashboard → Developer → API Keys
- Create a new key
- Add it to your
.env:
BOTHIVE_API_KEY=bh_your_key_hereLicense
MIT — BotHive Inc.
