Skip to main content
The X API uses pagination for endpoints that return multiple pages of results (e.g. timelines, search etc.). Each API call response includes a meta object with result_count, previous_token, and next_token. The XDK takes care of making multiple API calls using the next_token so developers can just specify how much data they are looking for without having to make multiple calls. The SDK simplifies this with:
  • Built-in Iterators: Use generator functions for seamless multi-page fetching.
  • Explicit Token Handling: For flexible manual control when needed by passing pagination_token when needed.
  • Max Results Enforcement: Respect max_results per call (up to API limits, e.g., 100 for search).
Use the iterate() method on paginated responses to fetch all results lazily. Example: Paginated Search
  • The iterator handles next_token automatically.
  • Stops when no next_token is present.
  • Supports rate limit backoff to avoid 429 errors.

Manual Pagination

If you require control over the results for some custom logic (e.g. processing page-by-page), you can still use the next_token and do the pagination manually as shown below:
Tips:
  • Always specify max_results to optimize (default varies by endpoint).
  • Monitor meta.result_count for debugging.
  • For very large queries, consider async iteration to avoid blocking. For detailed code examples using the Python XDK, check out our code samples GitHub repo.