Build Your First AI-Powered Application
This guide will walk you through creating your first Trainly-powered application that can answer questions about your documents.By the end of this guide, you’ll have a working document Q&A system with less than 20 lines of code.
Step 1: Create Your Knowledge Base
1
Sign Up
Create a free account at trainlyai.com
2
Create a Chat
Click “New Chat” to create your first knowledge base
3
Upload Documents
Upload PDFs, DOCX, TXT, or other documents. Trainly will automatically:
- Extract text content
- Create semantic chunks
- Generate embeddings
- Build a searchable graph
4
Test It
Try asking questions in the chat interface to verify your documents are indexed correctly
Step 2: Enable API Access
1
Open Settings
Click the settings icon in your chat
2
Configure Your Settings
- Choose your preferred AI model (GPT-4o-mini recommended)
- Set temperature and max tokens
- Add a custom prompt (optional)
- Select which documents to include
3
Publish Settings
Click “Publish Settings” - this makes your configuration available to the API
4
Enable API Access
Toggle “Enable API Access” and click “Generate API Key”
5
Copy Your Credentials
Save your API key (starts with
tk_) and chat IDStep 3: Make Your First Query
Choose your preferred language and make your first API call:Step 4: Add Streaming (Optional)
Make your app more responsive with real-time streaming:What You’ve Built
Congratulations! You now have:Knowledge Base
Your documents indexed and searchable via semantic search
AI Integration
AI models that can answer questions about your content
Citation System
Answers backed by source citations with relevance scores
API Access
Full programmatic access to query your knowledge base
Next Steps
Now that you have the basics working, explore more advanced features:Enhance Your Application
Add File Uploads
Allow users to upload their own documents
Implement Streaming
Add real-time streaming for better UX
Use Scope Filters
Segment data for multi-tenant apps
Optimize Costs
Choose the right models and cache responses
Complete Tutorials
- Web App
- Support Bot
- Research Tool
- Slack Bot
Build a Document Chat InterfaceCreate a full-featured chat application with:
- Real-time streaming responses
- File upload with drag & drop
- Citation display
- Conversation history
Common First Steps
Upload More Documents
List Your Files
Try Different Models
Troubleshooting
API Key Not Working
API Key Not Working
Check these:
- API key starts with
tk_ - API access is enabled in chat settings
- Chat settings are published
- Using correct chat ID
Empty or Generic Responses
Empty or Generic Responses
Possible causes:
- No documents uploaded
- Documents not processed yet (takes 10-30 seconds)
- Published settings don’t include your documents
- Question not relevant to your content
Rate Limit Errors
Rate Limit Errors
Default limits:
- 60 requests/minute per API key
Authentication Errors
Authentication Errors
Check:
- API key is valid and not expired
- Using correct authorization header format:
Authorization: Bearer tk_your_key - Chat has API access enabled
Example Projects
Get inspired by complete working examples:Next.js Chat App
Full-featured document chat with streaming and file upload
Python CLI Tool
Command-line interface for document Q&A
Customer Support Bot
Automated support system with Flask backend
Research Assistant
Academic paper analysis and literature review tool
Resources
JavaScript SDK
Complete JS/TS guide
Python SDK
Complete Python guide
API Reference
REST API docs
Authentication
Auth methods
Best Practices
Production tips
Examples
Real-world code
Get Help
Join the Community
Ask questions, share projects, and get help from the Trainly team and community
- 📧 Email: support@trainlyai.com
- 💬 Discord: Join our server
- 🐙 GitHub: Report issues
- 📚 Docs: You’re already here!