Report API
Report failed or problematic completions to improve Morph model quality
curl --request POST \
--url https://api.morphllm.com/api/report \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"completion_id": "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d",
"failure_reason": "Traceback: ... Generated code had syntax errors",
"user_query": "Add error handling to the login function"
}
'import requests
url = "https://api.morphllm.com/api/report"
payload = {
"completion_id": "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d",
"failure_reason": "Traceback: ... Generated code had syntax errors",
"user_query": "Add error handling to the login function"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
completion_id: 'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
failure_reason: 'Traceback: ... Generated code had syntax errors',
user_query: 'Add error handling to the login function'
})
};
fetch('https://api.morphllm.com/api/report', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.morphllm.com/api/report",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'completion_id' => 'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'failure_reason' => 'Traceback: ... Generated code had syntax errors',
'user_query' => 'Add error handling to the login function'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.morphllm.com/api/report"
payload := strings.NewReader("{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.morphllm.com/api/report")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.morphllm.com/api/report")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Report successfully recorded",
"data": {
"request_log_id": "req_123456789",
"reported_at": "2024-01-15T10:30:00Z"
}
}{
"error": {
"code": "invalid_request_error",
"message": "The request body is missing the `model` field."
}
}{
"error": {
"code": "unauthorized",
"message": "Invalid API key provided."
}
}{
"error": {
"code": "rate_limited",
"message": "Too many requests. Retry in 12 seconds."
}
}{
"error": {
"code": "internal_error",
"message": "Something went wrong on our side."
}
}Overview
Report failed or problematic completions to help improve Morph’s quality. This endpoint allows you to flag completions that produced incorrect, malformed, or problematic code so our team can investigate and improve the models. When to use this endpoint:- Generated code has syntax errors
- Applied changes broke existing functionality
- Model output doesn’t match the intended instruction
- Generated code produces runtime errors or exceptions
- Code quality issues (security vulnerabilities, bad practices)
x-completion-id) or server logs from your original apply request.
Request Body
Response
Error Codes
| Status | Description |
|---|---|
200 | Report successfully recorded |
400 | Invalid request parameters |
401 | Invalid or missing API key |
404 | Completion ID not found |
409 | Request already reported |
Examples
cURL
curl -X POST "https://morphllm.com/api/report" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"completion_id": "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d",
"failure_reason": "Generated code had syntax errors: SyntaxError: Unexpected token in JSON",
"user_query": "Add error handling to the user login function"
}'
JavaScript (fetch)
const reportFailure = async (completionId, failureReason, userQuery = null) => {
const payload = {
completion_id: completionId,
failure_reason: failureReason,
};
// Include user_query only if provided
if (userQuery) {
payload.user_query = userQuery;
}
const response = await fetch('https://morphllm.com/api/report', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
};
// Usage with user query
try {
const result = await reportFailure(
'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'Generated code produces runtime error: TypeError: Cannot read property',
'Add validation to user input fields'
);
console.log('Report submitted:', result);
} catch (error) {
console.error('Failed to submit report:', error);
}
// Usage without user query
try {
const result = await reportFailure(
'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'Generated code produces runtime error: TypeError: Cannot read property'
);
console.log('Report submitted:', result);
} catch (error) {
console.error('Failed to submit report:', error);
}
Python (requests)
import requests
import json
def report_failure(completion_id, failure_reason, api_key, user_query=None):
url = "https://morphllm.com/api/report"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"completion_id": completion_id,
"failure_reason": failure_reason
}
# Include user_query only if provided
if user_query:
payload["user_query"] = user_query
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status() # Raises an HTTPError for bad responses
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error submitting report: {e}")
return None
# Usage with user query
api_key = "your-api-key"
completion_id = "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d"
failure_reason = """
Traceback (most recent call last):
File "generated_code.py", line 10, in <module>
result = process_data(invalid_input)
File "generated_code.py", line 5, in process_data
return data.split('.')
AttributeError: 'NoneType' object has no attribute 'split'
"""
user_query = "Refactor the data processing function to handle null values"
result = report_failure(completion_id, failure_reason, api_key, user_query)
if result:
print(f"Report submitted successfully: {result}")
# Usage without user query
result = report_failure(completion_id, failure_reason, api_key)
if result:
print(f"Report submitted successfully: {result}")
Node.js (axios)
const axios = require('axios');
async function reportFailure(completionId, failureReason, apiKey, userQuery = null) {
try {
const payload = {
completion_id: completionId,
failure_reason: failureReason,
};
// Include user_query only if provided
if (userQuery) {
payload.user_query = userQuery;
}
const response = await axios.post('https://morphllm.com/api/report', payload, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
});
return response.data;
} catch (error) {
if (error.response) {
// Server responded with error status
console.error('Server error:', error.response.data);
throw new Error(`Server error: ${error.response.status} - ${error.response.data.error?.message}`);
} else if (error.request) {
// Request was made but no response received
console.error('Network error:', error.request);
throw new Error('Network error: No response received');
} else {
// Something else happened
console.error('Request error:', error.message);
throw new Error(`Request error: ${error.message}`);
}
}
}
// Usage with user query
(async () => {
try {
const result = await reportFailure(
'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'Generated code fails unit tests: Expected 5 but got undefined',
'your-api-key',
'Add unit tests for the calculate function'
);
console.log('Success:', result.message);
console.log('Report ID:', result.data?.request_log_id);
console.log('Reported at:', result.data?.reported_at);
} catch (error) {
console.error('Failed to report:', error.message);
}
})();
// Usage without user query
(async () => {
try {
const result = await reportFailure(
'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'Generated code fails unit tests: Expected 5 but got undefined',
'your-api-key'
);
console.log('Success:', result.message);
console.log('Report ID:', result.data?.request_log_id);
console.log('Reported at:', result.data?.reported_at);
} catch (error) {
console.error('Failed to report:', error.message);
}
})();
Response Example
Successful response (200 OK):{
"success": true,
"message": "Report successfully recorded",
"data": {
"request_log_id": "req_123456789",
"reported_at": "2024-01-15T10:30:00Z"
}
}
{
"error": {
"message": "Missing required parameter: completion_id",
"type": "invalid_request_error",
"code": "missing_parameter"
}
}
Authorizations
Morph API key, passed as Authorization: Bearer sk-.... Create keys at https://www.morphllm.com/dashboard/api-keys.
Body
Report request for failed completion
A single problematic completion, identified by id and described by its failure.
The completion ID from the original request (found in response headers or logs)
"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d"
Description of what went wrong (Error message, traceback, etc.)
"Traceback: ... Generated code had syntax errors"
Optional: The original user instruction that led to the problematic completion
2000"Add error handling to the login function"
Response
Report successfully recorded
Acknowledgement that the report was stored, with the internal record id.
curl --request POST \
--url https://api.morphllm.com/api/report \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"completion_id": "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d",
"failure_reason": "Traceback: ... Generated code had syntax errors",
"user_query": "Add error handling to the login function"
}
'import requests
url = "https://api.morphllm.com/api/report"
payload = {
"completion_id": "chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d",
"failure_reason": "Traceback: ... Generated code had syntax errors",
"user_query": "Add error handling to the login function"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
completion_id: 'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
failure_reason: 'Traceback: ... Generated code had syntax errors',
user_query: 'Add error handling to the login function'
})
};
fetch('https://api.morphllm.com/api/report', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.morphllm.com/api/report",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'completion_id' => 'chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d',
'failure_reason' => 'Traceback: ... Generated code had syntax errors',
'user_query' => 'Add error handling to the login function'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.morphllm.com/api/report"
payload := strings.NewReader("{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.morphllm.com/api/report")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.morphllm.com/api/report")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"completion_id\": \"chatcmpl-9d9e2fc21c094f4eacbcee0009f2f12d\",\n \"failure_reason\": \"Traceback: ... Generated code had syntax errors\",\n \"user_query\": \"Add error handling to the login function\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Report successfully recorded",
"data": {
"request_log_id": "req_123456789",
"reported_at": "2024-01-15T10:30:00Z"
}
}{
"error": {
"code": "invalid_request_error",
"message": "The request body is missing the `model` field."
}
}{
"error": {
"code": "unauthorized",
"message": "Invalid API key provided."
}
}{
"error": {
"code": "rate_limited",
"message": "Too many requests. Retry in 12 seconds."
}
}{
"error": {
"code": "internal_error",
"message": "Something went wrong on our side."
}
}