Best Practices
Follow these guidelines to build reliable, efficient, and cost-effective applications with Assisters API.API Key Security
Use Environment Variables
Never hardcode API keys in source code
Rotate Regularly
Create new keys and revoke old ones periodically
Separate Environments
Use different keys for dev, staging, and production
Restrict Domains
Set allowed domains for client-side usage
Error Handling
Always handle errors gracefully:Prompt Engineering
Use System Messages
Set consistent behavior with system messages:Be Specific
Provide Examples
Performance Optimization
Enable Streaming
For better UX in chat applications:Batch Requests
For embeddings and moderation, batch multiple inputs:Cache Results
Don’t re-request the same data:Cost Management
Set Token Limits
Choose the Right Model
| Task | Recommended Model | Why |
|---|---|---|
| Simple Q&A | phi-3-mini | Cheapest, fastest |
| General chat | llama-3.1-8b | Best value |
| Complex reasoning | llama-3.1-70b | Highest quality |
Monitor Usage
Reliability
Implement Timeouts
Use Idempotency Keys
For critical operations:Implement Circuit Breakers
Content Safety
Moderate Inputs
Validate Outputs
Logging & Monitoring
Log Important Data
Track Metrics
Key metrics to monitor:- Request latency
- Token usage
- Error rates
- Cost per request