Skip to main content

SDK Quickstart

Install the Nexatron SDK and send your first natural language query in under five minutes.

Installation

npm install @nexatron/chat

Create a Client

import { NexatronClient } from '@nexatron/chat';

const client = new NexatronClient({
token: process.env.NEXATRON_API_KEY,
baseUrl: 'https://api.nexatron.io', // or your self-hosted URL
});

Send Your First Query

const result = await client.sendMessage('What were total sales last quarter?');

console.log(result.sql);
// SELECT SUM(amount) AS total_sales
// FROM orders
// WHERE order_date >= '2026-01-01' AND order_date < '2026-04-01'

console.log(result.data);
// { rows: [{ total_sales: 1284350.00 }] }

console.log(result.content);
// "Total sales last quarter were $1,284,350.00, a 12% increase over Q4 2025."

Pass a conversationId in the options to keep context across follow-up questions:

const first = await client.sendMessage('Show revenue by region');

const followUp = await client.sendMessage('Which region grew the fastest?', {
conversationId: first.id,
});

React Provider and Hook

For React applications, wrap your app in the provider and use the useNexatronChat hook:

import { NexatronProvider, useNexatronChat } from '@nexatron/chat/react';

// Wrap your app
function App() {
return (
<NexatronProvider
config={{
baseUrl: 'https://api.nexatron.io',
token: embedToken, // minted server-side; see the React Widget guide
}}
>
<Dashboard />
</NexatronProvider>
);
}

// Use in any component
function Dashboard() {
const { sendMessage, messages, isLoading, error } = useNexatronChat();

const handleAsk = async () => {
await sendMessage('Top 10 customers by lifetime value');
};

return (
<div>
<button onClick={handleAsk} disabled={isLoading}>
Ask
</button>

{isLoading && <p>Thinking...</p>}
{error && <p role="alert">{error}</p>}

{messages.map((msg) => (
<div key={msg.id}>
{msg.role === 'user' ? (
<p><strong>You:</strong> {msg.content}</p>
) : (
<div>
<p>{msg.content}</p>
{msg.data && <table>{/* render msg.data rows */}</table>}
{msg.sql && <pre>{msg.sql}</pre>}
</div>
)}
</div>
))}
</div>
);
}

Next Steps