> ## Documentation Index
> Fetch the complete documentation index at: https://docs.athina.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query the Graph API using cURL or Python

> We have provided examples of how to query the Athina AI GraphQL API using cURL and Python. You can use these examples to fetch data from the API and integrate it into your applications.

## Postman Collection[](#postman-collection)

You can find   [here](https://docs.athina.ai/GraphQL.postman_collection.json)   an entire postman collection with different types of queries for reference. You can download the collection and import it into your postman application.

## cURL[](#curl)

To start, let’s make a request via cURL to query data from Athina AI GraphQL API.

### Fetching Data from the API[](#fetching-data-from-the-api)

```curl
# Replace <ATHINA_API_KEY> with your athina api key obtained from the dashboard
curl --location 'https://api.athina.ai/graphql' \
--header 'Content-Type: application/json' \
--header 'athina-api-key: <ATHINA_API_KEY>' \
--data '{
    "query": "query GetPromptRuns($limit: Int!) { getPromptRunsByFilters(limit: $limit) { id org_id    prompt_slug    language_model_id    prompt_response prompt_tokens}}",
    "variables": {
        "limit": 2,
        "page": 0
    }
}'
```

## Node.js[](#nodejs)

### Prerequisites[](#prerequisites)

To use the Athina AI GraphQL API in Node.js, make sure that you have the `request` library installed. You can install these packages with the following commands:

```npm
npm install request
```

### Fetching Data from the API[](#fetching-data-from-the-api-1)

Here's an example of how to query the Athina AI GraphQL API using Node.js:

```c
var request = require('request');
// Replace <ATHINA_API_KEY> with your athina api key obtained from the dashboard
var options = {
  'method': 'POST',
  'url': 'https://api.athina.ai/graphql',
  'headers': {
    'Content-Type': 'application/json',
    'athina-api-key': '<ATHINA_API_KEY>'
  },
  body: JSON.stringify({
    "query": "query GetPromptRuns($limit: Int!) { getPromptRunsByFilters(limit: $limit) { id org_id    prompt_slug    language_model_id    prompt_response prompt_tokens}}",
    "variables": {
      "limit": 2,
      "page": 0
    }
  })
 
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

## Python[](#python)

<Tip>
  **Note**: The python example uses the `gql` and `aiohttp` libraries to communicate with the API. You can alternatively use just `requests` library to communicate with the API directly as well.
</Tip>

### Prerequisites[](#prerequisites-1)

To use the Athina 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:

```pip
pip install gql
pip install aiohttp
```

### Setting up a GraphQL Client[](#setting-up-a-graphql-client)

Here's how to setup a GraphQL client to communicate with the Athina GraphQL API:

```python
from gql.transport.aiohttp import AIOHTTPTransport
from gql import gql, Client
 
url = "https://api.athina.ai/graphql"
 
# Replace <ATHINA_API_KEY> with your athina api key obtained from the dashboard
transport = AIOHTTPTransport(url=url, headers={
    "athina-api-key": "<ATHINA_API_KEY>"
})
 
client = Client(transport=transport, fetch_schema_from_transport=True)
```

In this code:

* `url` is the endpoint of the Athina 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[](#fetching-data-from-the-api-2)

Here's how to fetch data from the Athina AI API using GraphQL:

```curl
SIZE = 5
query = gql(
    """
    query GetPromptRuns($limit: Int!, $page: Int!) {
        getPromptRunsByFilters(limit: $limit, page: $page) {
            id
            org_id
            prompt_slug
            language_model_id
            prompt_response
            prompt_tokens
        }
    }
    """
)
result = client.execute(query,
    variable_values={
        "limit": SIZE,
        "page": 0
    }
)
print(len(result["getPromptRunsByFilters"]))
print(result)
```

In this code:

* `SIZE` is the number of records fetched per request.
* `gql` parses the GraphQL query.
* `client.execute` runs the query and returns the result. The `variable_values` parameter is used to set the `limit` and `page` in the GraphQL query.

The response contains a list of `PromptRun` objects. Each `PromptRun` object contains the following fields: `id`, `org_id`, `prompt_slug`, `language_model_id`, `prompt_response`, and `prompt_tokens`.
