> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rate limit error during dataset iteration

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "Use case - Dataset iteration with Python SDK versions before 0.3.8"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

Summary

When iterating over large datasets with Python SDK versions before 0.3.8, users encounter a `TooManyRequestsError` because the SDK makes individual BTQL queries for each page of results, exceeding the 20 requests per 60 seconds rate limit. This issue is resolved by upgrading to SDK version 0.3.8 or later, which includes automatic rate limit handling for dataset operations.

## Error Message

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
braintrust.util.AugmentedHTTPError: {
  "Code": "TooManyRequestsError",
  "Message": "Too many requests. Source: checkBtqlOrgRateLimit. Rate limit: 20 requests per 60 seconds. Consumed: 21..."
}

```

## Resolution Steps

### Solution 1: Upgrade SDK (recommended)

#### Step 1: Check current version

Verify your current SDK version.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import braintrust
print(braintrust.__version__)

```

#### Step 2: Upgrade SDK

Install the latest version with automatic rate limit handling.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
pip install --upgrade braintrust

```

#### Step 3: Resume normal iteration

Dataset iteration will now handle rate limits automatically.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
dataset = braintrust.init_dataset(project="my-project", name="my-dataset")
for row in dataset:
    # SDK handles rate limiting automatically
    process_row(row)

```

### Solution 2: Use fetch() method (immediate workaround)

#### Step 1: Fetch all data at once

Use `fetch()` to retrieve all rows in a single API call.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
dataset = braintrust.init_dataset(project="my-project", name="my-dataset")
all_rows = dataset.fetch()  # Single operation, no pagination

```

#### Step 2: Process locally

Iterate through the fetched data without additional API calls.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
for row in all_rows:
    process_row(row)

```
