What is Request Feedback?
Request Feedback allows you to enrich your API calls with user feedback and other data after the initial request has been completed.
This is useful for gathering insights on the quality of the model’s response, which can be used for analytics, auditing, and improving the user experience.
With this feature, you can:
- Capture user ratings and comments on AI responses.
- Track which responses were helpful or unhelpful.
- Add contextual data from your platform after the fact.
- Build a feedback loop to fine-tune models and prompts.
Benefits
- Quality Monitoring: Continuously track the performance and quality of your AI models.
- User Satisfaction: Understand what your users think about the AI responses they receive.
- Data-Driven Improvements: Use feedback data to identify areas for improvement in your prompts, models, or workflows.
- Enhanced Auditing: Add context to requests for better auditing and analysis.
Tip: Standardize your feedback data structure (e.g., ratings, tags) to make it easier to analyze across your applications.
How It Works
- After a chat completion, you get an ID in the response.
- Use this ID to send a
POST
request to the Requesty feedback endpoint.
- Include your feedback data in the JSON payload.
- View and analyze this feedback in your Requesty dashboard.
Important notes
- You can POST feedback multiple times per request.
- Every subsequent call merges the new values.
- If a new feedback call contains an existing key, the new value overwrites the existing one.
Python Example
Here’s how you can send feedback after a chat completion call:
import openai
import requests
import os
requesty_api_key = [SAFELY LOAD YOUR API KEY...]
# Assume client is an initialized OpenAI client pointed at Requesty
client = openai.OpenAI(api_key=requesty_api_key,
base_url="https://router.requesty.ai/v1")
# 1. Make the initial request
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Your prompt here"}],
)
# 2. Get the unique ID from the response
request_id = response.id
# 3. Send feedback to the Requesty API
feedback_url = f"https://ingestion.requesty.ai/feedback/{request_id}"
feedback_headers = {
"Authorization": f"Bearer {requesty_api_key}",
"Content-Type": "application/json"
}
feedback_data = {
"data": {
"message": "The response was very accurate and helpful.",
"rating": 5,
"helpful": True,
"user_id": "user_1234",
"tags": ["customer-support", "positive-feedback"]
}
}
try:
feedback_response = requests.post(
feedback_url,
headers=feedback_headers,
json=feedback_data,
)
feedback_response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
print("Feedback submitted successfully!")
except requests.exceptions.RequestException as e:
print(f"Failed to submit feedback: {e}")
Node.js Example
Here’s how you can send feedback using Node.js.
import OpenAI from 'openai';
import fetch from 'node-fetch';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const REQUESTY_API_KEY = process.env.REQUESTY_API_KEY;
const ROUTER_BASE_URL = 'https://router.requesty.ai/v1';
const FEEDBACK_BASE_URL = 'https://ingestion.requesty.ai/feedback/';
// Initialize OpenAI client
const client = new OpenAI({
apiKey: REQUESTY_API_KEY,
baseURL: ROUTER_BASE_URL,
});
async function generateWithFeedback() {
try {
const response = await client.chat.completions.create({
model: "anthropic/claude-3-7-sonnet-latest",
messages: [
{ role: "user", content: "What is AES?" }
]
});
const requestId = response.id;
// Send feedback POST request
const feedbackUrl = FEEDBACK_BASE_URL + requestId;
const headers = {
"Authorization": `Bearer ${REQUESTY_API_KEY}`,
"Content-Type": "application/json"
};
const feedbackData = {
data: {
message: "Test feedback message",
rating: 5,
helpful: true
}
};
const feedbackResponse = await fetch(feedbackUrl, {
method: 'POST',
headers: headers,
body: JSON.stringify(feedbackData)
});
if (feedbackResponse.ok) {
console.log("Feedback sent successfully");
} else {
console.error("Failed to send feedback:", feedbackResponse.statusText);
}
} catch (error) {
console.error('Error:', error);
}
}
generateWithFeedback();