Skip to main content
This guide shows how to work with paginated API responses when listing prompts. Pagination allows you to efficiently retrieve large numbers of prompts without overwhelming your application or the API.

Prerequisites

Understanding Pagination

The Claro API uses cursor-based pagination for list operations:
Cursor-based pagination is more reliable than offset-based pagination, especially when data is being added or removed during iteration.

Example 1: Basic Pagination

Fetch the first page of prompts:

Example 2: Fetch Next Page

Use the cursor to fetch the next page:

Example 3: Iterate Through All Pages

Loop through all pages to get all prompts:

Example 4: Iterate with Limit

Fetch a specific maximum number of prompts:

Example 5: Process While Paginating

Process prompts as you fetch them (memory efficient):

Example 6: Generator Pattern

Use a generator for memory-efficient iteration:
Generators are memory-efficient because they only load one page at a time, making them ideal for processing large numbers of prompts.

Example 7: Filter While Paginating

Filter prompts while iterating:

Example 8: Paginate with Progress

Show progress while paginating:

Example 9: Parallel Processing

Process pages in parallel (advanced):
Be cautious with parallel processing to avoid hitting rate limits. Use this pattern only when processing is slow and API calls are already complete.

Example 10: Save and Resume

Save pagination state to resume later:

Example 11: Page Size Optimization

Find optimal page size for your use case:
Larger page sizes reduce the number of API calls but may increase response time. Find the balance that works for your application.

Example 12: Error Handling During Pagination

Robust pagination with error handling:

Next Steps

Basic Usage

Learn basic SDK operations

File Downloads

Download context files

Error Handling

Handle errors gracefully

Advanced Patterns

Production-ready patterns