{"record":{"id":"aa360c589037980f","repo":"BerriAI/litellm","slug":"error-apply-db-fixes-str-e","errorCode":null,"errorMessage":"Error apply_db_fixes: {str(e)}","messagePattern":"Error apply_db_fixes: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"db_scripts/update_unassigned_teams.py","lineNumber":33,"sourceCode":"            SET team_id = (\n                SELECT vt.team_id\n                FROM \"LiteLLM_VerificationToken\" vt\n                WHERE vt.token = \"LiteLLM_SpendLogs\".api_key\n            )\n            WHERE team_id IS NULL\n            AND EXISTS (\n                SELECT 1\n                FROM \"LiteLLM_VerificationToken\" vt\n                WHERE vt.token = \"LiteLLM_SpendLogs\".api_key\n            );\n        \"\"\"\n        response = await db.query_raw(sql_query)\n        print(\n            \"Updated unassigned teams, Response=%s\",\n            response,\n        )\n    except Exception as e:\n        raise Exception(f\"Error apply_db_fixes: {str(e)}\")\n    return\n","sourceCodeStart":15,"sourceCodeEnd":35,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/db_scripts/update_unassigned_teams.py#L15-L35","documentation":"In the OpenAI image-edit transformation, the provider's HTTP response body is expected to be JSON matching the ImageResponse schema. If raw_response.json() throws (body is HTML, empty, or malformed), the handler raises OpenAIError with the raw body text as the message and the HTTP status as status_code. The literal 'raw_response.text' is the fallback message source - meaning the body was not parseable JSON.","triggerScenarios":"Calling litellm.image_edit() and receiving a non-JSON body: a 5xx HTML error page from a proxy or the API, an empty body from a gateway timeout, truncated multipart responses, or an OAuth/SSO login page from a misconfigured api_base.","commonSituations":"Custom api_base pointing at a gateway that returns HTML errors; corporate proxies intercepting requests; provider incidents returning non-JSON 500 pages; oversized image uploads rejected by intermediaries with plain-text errors.","solutions":["Catch OpenAIError and log .status_code and .message (the raw body) to see what the server actually returned.","If using a custom api_base, curl the image edit endpoint directly and confirm it returns OpenAI-spec JSON.","Bypass corporate proxies or add proper exceptions for api.openai.com.","Retry transient 5xx non-JSON responses with backoff; if persistent, check status.openai.com."],"exampleFix":"# before\nimg = litellm.image_edit(model=\"gpt-image-1\", image=[...], prompt=\"...\")\n\n# after\ntry:\n    img = litellm.image_edit(model=\"gpt-image-1\", image=[...], prompt=\"...\")\nexcept litellm.exceptions.OpenAIError as e:\n    logger.error(\"image_edit failed %s: %s\", e.status_code, str(e.message)[:500])\n    raise","handlingStrategy":"try-catch","validationCode":"def looks_like_openai_endpoint(api_base: str) -> bool:\n    return api_base.rstrip(\"/\").endswith((\"api.openai.com\", \"openai.azure.com\")) or \"/v1\" in api_base","typeGuard":"from litellm.exceptions import OpenAIError\n\ndef is_non_json_response_error(e: BaseException) -> bool:\n    return isinstance(e, OpenAIError) and not str(getattr(e, \"message\", \"\")).strip().startswith(\"{\")","tryCatchPattern":"from litellm.exceptions import OpenAIError\n\ntry:\n    img = litellm.image_edit(model=\"gpt-image-1\", image=image, prompt=p)\nexcept OpenAIError as e:\n    logger.error(\"non-JSON body (%s): %s\", e.status_code, str(e.message)[:300])\n    if e.status_code >= 500:\n        time.sleep(2)  # retry once for transient gateway errors\n        img = litellm.image_edit(model=\"gpt-image-1\", image=image, prompt=p)\n    else:\n        raise","preventionTips":["curl your api_base once to confirm it returns JSON errors before wiring it into litellm.","Log the first 300 chars of the error body - HTML proxy pages are instantly recognizable.","Keep image payloads under gateway limits to avoid truncated multipart responses."],"tags":["openai","image-edit","response-parsing","litellm","http"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}