AI Agents API Endpoints Documentation

The Premium endpoints in this doc have been created to support organizations with AI Agents that can explore, visualize and analyze data.

As a prototypr.ai customer, it is important to provide you with easy access to your data in a variety of formats that you can use. In order to gain access to agents via the prototypr.ai API, you will need to sign up to the Closed GA4 x AI Beta from within the app in addition to generating an API Key, which is accessible on the /home page when you login.

AI Agent Endpoints

As a Premium prototypr.ai customer or member, you have access to the following Agents via the API:

  1. Fine Tuned Google Analytics GPT-4o Agent

  2. AB Testing and Optimization Agent

More agent APIs will be available soon! If you have any feedback or feature requests about these APIs, please take the time to fill out this short survey.

AI Agent Use Case: Building a Google Analytics 4 Chatbot

One of the ways that prototypr.ai is using the fine tuned GA4 GPT agent API is to power a chatbot that enables customers to chat with their Google Analytics data. If you or your company is using Google Analytics 4, then why not consider building a chatbot with this Agent to enable easier access to your data.

Below is a example video of a Google Analytics 4 GPT chatbot in Test Center, which is prototypr.ai's analytics platform:

Fine Tuned Google Analytics GPT-4o Agent PREVIEW

Purpose

Enable developers to Chat with their Google Analytics data, build Google Analytics 4 API queries and visualize data with ChartJS.

Type of Request: POST

URL: https://www.prototypr.ai/api/v1/agents/ga4-gpt

Headers

  • Authentication: Bearer ${TOKEN}
  • Content-Type: application/json
  • Accept: application/json

Request Body

  • user_id: String

    This is your prototypr.ai user_id

  • workspace_id: String

    This is your prototypr.ai workspace_id, which is connected to your Google Analytics 4 account. For details about how to connect prototypr.ai to GA4, please review this article: How to connect your prototypr.ai account to Google Analytics.

  • messages: Array

    This is a standardized chat completions message thread.

  • gpt_data_analysis: Boolean

    Setting this to True enables the Agent to conduct analysis on your GA4 data

Python Request

import requests
import os
import json

messages_thread = []

# a standardized chat completions messages_thread
messages_thread.append({
    "role": "user",
    "content": "how many users visited my site yesterday?"
})

url = "https://www.prototypr.ai/api/v1/agents/ga4-gpt"

payload = {
    "user_id": "your_user_id",
    "workspace_id": "your_workspace_id",
    "messages": messages_thread,
    "gpt_data_analysis": True
}

headers = {
    "Authorization": "Bearer " + os.getenv("API_KEY"),
    "Content-Type": "application/json",
    "Accept": "application/json"
}

response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.json())
                                

Sample Response

{ "data": {
    "credit_balance": 99,
    "google_analytics_data" : [
      {
        "kind": "analyticsData#runReport",
        "metaData": {
            "currencyCode": "CAD",
            "timeZone": "America/Toronto"
        },
        "metricHeaders": [
            {
                "name": "activeUsers",
                "type": "America/TYPE_INTEGER"
            }
        ],
        "rowCount": 1,
        "rows": [
            {
                "metricValues": [
                    {
                        "value": "89"
                    }
                ]
            }
        ],
        "totals": [
            {
                "metricValues": [
                    {
                        "value": "89"
                    }
                ]
            }
        ]
      }
    ],
    "google_analytics_query" : {
        "dateRanges": [
            {
                "endDate": "yesterday"
                "startDate": "yesterday"
            }
        ],
        "keepEmptyRows": True,
        "metricAggregations": [
            "TOTAL"
        ],
        "metrics": [
            {
                "name": "activeUsers"
            }
        ]
    },
    "gpt_data_analysis": "<div><p class='analysis-copy'>Yesterday, the site attracted a total of 89 active users, indicating stable engagement.</p></div>",
    "request_log": {
        "request_count": "1",
        "request_date": "2024-12-09 11:45:00",
        "request_id": "8e4249ed56d44f543487c4bf8f16b649",
        "service": "/agents/ga4-gpt"
    },
    "messages_thread": [
        {
            "content": "how many users visited my site yesterday",
            "role": "user",
        },
        {
            "content": "{\"metrics\": [{\"name\": \"activeUsers\"}], \"dateRanges\": [{\"startDate\": \"yesterday\", \"endDate\": \"yesterday\"}], \"keepEmptyRows\": true, \"metricAggregations\": [\"TOTAL\"]}",
            "role": "assistant",
        },
        {
            "content": "[{\"metricHeaders\": [{\"name\": \"activeUsers\", \"type\": \"TYPE_INTEGER\"}], \"rows\": [{\"metricValues\": [{\"value\": \"89\"}]}], \"totals\": [{\"metricValues\": [{\"value\": \"89\"}]}], \"rowCount\": 1, \"metadata\": {\"currencyCode\": \"CAD\", \"timeZone\": \"America/Toronto\"}, \"kind\": \"analyticsData#runReport\"}]",
            "role": "assistant",
        },
        {
            "content": "<div><p class='analysis-copy'>Yesterday, the site attracted a total of 89 active users, indicating stable engagement.</p></div>",
            "role": "assistant"
        }
    ],
    "model": "ga4-gpt-4o-ft"
  }
}                           

Google Analytics 4 AI Agent API FAQ

Login to prototypr.ai, which will take you to /home. Click on the API link at the top of the page, which will take you to the /api-keys page. Scroll down to My Usage Stats and you will see your user_id.

Your workspace_id is available from the /home screen. Click on the 3 dot menu for your workspace, and this will bring up a Edit Workspace menu, where you can see your workspace_id.

In order for you to use this GA4 agent, you will need to take the following steps:

1. Sign up to the Closed GA4 x AI Beta from the /home page. Click on the Analytics icon and register.

2. Once approved in the beta, please visit the following guide and authenticate GA4: How to connect your prototypr.ai account to Google Analytics.

Currently, this AI Agent is part of a pay-as-you-go model. Each request to the GA4 GPT model uses 1 credit. You can purchase credits inside the app in the membership area which is linked off of the /home page.

There are a number of use cases you could use this agent for. They include:

1. Create a Google Analytics Chatbot for your stakeholders

2. Build GA4 Queries with natural language

3. Build a GA4 dashboard generator like the one in prototypr.ai

4. Ask the bot to visualize and analyze data with ChartJS

It can take anywhere from ~7 seconds to 30 seconds (which is the max before the model times out). Simple queries result in the fastest generation.

The GA4 GPT currently uses ChartJS to render any data visualizations. If you plan to create your own chatbot using this API, it is recommended to add the appropriate ChartJS javascript file to your pages.

Yes! This agent can visualize any data you paste into the input field when chatting. For example you could copy and paste some time series data and ask it to create a line graph of this data.

The GA4 GPT Agent was trained using ~1.5 million tokens of natural language and API queries using OpenAI's fine tuning tool. The queries were primarily non-retention based. Better retention query generation will be available in a future update.

AB Testing and Optimization Agent PREVIEW

Purpose

This agent can scrape URLs to uncover and summarize optimization opportunities in SEO and A/B testing, automate the creation of test plans, and retrieve historical learnings, all designed to accelerate experimentation workflows with the goal of improving digital experiences.

Type of Request: POST

URL: https://www.prototypr.ai/api/v1/agents/ai-optimizer

Headers

  • Authentication: Bearer ${TOKEN}
  • Content-Type: application/json
  • Accept: application/json

Request Body

  • user_id: String

    This is your prototypr.ai user_id

  • workspace_id: String

    This is your prototypr.ai workspace_id, which can be found by editing your workspace from the /home page.

  • messages: Array

    This is a standardized chat completions message thread.

Python Request

import requests
import os
import json

messages_thread = []

# a standardized chat completions messages_thread
messages_thread.append({
    "role": "user",
    "content": "please create a test plan for the hypothesis: By personalizing the onboarding experience for new users, we will improve weekly retention rates by 20% within a 3-month period after sign-up."
})

url = "https://www.prototypr.ai/api/v1/agents/ai-optimizer"

payload = {
    "user_id": "your_user_id",
    "workspace_id": "your_workspace_id",
    "messages": messages_thread
}

headers = {
    "Authorization": "Bearer " + os.getenv("API_KEY"),
    "Content-Type": "application/json",
    "Accept": "application/json"
}

response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.json())
                                

Sample Response

{ "data": {
    "agent": "ai-optimizer",
    "credit_balance": 99,
    "request_log": {
        "request_count": "1",
        "request_date": "2025-01-02 11:45:00",
        "request_id": "8a2ea2874dd44c34a09c5d753549779d",
        "service": "/agents/ai-optimizer"
    },
    "messages": [
        {
            "content": "please create a test plan for the hypothesis: By personalizing the onboarding experience for new users, we will improve weekly retention rates by 20% within a 3-month period after sign-up.",
            "role": "user",
        },
        {
            "content": "<div>\n    <p>I put together a first draft of an experiment plan for your review at the following link:</p>\n    <a class='link-to-test-plan-id' href='https://www.prototypr.ai/test-plan?pwid=YOUR_WORKSPACE_ID&xid=TEST_PLAN_ID'>\n        <p>https://www.prototypr.ai/test-plan?pwid=YOUR_WORKSPACE_ID&xid=TEST_PLAN_ID</p>\n    </a>        \n</div>",
            "role": "assistant",
        }
    ]
  }
}                           

AB Testing and Optimization Agent API FAQ

This agent can scrape urls by prompting it to visit a specific url and asking it to perform an action such as summarizing ab testing opportunities. Here is an example prompt you can use:

Prompt: What are some opportunities i could explore to improve the content at this url: prototypr.ai/docs/api/agents

Depending on the complexity of the web page and your request, wait times can vary. As an example, scraping and summarizing the prototypr.ai homepage using the prompt above takes approximately 20 seconds to complete.

Prompt: I've noticed that my home page's primary cta converts at roughly 40%, and I have a hypothesis that if I change the headline to talk about _____, then I can believe I can increase conversion rates by 10% over the current baseline. Can you please generate a test plan?

If your prompt is successful, then the agent will create a new Test Plan with a link to it in your prototypr.ai AI workspace. To access all of your Test Plans, please visit your AI workspace and then click on Test Plans, which is located in the workspace's Research section.

Currently, this AI Agent is part of a pay-as-you-go model. Each request to the model uses 1 credit. You can purchase credits inside the app in the membership area which is linked off of the /home page.

There are a number of use cases you could use this agent for. They include:

1. Scraping URLs and summarizing content

2. Chatting with the agent about a webpage's content

3. Building Test plans for an AB Test

4. Asking the agent to identify SEO opportunities

5. Asking the agent about historical tests that have been ran

6. Asking the agent to provide statistics around historical tests that have been created

Yes! This Agent uses Retrieval-Augmented Generation (RAG) memory to save test plans and retrieve past learnings from a secure, private database. This allows developers to build upon previous insights, refine strategies, and avoid redundant experimentation.

This Agent analyzes content, structure, and metadata of a given URL in order to detect areas for improvement in SEO, content, and A/B testing experiments. The Agent typically breaks down the problem that it sees and presents an actionable recommendation with rationale.

To get started, sign up for a prototypr.ai account and then generate an API key in the developer API section which is linked off of the /home page.

The AB Testing and Optimization Agent uses a mixture of different models to complete various tasks. The models that power this agent include:

Google Gemini 2.0 Flash

OpenAI GPT-4o

OpenAI GPT-4o-mini

Rate Limits and API Usage Stats

Currently there are rate limits of 25/day across all API endpoints. This will grow over time as prototypr.ai adds more endpoints. If you need more, please feel free to connect with Gareth Cull, who is the creator of prototypr.ai.

As part of this API Service, prototypr.ai provides usage stats so that you can see how often your api key is being used.

API Feedback

Your feedback is critical for prototypr.ai to improve its products and services. Please consider taking this short 2-3 minute developer feedback survey about the prototypr.ai API.