@courseecho/ai-client-node
v1.2.0
Published
Node.js client for CourseEcho AI API. Server-side SDK for backend integrations.
Maintainers
Readme
@courseecho/ai-client-node
Node.js client for AI orchestrator - Backend integration for server-side AI queries.
Overview
Production-ready Node.js client with:
- Express/Koa middleware support
- AWS Lambda compatible
- Streaming responses
- Batch processing
- Full TypeScript support
- Zero external dependencies beyond @courseecho/ai-core-sdk
Installation
npm install @courseecho/ai-client-node @courseecho/ai-core-sdkQuick Start
import { AiClient } from '@courseecho/ai-client-node';
const client = new AiClient({
apiKey: 'your-api-key',
baseUrl: 'https://ai.courseecho.com'
});
const response = await client.query({
query: 'How do I get started with React?',
context: { pageType: 'course', entityId: 'react-101' }
});
console.log(response.answer);v2.1+ Features
Basic Query
const response = await client.query({
query: 'What is the difference between state and props?',
context: { pageType: 'lesson', entityId: 'lesson-456' },
userId: 'user-123'
});
console.log('Answer:', response.answer);
console.log('Confidence:', response.confidence);Streaming Responses
const stream = await client.queryStream({
query: 'Explain React hooks',
context: { pageType: 'course', entityId: 'react-101' }
});
stream.on('data', (chunk) => {
process.stdout.write(chunk);
});
stream.on('end', () => {
console.log('\n[Complete]');
});Usage Examples
Express Integration
import express from 'express';
import { AiClient } from '@courseecho/ai-client-node';
const app = express();
const client = new AiClient({ apiKey: 'your-api-key' });
app.post('/api/ask', async (req, res) => {
try {
const { query, courseId } = req.body;
const response = await client.query({
query,
context: { pageType: 'course', entityId: courseId },
userId: req.user?.id
});
res.json(response);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000);AWS Lambda
import { AiClient } from '@courseecho/ai-client-node';
const client = new AiClient({
apiKey: process.env.COURSEECHO_API_KEY
});
export const handler = async (event) => {
const { query, courseId } = JSON.parse(event.body);
const response = await client.query({
query,
context: { pageType: 'course', entityId: courseId }
});
return {
statusCode: 200,
body: JSON.stringify(response)
};
};Batch Processing
import { AiClient } from '@courseecho/ai-client-node';
const client = new AiClient({ apiKey: 'your-api-key' });
const queries = [
{ query: 'What is React?', courseId: 'react-101' },
{ query: 'What is Vue?', courseId: 'vue-101' },
{ query: 'What is Angular?', courseId: 'angular-101' }
];
const results = await Promise.all(
queries.map(q =>
client.query({
query: q.query,
context: { pageType: 'course', entityId: q.courseId }
})
)
);
results.forEach(r => console.log(r.answer));Configuration
const client = new AiClient({
apiKey: 'your-api-key', // Required
jwtToken: 'token', // Optional - use instead of apiKey
baseUrl: 'https://ai.courseecho.com', // Default
timeout: 30000, // 30s default
retries: 2, // Retry on failure
wordDelay: 28 // Typewriter effect (ms)
});Authentication
API Key (Recommended):
const client = new AiClient({ apiKey: 'your-api-key' });JWT Token:
const client = new AiClient({ jwtToken: user.token });Error Handling
try {
const response = await client.query({
query: 'Help me with React',
context: { pageType: 'course' }
});
} catch (error) {
if (error.code === 'QUOTA_EXCEEDED') {
console.log('Query quota exceeded');
} else if (error.code === 'UNAUTHORIZED') {
console.log('Invalid API key');
} else {
console.log('Error:', error.message);
}
}Support
- Docs: https://courseecho.com/docs
- Issues: https://github.com/COURSEECHO/courseecho-ai-widget-sdk/issues
- Email: [email protected]
License
MIT 2026 CourseEcho
