Visualize AI Gateway metrics

Uses: AI Gateway Kong Gateway
Related Documentation
Incompatible with
konnect
Tags
Minimum Version
Kong Gateway - 3.6
TL;DR

You can use any logging plugin to send your AI Gateway metrics and logs to your dashboarding tool. For testing purposes, you can start our sample observability stack, send requests to /gpt4o, and visualize the results at http://localhost:5601/app/dashboards#/view/aa8e4cb0-9566-11ef-beb2-c361d8db17a8.

If you’re using Konnect, you can visualize AI Gateway metrics with Advanced Analytics.

Prerequisites

This tutorial uses OpenAI:

  1. Create an OpenAI account.
  2. Get an API key.
  3. Create a decK variable with the API key:
    export OPENAI_AUTH_HEADER='Bearer {api-key}'
    

Clone the sample repository

Kong provides a sample stack using Elasticsearch, Logstash, and Kibana to visualize AI Gateway metrics.

The kong-ai-gateway-observability GitHub repository comes with a configured Kong Gateway instance. You can see the sample Kong Gateway configuration in kong.yaml. It includes:

The AI Proxy plugin is pre-configured with to fetch the OpenAI key from the OPENAI_AUTH_HEADER environment variable, as defined in the prerequisites.

To use this stack, clone the repository:

git clone https://github.com/KongHQ-CX/kong-ai-gateway-observability
cd kong-ai-gateway-observability

Start the stack

Use the following command to start the sample stack:

docker compose up

Send requests

Once the stack is running, open a new terminal and send some requests to the /gpt4o endpoint with the Consumer’s API key to generate metrics. For example:

curl -X POST "http://localhost:8000/gpt4o" \
     -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "Authorization: Bearer department-1-api-key" \
     --json '{
       "messages": [
         {
           "role": "system",
           "content": "You are a mathematician"
         },
         {
           "role": "user",
           "content": "What is 1+1?"
         }
       ]
     }'

Visualize the metrics

Go to the following URL to visualize your metrics in Kibana:

http://localhost:5601/app/dashboards#/view/aa8e4cb0-9566-11ef-beb2-c361d8db17a8

Cleanup

curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!