Add Human Feedback using API
Last updated Oct 26, 2026 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.
1. Create an API Token
-
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
POSTrequest to the Cloudflare API.
2. Retrieve the cf-aig-log-id
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.
Method 1: Locate the cf-aig-log-id in the request response
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.
Treat the log ID as an opaque string. Newer logs use lowercase UUIDv7 IDs, and older logs use 26-character ULIDs. The logs API accepts both.
In the example below, the cf-aig-log-id is 019a7b3e-5f2c-7c41-9d3e-2b8f6a1c4e07.
{
"status": "success",
"headers": {
"cf-aig-log-id": "019a7b3e-5f2c-7c41-9d3e-2b8f6a1c4e07"
},
"data": {
"response": "Sample response data"
}
}
Method 2: Retrieve the cf-aig-log-id via API (GET request)
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
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>AI Gateway Write</code>
- <code>AI Gateway Read</code>
</details>
List Gateway Logsbash
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": "019a7b3e-5f2c-7c41-9d3e-2b8f6a1c4e07",
"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
}
]
}
Method 3: Retrieve the cf-aig-log-id via a binding
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;
Note:
The aiGatewayLogId property, will only hold the last inference call log id.
3. Submit feedback via PATCH request
Once you have both the API token and the cf-aig-log-id, you can send a PATCH request to submit feedback.
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>AI Gateway Write</code>
</details>
Patch Gateway Logbash
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
}
4. Verify the feedback submission
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?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai-gateway/evaluations/add-human-feedback-api/#page","headline":"Add Human Feedback using API","description":"Submit human feedback on AI Gateway request logs using the Cloudflare API.","url":"https://developers.cloudflare.com/ai-gateway/evaluations/add-human-feedback-api/","inLanguage":"en","image":"https://developers.cloudflare.com/ai-gateway/evaluations/add-human-feedback-api/og.png?v=55ab5bde9f6f1dfd","dateModified":"2026-10-26","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Provide human feedback on AI Gateway evaluations programmatically using Worker bindings. title: Add human feedback using Worker Bindings image: https://developers.cloudflare.com/ai-gateway/evaluations/add-human-feedback-bindings/og.png?v=d877b086c32d8c8b
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ai-gateway/llms.txt
Use this file to discover all available pages before exploring further.
Docs