Visualize AI Gateway metrics
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
OpenAI
This tutorial uses OpenAI:
- Create an OpenAI account.
- Get an API key.
- 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:
- A Gateway Service
- A Route with the
/gpt4o
path - A Consumer with the API key
Bearer department-1-api-key
- Three plugins:
- HTTP Log to send logs to the pre-configured Logstash server
- Key Authentication to authenticate the Consumer
- AI Proxy configured with OpenAI to enable a chat route
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
Destroy the Kong Gateway container
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d