Polling Strategy

Implement an efficient polling mechanism to check task status without hitting rate limits.

Exponential Backoff

Instead of polling at a fixed interval (e.g., every 1 second), we strongly recommend using exponential backoff. This means increasing the wait time between each request.

For example: wait 1s, then 2s, then 4s, then 8s, up to a maximum interval (e.g., 10s).

javascript
async function pollTaskStatus(taskId, accessToken) {
  let delay = 1000; // Start with 1 second
  const maxDelay = 10000; // Max 10 seconds

  while (true) {
    const response = await fetch(`https://api.flimpa.com/api/v1/tasks/${taskId}`, {
      headers: { 'X-Task-Access-Token': accessToken }
    });
    
    const data = await response.json();
    
    if (data.status === 'COMPLETED' || data.status === 'FAILED') {
      return data;
    }
    
    await new Promise(resolve => setTimeout(resolve, delay));
    delay = Math.min(delay * 2, maxDelay); // Exponential backoff
  }
}

Handling Rate Limits

429 Too Many Requests

If you poll too aggressively, you may receive a 429 status code. Your code should catch this and wait longer before retrying.

Webhooks

Coming Soon

Webhooks for task completion are Coming Soon. For now, please use polling with exponential backoff.