Add Human Feedback using API
This guide will walk you through the steps of adding human feedback to an AI Gateway request using the Cloudflare API. You will learn how to retrieve the relevant request logs, and submit feedback using the API.
If you prefer to add human feedback via the dashboard, refer to Add Human Feedback.
- Create an API token with the following permissions:
AI Gateway - Read
AI Gateway - Edit
- Get your Account ID.
- Using that API token and Account ID, send a
POST
request to the Cloudflare API.
The cf-aig-log-id
is a unique identifier for the specific log entry to which you want to add feedback. Below are two methods to obtain this identifier.
This method allows you to directly find the cf-aig-log-id
within the header of the response returned by the AI Gateway. This is the most straightforward approach if you have access to the original API response.
The steps below outline how to do this.
- Make a Request to the AI Gateway: This could be a request your application sends to the AI Gateway. Once the request is made, the response will contain various pieces of metadata.
- Check the Response Headers: The response will include a header named
cf-aig-log-id
. This is the identifier you will need to submit feedback.
In the example below, the cf-aig-log-id
is 01JADMCQQQBWH3NXZ5GCRN98DP
.
{ "status": "success", "headers": { "cf-aig-log-id": "01JADMCQQQBWH3NXZ5GCRN98DP" }, "data": { "response": "Sample response data" }}
If you do not have the cf-aig-log-id
in the response body or you need to access it after the fact, you are able to retrieve it by querying the logs using the Cloudflare API.
Send a GET
request to get a list of logs and then find a specific ID
Required API token permissions
At least one of the following token permissions
is required:
AI Gateway Write
AI Gateway Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai-gateway/gateways/$GATEWAY_ID/logs" \ --request GET \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{ "result": [ { "id": "01JADMCQQQBWH3NXZ5GCRN98DP", "cached": true, "created_at": "2019-08-24T14:15:22Z", "custom_cost": true, "duration": 0, "id": "string", "metadata": "string", "model": "string", "model_type": "string", "path": "string", "provider": "string", "request_content_type": "string", "request_type": "string", "response_content_type": "string", "status_code": 0, "step": 0, "success": true, "tokens_in": 0, "tokens_out": 0 } ]}
You can also retrieve the cf-aig-log-id
using a binding, which streamlines the process. Here's how to retrieve the log ID directly:
const resp = await env.AI.run( "@cf/meta/llama-3-8b-instruct", { prompt: "tell me a joke", }, { gateway: { id: "my_gateway_id", }, },);
const myLogId = env.AI.aiGatewayLogId;
Once you have both the API token and the cf-aig-log-id
, you can send a PATCH request to submit feedback.
Required API token permissions
At least one of the following token permissions
is required:
AI Gateway Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai-gateway/gateways/$GATEWAY_ID/logs/$ID" \ --request PATCH \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "feedback": 1 }'
If you had negative feedback, adjust the body of the request to be -1
.
{ "feedback": -1}
You can verify the feedback submission in two ways:
- Through the Cloudflare dashboard ↗: check the updated feedback on the AI Gateway interface.
- Through the API: Send another GET request to retrieve the updated log entry and confirm the feedback has been recorded.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark