Skip to main content
The Smooth API uses polling to deliver task results and events. This page explains how the polling mechanism works and best practices for implementing it.

Why Polling?

The API uses polling rather than webhooks or WebSockets for several reasons:
  • Simplicity - No need to set up webhook endpoints or maintain WebSocket connections
  • Reliability - No lost events due to connection issues
  • Firewall-friendly - Works behind firewalls that block incoming connections
  • Stateless - Each request is independent; easy to implement in any language

Basic Polling

For simple tasks, poll the task endpoint until the status changes to done, failed, or cancelled:
Response (running):
Response (completed):

HTTP Status Codes

Event-Based Polling

For sessions and custom tools, use the event_t parameter to receive events incrementally. This is more efficient than fetching the full response each time.

The event_t Parameter

The event_t (event timestamp) parameter filters events to only return those that occurred after the specified timestamp:

Event Structure

Each event contains:

Polling Loop Implementation

Here’s a robust polling implementation:

Best Practices

1. Use Appropriate Poll Intervals

2. Implement Exponential Backoff

For long-running tasks, increase the interval over time:

3. Handle Network Errors

4. Track Processed Events

Avoid processing the same event twice:

5. Clean Up on Errors

If your polling loop fails, consider cancelling the task to avoid resource leaks:

Python SDK

The Python SDK handles all polling automatically:

Debugging

Checking Event Flow

Add logging to understand the event flow:

Common Issues