Development Environment
Get your development environment ready to build with Trainly’s API and SDKs.Prerequisites:
- Node.js 18+ or Python 3.8+ (depending on your stack)
- A Trainly account with an active chat
- API key and chat ID from your Trainly dashboard
Environment Setup
JavaScript/TypeScript Projects
1
Install the SDK
2
Create Environment File
Create a
.env.local file in your project root:3
Initialize the Client
4
Test Your Setup
Python Projects
1
Create Virtual Environment
2
Install the SDK
3
Create Environment File
Create a Install python-dotenv:
.env file in your project root:4
Initialize the Client
5
Test Your Setup
Project Structure
Recommended Structure for Web Apps
Recommended Structure for Python Apps
Configuration Best Practices
Separate Environments
Use different credentials for development and production:Config File Pattern
Local Testing
Test Script (JavaScript)
Test Script (Python)
Development Tools
VS Code Extensions
Recommended extensions for Trainly development:- Thunder Client - Test API endpoints directly in VS Code
- REST Client - HTTP requests in
.httpfiles - Better Comments - Highlight TODO, FIXME, etc.
- Error Lens - Inline error messages
- GitLens - Git integration
HTTP Client Testing
Create atrainly.http file for quick API testing:
Debugging
Enable Debug Mode
Common Development Issues
CORS Errors (Browser)
CORS Errors (Browser)
Problem: Getting CORS errors when calling Trainly from the browserSolution: Never call Trainly API directly from the browser with your API key. Instead:
- Create a server-side API route
- Frontend calls your API route
- Your API route calls Trainly
Module Not Found
Module Not Found
Problem:
Error: Cannot find module '@trainly/react'Solution:401 Unauthorized
401 Unauthorized
Empty Responses
Empty Responses
Problem: API returns empty or generic answersSolution:
- Verify documents are uploaded
- Wait 10-30 seconds after upload for processing
- Check published settings include your documents
- Try a more specific question
- Check scope filters aren’t too restrictive
Testing
Unit Testing Setup
Integration Testing
Create a separate test environment:Docker Development
Dockerfile
Docker Compose
Hot Reload Development
Next.js
Next.js automatically reloads on changes. No configuration needed!Express.js with Nodemon
Python with Watchdog
Deployment
Environment Variables
Set these in your deployment platform:| Variable | Description | Example |
|---|---|---|
TRAINLY_API_KEY | Your API key | tk_prod_key_123 |
TRAINLY_CHAT_ID | Your chat ID | chat_prod_abc123 |
NODE_ENV | Environment | production |