BerriAI/litellm · error · HTTPException
Failed to transform Braintrust response: {str(e)}
Error message
Failed to transform Braintrust response: {str(e)} What it means
This is the get_error_class factory of LiteLLM's OpenAI Containers transformation: it constructs and raises a BaseLLMException carrying the HTTP status code, the error message, and the response headers extracted from a failed container-API HTTP response. The literal 'error_message' is the parameter name - the actual text comes from the upstream response body. It is LiteLLM's normalization point for non-2xx responses from OpenAI container endpoints (e.g. /v1/containers file operations).
Source
Thrown at cookbook/litellm_proxy_server/braintrust_prompt_wrapper_server.py:233
except httpx.RequestError as e:
raise HTTPException(
status_code=502,
detail=f"Failed to connect to Braintrust API: {str(e)}",
)
except json.JSONDecodeError as e:
raise HTTPException(
status_code=502,
detail=f"Failed to parse Braintrust API response: {str(e)}",
)
print(f"braintrust_data: {braintrust_data}")
# Transform the response
try:
transformed_data = transform_braintrust_response(braintrust_data)
print(f"transformed_data: {transformed_data}")
return JSONResponse(content=transformed_data)
except Exception as e:
raise HTTPException(
status_code=500,
detail=f"Failed to transform Braintrust response: {str(e)}",
)
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {"status": "healthy", "service": "braintrust-prompt-wrapper"}
@app.get("/")
async def root():
"""Root endpoint with service information."""
return {
"service": "Braintrust Prompt Wrapper for LiteLLM",
"version": "1.0.0",
"endpoints": {View on GitHub (pinned to 6c2dcb801b)
Solutions
- Catch litellm.exceptions.BaseLLMException (or litellm.APIError) and read .status_code, .message, .headers.
- 404: verify container_id/file_id exists in the same org/project as the key.
- 401/403: confirm the key is valid and has container API access.
- Check .headers for retry-after on 429 and back off accordingly.
Example fix
# before
content = litellm.get_container_file_content(...)
# after
try:
content = litellm.get_container_file_content(...)
except litellm.exceptions.BaseLLMException as e:
if e.status_code == 404:
raise FileNotFoundError(e.message) from e
raise Defensive patterns
Strategy: try-catch
Validate before calling
def container_file_url_ok(container_id: str, file_id: str) -> bool:
return container_id.startswith("ctr_") and file_id.startswith("file-") Type guard
from litellm.llms.base_llm.chat.transformation import BaseLLMException
def is_container_api_error(e: BaseException) -> bool:
return isinstance(e, BaseLLMException) Try / catch
from litellm.exceptions import APIError
try:
content = litellm.get_container_file_content(...)
except APIError as e:
sc = getattr(e, "status_code", None)
if sc == 404:
raise FileNotFoundError(str(e)) from e
if sc == 429:
retry_after = float(getattr(e, "headers", {}).get("retry-after", 5))
time.sleep(retry_after)
raise Prevention
- Validate container_id/file_id format and ownership before requests.
- Cache id-to-project mappings to avoid cross-org 404s.
- Honor retry-after headers on container API rate limits.
When it happens
Trigger: Calling litellm container/file APIs (e.g. retrieving binary file content from a container) when OpenAI returns a non-2xx status: 401 invalid key, 404 unknown container or file id, 400 bad request, or 429 rate limiting. The HTTP handler extracts status/body/headers and routes them through this factory to raise BaseLLMException.
Common situations: Using an expired or scoped-down API key that lacks container access; referencing a container_id or file_id from another project/org; preview API changes to the containers endpoints; uploading then immediately downloading files before processing completes.
Related errors
- Error apply_db_fixes: {str(e)}
- Unclassified keys in {PRICES_PATH.name}: {', '.join(unclassi
- No Braintrust API token provided. Pass via Authorization hea
- Braintrust API error: {e.response.text}
- Failed to connect to Braintrust API: {str(e)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/a8bb43a6cf7a0f7b.
Report an issue: GitHub.