Continue observations queries that would otherwise time out
Short or empty pages can include a continuation cursor so expensive observations queries can make progress across requests.
We're improving Observations API v2 reliability so the small percentage of queries that currently time out can make progress across multiple requests.
A page may contain fewer observations than limit, including none, while meta.cursor is present. Keep requesting pages until meta.cursor is absent.
With the Python SDK configured for your project, this fetches generation observations from the last seven days:
from datetime import datetime, timedelta, timezone
from langfuse import get_client
langfuse = get_client()
end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(days=7)
cursor = None
while True:
page = langfuse.api.observations.get_many(
type="GENERATION",
from_start_time=start_time,
to_start_time=end_time,
limit=100,
cursor=cursor,
)
for observation in page.data:
print(observation.id)
cursor = getattr(page.meta, "cursor", None)
if not cursor:
breakSome of our documentation examples incorrectly stopped pagination when a page was empty. If you copied one of those examples, update your loop to check meta.cursor instead of the number of returned observations. Otherwise, it may stop before retrieving all results.
Updated examples:
- Data migration: English and Japanese.
- Evaluation workflows: external pipelines, RAGAS, and golden datasets.
- Intent classification: pipeline cookbook and chatbot analytics.
- Deleting a session's traces.
See the cursor pagination guide for the response contract.