Prerequisites
To use the Helicone AI GraphQL API, make sure that you have thegql and aiohttp libraries installed in your Python environment. You can install these packages with the following commands:
Setting up a GraphQL Client
Here’s how to setup a GraphQL client to communicate with the Helicone API:urlis the endpoint of the Helicone AI GraphQL API.AIOHTTPTransportestablishes the connection to the API endpoint.Clientis a GraphQL client that communicates with the API using the provided transport.
Fetching Data from the API
Here’s how to fetch data from the Helicone AI API using GraphQL:MAX_LOOPSis the maximum number of requests the client will make to the API.SIZEis the number of records fetched per request.gqlparses the GraphQL query.client.executeruns the query and returns the result. Thevariable_valuesparameter is used to set thelimitandoffsetin the GraphQL query.
heliconeRequest objects. Each object includes the prompt, a list of properties with their name, the responseBody, and the response.
The loop continues to fetch data until there are no more records (when result["heliconeRequest"] is an empty list), at which point it prints “No more results” and stops.