{"record":{"id":"24b2787f21deff78","repo":"BerriAI/litellm","slug":"promptlayer-did-not-successfully-log-the-response","errorCode":null,"errorMessage":"Promptlayer did not successfully log the response!","messagePattern":"Promptlayer did not successfully log the response!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"litellm/integrations/prompt_layer.py","lineNumber":66,"sourceCode":"                \"https://api.promptlayer.com/rest/track-request\",\n                json={\n                    \"function_name\": \"openai.ChatCompletion.create\",\n                    \"kwargs\": new_kwargs,\n                    \"tags\": tags,\n                    \"request_response\": dict(response_obj),\n                    \"request_start_time\": int(start_time.timestamp()),\n                    \"request_end_time\": int(end_time.timestamp()),\n                    \"api_key\": self.key,\n                    # Optional params for PromptLayer\n                    # \"prompt_id\": \"<PROMPT ID>\",\n                    # \"prompt_input_variables\": \"<Dictionary of variables for prompt>\",\n                    # \"prompt_version\":1,\n                },\n            )\n\n            response_json: Final = request_response.json()\n            if not request_response.json().get(\"success\", False):\n                raise Exception(\"Promptlayer did not successfully log the response!\")\n\n            print_verbose(f\"Prompt Layer Logging: success - final response object: {request_response.text}\")\n\n            if \"request_id\" in response_json:\n                if metadata:\n                    response: Final = litellm.module_level_client.post(\n                        \"https://api.promptlayer.com/rest/track-metadata\",\n                        json={\n                            \"request_id\": response_json[\"request_id\"],\n                            \"api_key\": self.key,\n                            \"metadata\": metadata,\n                        },\n                    )\n                    print_verbose(f\"Prompt Layer Logging: success - metadata post response object: {response.text}\")\n\n        except Exception:\n            print_verbose(f\"error: Prompt Layer Error - {traceback.format_exc()}\")\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/prompt_layer.py#L48-L84","documentation":"After POSTing a track-request payload to api.promptlayer.com, PromptLayer raises a generic Exception whenever the response JSON lacks success: true. This means the request reached PromptLayer but was rejected (auth, malformed body, or server-side failure) — it is not a network error, the HTTP layer succeeded.","triggerScenarios":"Calling litellm with the prompt_layer callback while PROMPTLAYER_API_KEY is wrong/expired (key sent in the JSON body); prompt template references (prompt_id, prompt_input_variables) that do not match the account; PromptLayer API returning success: false for schema violations.","commonSituations":"Rotated or typo'd PromptLayer API keys; using a prompt id from a different workspace; PromptLayer API changes or transient 4xx/5xx that still return JSON with success false.","solutions":["Verify PROMPTLAYER_API_KEY is the correct active key for the same workspace as any prompt ids used","Log request_response.text just before the raise (or reproduce the POST in curl) to see PromptLayer's actual error message","Remove unsupported optional fields (prompt_id / prompt_input_variables) from the payload and retry","If the failure is transient, wrap the call and retry once with backoff"],"exampleFix":"# before\nresponse_json = request_response.json()\nif not request_response.json().get(\"success\", False):\n    raise Exception(\"Promptlayer did not successfully log the response!\")\n\n# after — surface the upstream reason\nif not response_json.get(\"success\", False):\n    raise Exception(\n        f\"PromptLayer logging failed (status={request_response.status_code}): \"\n        f\"{response_json.get('message', request_response.text)}\"\n    )","handlingStrategy":"retry","validationCode":"import litellm\nimport os\n\nassert os.getenv(\"PROMPTLAYER_API_KEY\"), \"PROMPTLAYER_API_KEY missing — PromptLayer logging will fail\"","typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        resp = litellm.completion(model=\"gpt-4o\", messages=msgs)\n        break\n    except Exception as e:\n        if \"Promptlayer did not successfully log\" in str(e) and attempt == 0:\n            continue  # transient PromptLayer rejection — retry once\n        raise","preventionTips":["Treat PromptLayer callback failures as non-fatal: wrap completion calls or run the callback in fire-and-forget mode so logging outages don't break inference","Rotate the PromptLayer API key with the same discipline as provider keys and monitor its expiry","Log the full upstream response body when debugging — PromptLayer puts the real reason in JSON other than success=false"],"tags":["promptlayer","logging","api-key","callbacks"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}