Skip to main content
Version: Latest

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({
apiKey: process.env.NEXATRON_API_KEY,
baseUrl: 'https://api.nexatron.dev', // or your self-hosted URL
});

Send Your First Query

const result = await client.query('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);
// [{ total_sales: 1_284_350.00 }]

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

Handle Streaming Responses

For long-running queries, use streaming to show results as they arrive:

const stream = client.queryStream('Show monthly revenue trends for 2025');

stream.on('stage', (stage) => {
// Pipeline stages: "planning" | "resolving" | "generating" | "executing" | "summarizing"
console.log(`Stage: ${stage.name} - ${stage.message}`);
});

stream.on('sql', (sql) => {
console.log('Generated SQL:', sql);
});

stream.on('data', (rows) => {
console.log('Results:', rows);
});

stream.on('summary', (text) => {
console.log('Summary:', text);
});

stream.on('done', (result) => {
// Full result object with sql, data, summary, metadata
console.log('Conversation ID:', result.conversationId);
});

stream.on('error', (err) => {
console.error('Query failed:', err.message);
});

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 apiKey={process.env.NEXT_PUBLIC_NEXATRON_API_KEY}>
<Dashboard />
</NexatronProvider>
);
}

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

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

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

{stage && <p>Processing: {stage.name}...</p>}

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

Conversation Context

Queries within a conversation automatically have context. Follow-up questions reference previous results:

const chat = client.conversation();

await chat.query('Show revenue by region');
// Returns revenue breakdown by region

await chat.query('Which region grew the fastest?');
// Automatically references the previous result set

await chat.query('Drill into that region by month');
// Continues the conversation with full context

Next Steps