Skip to main content

Security

  • Never commit API keys to version control
  • Use environment variables
  • Rotate keys regularly
  • Use separate keys for dev/staging/production
Never expose API keys in client-side code:
  • ❌ Browser JavaScript
  • ❌ Mobile apps
  • ❌ Public repositories
  • ✅ Backend servers
  • ✅ Serverless functions
Always validate user input:

Performance

Process multiple requests in parallel:
Use streaming for better perceived performance:
Cache common queries to save costs:

Cost Optimization

Use cheaper models when appropriate:
  • Simple tasks: gpt-4.1-nano, claude-3.5-haiku
  • Complex reasoning: gpt-5.1, claude-sonnet-4.5, o3
  • Code: claude-sonnet-4.5, gpt-5.1
  • Fast & affordable: gpt-5.1-mini, gpt-4.2-mini
Shorter, more specific prompts cost less:
Set max_tokens to avoid excessive output:
Track costs in real-time:
  • Check Dashboard regularly
  • Set up billing alerts
  • Review usage patterns
  • Identify optimization opportunities

Error Handling

Always retry transient errors:
Have fallbacks ready:
Track errors for debugging:

Production Checklist

1

Security

  • ✅ API keys in environment variables
  • ✅ No keys in client-side code
  • ✅ Input validation
  • ✅ Rate limiting on your API
2

Performance

  • ✅ Async/concurrent requests
  • ✅ Streaming enabled where appropriate
  • ✅ Response caching
  • ✅ Timeouts configured
3

Reliability

  • ✅ Retry logic implemented
  • ✅ Error handling
  • ✅ Logging
  • ✅ Monitoring/alerting
4

Cost

  • ✅ Right model for each task
  • ✅ Prompts optimized
  • ✅ Output limits set
  • ✅ Usage monitoring

Example Production Setup

Error Handling

Comprehensive error handling guide

API Reference

Complete API documentation