Python Example
Prerequisites
To use the Helicone AI GraphQL API, make sure that you have the gql
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:
In this code:
url
is the endpoint of the Helicone AI GraphQL API.AIOHTTPTransport
establishes the connection to the API endpoint.Client
is 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:
In this code:
MAX_LOOPS
is the maximum number of requests the client will make to the API.SIZE
is the number of records fetched per request.gql
parses the GraphQL query.client.execute
runs the query and returns the result. Thevariable_values
parameter is used to set thelimit
andoffset
in the GraphQL query.
The response contains a list of 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.
Was this page helpful?