Prerequisites
Before you begin, make sure you have:- Node.js 16.0.0 or higher installed
- A Thred API key (get one at https://thred.ai)
Setup Guide
Generate Your First Response
Use the Run your code:You should see an AI-generated response about productivity tools, along with brand recommendations and affiliate links!
answer() method to generate an AI response:index.ts
Add Streaming (Optional)
For better user experience with long responses, use streaming to display the response in real-time:
streaming.ts
Streaming is ideal for longer responses as it provides immediate feedback to users. The
answerStream() method calls your callback with accumulated text as it arrives.Complete Example
Here’s a complete example that demonstrates both streaming and non-streaming responses:complete-example.ts
Advanced Features
Conversation Context
Maintain context across multiple messages:Previous Messages
Provide explicit conversation history:Using Async Generators
For more control over streaming:Error Handling
Implement robust error handling for production applications:Next Steps
Congratulations! You’ve successfully generated your first AI-powered response with Thred SDK. Here’s what to explore next:API Reference
Explore all available methods and configuration options
Streaming Responses
Learn advanced streaming patterns and best practices
Conversation Context
Maintain context across multiple interactions
Error Handling
Implement robust error handling for production apps
