Node.js SDK
Learn how to integrate Suada with your Node.js applications
Overview
The Suada Node.js SDK provides a simple and intuitive way to interact with the Suada API. It includes built-in TypeScript support and handles all the complexity of making API requests, managing authentication, and parsing responses.
Prerequisites
- Node.js version 18.0.0 or higher
- A Suada API key
- npm or yarn package manager
Installation
Install the Suada Node.js SDK using npm:
Or using yarn:
Quick Start
Here’s a basic example to get you started:
Authentication
Setting up your API Key
We recommend storing your API key in environment variables:
Then load it in your application:
Core Concepts
Chat Messages
The chat endpoint is the primary way to interact with Suada. Each chat request can include:
- A message (required)
- Chat history (optional)
- Configuration options (optional)
Response Format
Chat responses include several key components:
Advanced Features
LangChain Integration
The SDK provides seamless integration with LangChain, allowing you to use Suada’s capabilities within your LangChain applications:
LangChain Best Practices
-
Tool Configuration
- Provide clear, specific descriptions for your tools
- Use appropriate temperature settings for your use case
- Consider implementing tool-specific error handling
-
Agent Setup
- Use structured prompts for consistent behavior
- Implement proper chat history management
- Consider using memory for maintaining context
-
Error Handling
- Implement proper error handling for both Suada and LangChain
- Consider retry logic for transient failures
- Log agent actions for debugging
-
Performance
- Reuse agent instances when possible
- Implement appropriate timeouts
- Consider caching for frequently used data
Passthrough Mode
Passthrough mode allows you to associate Suada conversations with your application’s user system:
Privacy Mode
Enable privacy mode to ensure sensitive information is handled with additional security:
Error Handling
The SDK provides typed errors for better error handling:
Best Practices
-
Environment Variables
- Store API keys and sensitive configuration in environment variables
- Use a package like
dotenv
to manage environment variables
-
Error Handling
- Always implement try-catch blocks around API calls
- Use the provided error types for specific error handling
- Log errors appropriately for debugging
-
TypeScript Usage
- Take advantage of built-in type definitions
- Enable strict mode in your TypeScript configuration
- Use type annotations for better code reliability
-
Response Processing
- Always check for the presence of optional fields before using them
- Handle missing data gracefully
- Consider implementing retry logic for failed requests
Configuration Options
Option | Type | Required | Description |
---|---|---|---|
apiKey | string | Yes | Your Suada API key |
baseUrl | string | No | Custom API endpoint (defaults to https://suada.ai/api/public) |
passthroughMode | boolean | No | Enable user-specific resources |
FAQ
How do I handle rate limiting?
The SDK automatically handles rate limiting by implementing exponential backoff. You can customize this behavior by implementing your own retry logic.
Can I use the SDK in a browser environment?
No, the SDK is designed for server-side Node.js applications only. For browser applications, use our REST API with appropriate CORS headers.
How do I maintain conversation context?
Use the chatHistory
parameter to maintain conversation context:
How can I debug API calls?
Enable debug logging by setting the DEBUG
environment variable:
Support
- Email Support: hello@suada.ai