Expert recommendations for building reliable, secure, and efficient AI applications in production.
# Good: Load from environment
api_key = os.environ.get("MYTHIC_API_KEY")
# Bad: Hardcoded key
api_key = "sk-abc123..." # Never do this!
Never directly concatenate user input into system prompts. Always validate and sanitize inputs, and consider using structured formats like JSON for user data.
Handle transient errors gracefully with exponential backoff:
import time
import random
def retry_with_backoff(func, max_retries=3):
for attempt in range(max_retries):
try:
return func()
except RateLimitError:
wait = (2 ** attempt) + random.random()
time.sleep(wait)
Streaming reduces time-to-first-token and improves perceived performance:
mythic-4-mini for simple tasks (10x cheaper)mythic-4 for complex reasoningmythic-embed-3-small when full precision isn't needed