I am using the Kong gateway service with the request transformer plugin to set up the gateway to access the GCP Gemini service.
My Kong proxy domain is example.com and the route path is /gemini
So when I call https://example.com/gemini, it redirects to the Gemini endpoint. I am getting a response from Gemini using this. Up until now, everything is okay.
Below is the request body that I am using.
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a hello world program"
}
]
}
],
"generationConfig": {
"temperature": 0.9,
"topK": 1,
"topP": 1,
"maxOutputTokens": 2048,
"stopSequences": []
}
}
The complete request will look like the one below.
curl -X POST https://<kong-admin-api-url>/gemini/v1/projects/<gcp-project-id>/locations/asia-northeast1/publishers/google/models/gemini-1.5-pro:generateContent --header 'Content-Type: application/json' --header 'Authorization: Bearer <encrypted JWT token>' -d '{"contents": [{"role": "user", "parts":[{"text": "Write a hello world program"}]}], "generationConfig": {"temperature": 0.9, "topK": 1, "topP": 1, "maxOutputTokens": 2048, "stopSequences": []}}'
To filter billing details in the GCP dashboard, we need to add labels. My requirement is to include these labels in the request body.
I’ve found the GCP document on how we can add the labels.
cat > request.json << 'EOF'
{
"contents": {
"role": "ROLE",
"parts": { "text": "PROMPT_TEXT" }
},
"labels": {
"LABEL_KEY": "LABEL_VALUE"
},
}
EOF
So how can I add these labels with my requests using request transformer plugin.
,
"labels": {
"LABEL_KEY": "LABEL_VALUE"
},
It would be great if someone can also share the Kong admin API for adding these labels to request transformer body.
I tried below and getting errors
curl -X PATCH https://<kong-admin-api-url>/plugins/<plugin id> \
--header "Content-Type: application/json" \
--data '{
"config": {
"remove": {
"headers": ["Authorization"]
},
"add": {
"headers": ["Authorization: <JWT encrypted token>"],
"body": ["labels={\"test_label\":\"test\"}"]
}
}
}'