Skip to main content

Best Practices

Follow these best practices to build robust, efficient applications with vfrog.ai.

Security

Protect Your API Keys

# ✅ Good: Use environment variables
export VFROG_API_KEY="your-key-here"

# ❌ Bad: Hardcode in source
api_key = "vfrog_abc123..." # Don't do this!

Rotate Keys Regularly

Rotate API keys every 90 days or when team members leave.

Performance

Use the Sync Endpoint

The sync endpoint (/v1/cv/requests/sync) is currently the only available endpoint. It's suitable for both real-time features and batch processing (with appropriate rate limiting).

Optimize Images

# Resize large images before uploading
from PIL import Image

img = Image.open('large_image.jpg')
img.thumbnail((1024, 1024))
img.save('optimized.jpg', quality=85)

Implement Caching

Cache results for frequently processed images.

Reliability

Implement Retries

from tenacity import retry, stop_after_attempt, wait_exponential

@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=4, max=10)
)
def make_api_call():
return requests.post(url, headers=headers, json=data)

Handle Webhooks Properly

  1. Return 200 OK immediately
  2. Process asynchronously
  3. Make idempotent
  4. Verify signatures

Monitoring

Track Usage

Monitor your API usage in the console and set up alerts at 50%, 80%, and 100% of quota.

Log Everything

import logging

logging.info(f"Processing image {external_id}")
logging.error(f"Failed to process {external_id}: {error}")

Set Up Alerts

Configure alerts for:

  • High error rates
  • Quota warnings
  • Failed webhooks

Cost Optimization

  1. Use appropriate rate limiting for batch processing (10 requests/minute)
  2. Batch process images
  3. Implement caching
  4. Optimize image sizes
  5. Set appropriate quotas per API key