Skip to content
  • Manage your APIs
  • About API keys

API best practice for AI apps

Here’s a selection of recommendations for using API keys to build AI apps.

Security tips for AI apps

Link to this section
  • Always verify API keys: Never trust unverified API keys
  • Validate trusted context: Ensure AI operations are within user or organization boundaries
  • Sanitize inputs: Clean AI inputs to prevent injection attacks
  • Validate outputs: Check AI responses for harmful content
  • Rate limiting: Implement stricter limits for AI endpoints

Performance tips for AI apps

Link to this section
  • Cache AI responses: Cache common AI responses to reduce latency
  • Async processing: Use async/await for AI operations
  • Timeout handling: Set reasonable timeouts for AI requests
  • Resource monitoring: Track AI resource usage per user or organization

Monitoring tips for AI apps

Link to this section
  • Usage tracking: Monitor AI usage patterns per user or organization
  • Performance metrics: Track response times and success rates
  • Error logging: Log all AI-related errors with context
  • Cost tracking: Monitor AI costs per organization

Integration tips for AI apps

Link to this section
  • Clear boundaries: Define clear limits for AI access
  • Documentation: Document AI capabilities and limitations
  • Testing: Test AI integration thoroughly
  • Fallbacks: Provide fallback options when AI is unavailable