Skip to main content
Here are the key practices that will help you build reliable applications with the Incredible API:

πŸš€ Performance

Instead of multiple API calls, combine related requests:
# ❌ Multiple calls
curl -d '{"messages": [{"role": "user", "content": "Get user 1"}]}' ...
curl -d '{"messages": [{"role": "user", "content": "Get user 2"}]}' ...

# βœ… Single call
curl -d '{"messages": [{"role": "user", "content": "Get users 1 and 2"}]}' ...

2. Use Streaming for Long Responses

Enable streaming for better user experience:
curl -d '{"stream": true, "messages": [{"role": "user", "content": "Generate a long report"}]}' ...

πŸ›‘οΈ Security

3. Never Hardcode Credentials

# ❌ Don't do this
api_key="inc_abc123..."

# βœ… Use environment variables
api_key="$INCREDIBLE_API_KEY"

4. Validate User Input

Check prompts before sending to the API:
def validate_prompt(prompt):
  if len(prompt) > 10000:
      return "Prompt too long"
  if "<script>" in prompt.lower():
      return "Invalid content"
  return None

πŸ”„ Reliability

5. Handle Errors Gracefully

try:
  response = call_incredible_api(prompt)
  return response
except Exception as e:
  print(f"API call failed: {e}")
  return fallback_response()

6. Implement Retries

def call_with_retry(prompt, max_retries=3):
  for attempt in range(max_retries):
      try:
          return call_incredible_api(prompt)
      except Exception as e:
          if attempt == max_retries - 1:
              raise e
          time.sleep(2 ** attempt)  # Exponential backoff

πŸ“Š Monitoring

7. Log API Calls

Track usage and errors:
import logging

def log_api_call(prompt, response, duration):
  logging.info(f"API call: {len(prompt)} chars, {duration:.2f}s, success")

🎯 What’s Next?

Key Takeaway: Start simple, handle errors, and add monitoring as your application grows.