Skip to main content
Many OpenAI API endpoints return paginated lists. The Python SDK provides convenient auto-paginating iterators to work with these responses.

Auto-Pagination

The SDK automatically fetches additional pages as you iterate:
You don’t need to manually handle pagination - the SDK does it for you.

Async Pagination

Async iteration works the same way:

Manual Page Control

For more granular control over pagination, use the page helper methods:

Checking for More Pages

Fetching the Next Page

Async Page Fetching

Working with Page Data

Access the raw page data directly:

Page Types

The SDK uses different pagination types depending on the endpoint:

Cursor Pagination (SyncCursorPage)

Most endpoints use cursor-based pagination:

Conversation Cursor Pagination

Some endpoints use conversation-style pagination with a last_id:

Pagination Parameters

Common pagination parameters: Example:

Collecting All Pages

To collect all items from all pages:
Or with async:

Example: Processing in Batches

Process items in batches (one page at a time):

Paginated Endpoints

Common endpoints that support pagination:
  • client.fine_tuning.jobs.list()
  • client.files.list()
  • client.beta.vector_stores.list()
  • client.beta.vector_stores.files.list()
  • client.beta.threads.messages.list()
  • client.beta.threads.runs.list()
  • client.beta.threads.runs.steps.list()
Refer to the API Reference for pagination support on specific endpoints.