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.
Here’s how you can send feedback after a chat completion call:
Copy
import openaiimport requestsimport osrequesty_api_key = [SAFELY LOAD YOUR API KEY...]# Assume client is an initialized OpenAI client pointed at Requestyclient = openai.OpenAI(api_key=requesty_api_key, base_url="https://router.requesty.ai/v1")# 1. Make the initial requestresponse = client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": "Your prompt here"}],)# 2. Get the unique ID from the responserequest_id = response.id# 3. Send feedback to the Requesty APIfeedback_url = f"https://api.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}")