hey Matt! This is an example code snippet to get the data for the last x hours. Feel free to change up the query slightly to fit your limit and filter
import requests
from datetime import datetime, timedelta
# Calculate the ISO string for one hour ago
one_hour_ago_iso = (datetime.utcnow() -
timedelta(hours=1)).isoformat() + "Z"
# Define the GraphQL endpoint (replace with your actual endpoint)
url = "https://www.helicone.ai/api/graphql"
# Define the GraphQL query and variables
query = """
query ExampleQuery($limit: Int, $offset: Int, $timeStampISO: String){
heliconeRequest(
limit: $limit
offset: $offset
filters: [
{
createdAt: {
gte: $timeStampISO
}
}
]
) {
prompt
properties{
name
}
responseBody
response
}
}
"""
MAX_LOOPS = 1000
PAGE_SIZE = 100
all_data = []
for i in range(MAX_LOOPS):
print("Loop", i)
variables = {
"limit": PAGE_SIZE,
"offset": PAGE_SIZE * i,
"timeStampISO": one_hour_ago_iso
}
# Define headers with Authorization
headers = {
"Authorization": "Bearer <KEY>",
"Content-Type": "application/json"
}
# Send the request with headers
response = requests.post(
url, json={'query': query, 'variables': variables}, headers=headers)
# Check if the request was successful
if response.status_code == 200:
data = response.json()['data']['heliconeRequest']
all_data.extend(data)
print("Success!")
if (len(data) < PAGE_SIZE):
break
else:
print("Error:", response.status_code)
print(response.text)
print(len(all_data))