Skip to content

Add timeout kwarg to MeterClient.__init__ #1

Description

@tuvens

Problem

MeterClient.__init__ instantiates httpx.Client(timeout=60.0) and exposes no constructor kwarg to override that timeout. For sites where strategy generation involves a non-trivial LLM call (long pages, complex schemas), generate_strategy reliably exceeds 60 seconds and raises httpx.ReadTimeout (surfaces as MeterError: Request failed: Read timeout).

Source reference in meter-sdk==0.8.0:

# meter_sdk/client.py
class MeterClient:
    def __init__(self, api_key: str, base_url: str = "https://api.meter.sh"):
        ...
        self.client = httpx.Client(
            base_url=self.base_url,
            headers={"Authorization": f"Bearer {api_key}"},
            timeout=60.0  # ← hardcoded, no kwarg passthrough
        )

Current workaround

Users have to mutate the private-looking attribute after instantiation:

client = MeterClient(api_key=os.environ["METER_API_KEY"])
client.client.timeout = httpx.Timeout(300.0)  # fragile; version-coupled to httpx internals

This works but is brittle — it reaches through into the underlying httpx client, relies on client.timeout being a writable attribute (it is in httpx 0.28.x, but isn't guaranteed forever), and looks suspicious in code review.

Proposed change

Add a timeout kwarg with a sensible default:

def __init__(
    self,
    api_key: str,
    base_url: str = "https://api.meter.sh",
    timeout: float = 60.0,
):
    ...
    self.client = httpx.Client(
        base_url=self.base_url,
        headers={"Authorization": f"Bearer {api_key}"},
        timeout=timeout,
    )

Backwards-compatible (existing callers get the same 60 s default). Users who need longer can opt in:

client = MeterClient(api_key=..., timeout=300.0)

Real-world evidence

Encountered while building a pilot integration against the meter-sdk for a community-events directory project. Strategy generation for a single page (~86 row-items, output schema with 8 fields) regularly took 60-90 seconds in our environment. The workaround was needed twice in two separate scripts. Pilot writeup: https://github.com/tuvens/whatsapp-harvester/blob/main/docs/METER-PILOT-NOTES.md (see "Surprises" section).

Happy to send a PR if you'd take it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions