Skip to content

FluxbaseAI

Fluxbase AI client for listing chatbots and managing conversations

const ai = new FluxbaseAI(fetchClient, 'ws://localhost:8080')
// List available chatbots
const { data, error } = await ai.listChatbots()
// Create a chat connection
const chat = ai.createChat({
token: 'my-jwt-token',
onContent: (delta) => process.stdout.write(delta),
})
await chat.connect()
const convId = await chat.startChat('sql-assistant')
chat.sendMessage(convId, 'Show me recent orders')

new FluxbaseAI(fetch, wsBaseUrl): FluxbaseAI

Parameter Type
fetch { delete: (path) => Promise<void>; get: <T>(path) => Promise<T>; patch: <T>(path, body?) => Promise<T>; }
fetch.delete (path) => Promise<void>
fetch.get <T>(path) => Promise<T>
fetch.patch <T>(path, body?) => Promise<T>
wsBaseUrl string

FluxbaseAI

createChat(options): FluxbaseAIChat

Create a new AI chat connection

Parameter Type Description
options Omit<AIChatOptions, "wsUrl" | "_lookupChatbot"> Chat connection options

FluxbaseAIChat

FluxbaseAIChat instance


deleteConversation(id): Promise<{ error: Error | null; }>

Delete a conversation

Parameter Type Description
id string Conversation ID

Promise<{ error: Error | null; }>

Promise resolving to { error } (null on success)

const { error } = await ai.deleteConversation('conv-uuid-123')
if (!error) {
console.log('Conversation deleted')
}

getChatbot(id): Promise<{ data: AIChatbotSummary | null; error: Error | null; }>

Get details of a specific chatbot

Parameter Type Description
id string Chatbot ID

Promise<{ data: AIChatbotSummary | null; error: Error | null; }>

Promise resolving to { data, error } tuple with chatbot details


getConversation(id): Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>

Get a single conversation with all messages

Parameter Type Description
id string Conversation ID

Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>

Promise resolving to { data, error } tuple with conversation detail

const { data, error } = await ai.getConversation('conv-uuid-123')
if (data) {
console.log(`Title: ${data.title}`)
console.log(`Messages: ${data.messages.length}`)
}

getUsage(chatbotId): Promise<{ data: AIDailyQuotaSnapshot | null; error: Error | null; }>

Get the current user’s daily quota for a chatbot (Ask 2).

Returns requests used/limit and tokens used/limit, plus the RFC3339 timestamp of when the counters reset. Best-effort: counters are in-memory and reset on server restart; per-instance in multi-replica deployments.

For per-turn updates without an extra round-trip, read daily_quota from the onDone callback’s third argument.

Parameter Type Description
chatbotId string Chatbot ID

Promise<{ data: AIDailyQuotaSnapshot | null; error: Error | null; }>

Promise resolving to { data, error } with the quota snapshot

const { data, error } = await ai.getUsage('chatbot-uuid')
if (data) {
console.log(`${data.requests.limit - data.requests.used} requests left today`)
console.log(`${data.tokens.limit - data.tokens.used} tokens left today`)
}

listChatbots(namespace?): Promise<{ data: AIChatbotSummary[] | null; error: Error | null; }>

List available chatbots (public, enabled)

Parameter Type
namespace? string

Promise<{ data: AIChatbotSummary[] | null; error: Error | null; }>

Promise resolving to { data, error } tuple with array of chatbot summaries


listConversations(options?): Promise<{ data: ListConversationsResult | null; error: Error | null; }>

List the authenticated user’s conversations

Parameter Type Description
options? ListConversationsOptions Optional filters and pagination

Promise<{ data: ListConversationsResult | null; error: Error | null; }>

Promise resolving to { data, error } tuple with conversations

// List all conversations
const { data, error } = await ai.listConversations()
// Filter by chatbot
const { data, error } = await ai.listConversations({ chatbot: 'sql-assistant' })
// With pagination
const { data, error } = await ai.listConversations({ limit: 20, offset: 0 })

lookupChatbot(name): Promise<{ data: AIChatbotLookupResponse | null; error: Error | null; }>

Lookup a chatbot by name with smart namespace resolution

Resolution logic:

  1. If exactly one chatbot with this name exists -> returns it
  2. If multiple exist -> tries “default” namespace first
  3. If multiple exist and none in “default” -> returns ambiguous=true with namespaces list
Parameter Type Description
name string Chatbot name

Promise<{ data: AIChatbotLookupResponse | null; error: Error | null; }>

Promise resolving to { data, error } tuple with lookup result

// Lookup chatbot by name
const { data, error } = await ai.lookupChatbot('sql-assistant')
if (data?.chatbot) {
console.log(`Found in namespace: ${data.chatbot.namespace}`)
} else if (data?.ambiguous) {
console.log(`Chatbot exists in: ${data.namespaces?.join(', ')}`)
}

updateConversation(id, updates): Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>

Update a conversation (currently supports title update only)

Parameter Type Description
id string Conversation ID
updates UpdateConversationOptions Fields to update

Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>

Promise resolving to { data, error } tuple with updated conversation

const { data, error } = await ai.updateConversation('conv-uuid-123', {
title: 'My custom conversation title'
})