Skip to main content

Model Selection

Choosing the right model can significantly impact cost and quality.

Task-Based Recommendations

Cost Tiers

Cost Optimization

1. Use Smaller Models First

2. Set max_tokens

Always set a reasonable max_tokens limit:

3. Optimize Prompts

4. Batch Similar Requests

Performance Optimization

5. Use Streaming for UX

Streaming improves perceived performance:

6. Choose Fast Models for Interactive Use

7. Set Timeouts

Reliability

8. Implement Retries

9. Handle Errors Gracefully

10. Use Fallback Models

Security

11. Protect API Keys

12. Validate User Input

13. Set API Key Limits

Create separate API keys with spending limits for:
  • Development/testing
  • Production
  • Different applications

Monitoring

14. Track Usage

Check your dashboard regularly for:
  • Token usage by model
  • Cost breakdown
  • Cache hit rates
  • Error rates

15. Log Important Metrics

16. Set Up Alerts

Configure low balance alerts in your dashboard to avoid service interruption.

Checklist

  • Using appropriate model for each task
  • Setting max_tokens limits
  • Prompts are concise
  • Caching enabled where appropriate
  • Batching similar requests
  • Streaming for interactive UX
  • Fast models for real-time use
  • Timeouts configured
  • Retry logic implemented
  • Error handling in place
  • Fallback models configured
  • API keys in environment variables
  • Input validation
  • Separate keys for dev/prod
  • Spending limits set