---
updatedAt: 2025-12-05T16:05:32.000Z
agentTools:
  projectIndex: https://developers.modoenergy.com/llms.txt
---

# Example Modo Energy API client

```python Python
import logging
from datetime import datetime

import requests

logger = logging.getLogger(__name__)


class ModoApiClient:
    def __init__(self, api_token: str) -> None:
        self.api_token = api_token
        self.session = requests.Session()
        self.session.headers.update(
            {
                "X-Token": self.api_token,
                "Accept": "application/json",
            },
        )

    def get(self, url: str, params: dict[str, str] | None = None) -> dict | list[dict]:
        all_results: list[dict] = []
        next_url = url
        try:
            while next_url:
                response = self.session.get(next_url, params=params)

                response.raise_for_status()
                data = response.json()

                if isinstance(data, dict) and "results" in data:
                    results = data["results"]
                    if isinstance(results, dict):
                        results = [results]
                    all_results.extend(results)
                    next_url = data.get("next")
                    params = None
                else:
                    next_url = None
                    all_results = data
        except requests.RequestException as e:
            logger.error(e.response.text)
        finally:
            return all_results
```

```json Response Example
{"success":true}
```

# Define the init method

<!-- python@9-18 -->



# Define the get method

<!-- python@20-43 -->



# Create empty response objects

<!-- python@21 -->



# Iterate over paginated responses

<!-- python@24-39 -->

All paginated responses in the Modo Energy API will define a "next" URL, which points to the next page in the response. 

Single page responses don't define a "next" field, so will exit the loop after the first iteration.

# Handle any exceptions

<!-- python@40-41 -->



# Return the results

<!-- python@42-43 -->