xtekky/gpt4free · error · Exception
Failed to upload file: {result}
Error message
Failed to upload file: {result} What it means
Generic Exception raised by DeepSeekAuth's file-upload helper: the POST to DeepSeek's file-upload endpoint succeeded at the HTTP level (raise_for_status passed) but the JSON response contains no "data" key, so no file id could be extracted. The full response body is embedded in the message via debug logging and the exception.
Source
Thrown at g4f/Provider/needs_auth/DeepSeek.py:236
# Create multipart form data
data = FormData()
data.add_field("file", file, filename=filename, content_type="application/pdf")
async with session.post(
FILE_UPLOAD_ENDPOINT, data=data, headers={"accept": "application/json"}
) as response:
debug.log(f"DeepSeekAuth: File upload response status: {response.status}")
await raise_for_status(response)
result = await response.json()
debug.log(f"DeepSeekAuth: File upload response: {result}")
if "data" in result:
file_id = result["data"].get("id")
debug.log(f"DeepSeekAuth: File uploaded successfully, file_id: {file_id}")
return {"file_id": file_id, "filename": filename, "size": len(file)}
else:
debug.error(f"DeepSeekAuth: Failed to upload file: {result}")
raise Exception(f"Failed to upload file: {result}")
@classmethod
async def delete_chat_session(
cls, session: StreamSession, chat_session_id: str, headers: dict
):
"""
Delete a chat session from DeepSeek.
Tries multiple approaches (DELETE/POST with JSON body/query params) until one succeeds.
Args:
session: StreamSession instance
chat_session_id: The session ID to delete
headers: Request headers including authorization
"""
import json as json_module
# Try different deletion approaches - POST with JSON body first (as seen in HAR)View on GitHub (pinned to 973504e177)
Solutions
- Inspect the {result} payload in the message — it usually contains the upstream reason (format, size, permission).
- Retry with a supported file type and a smaller file.
- Re-export a fresh HAR file so the auth token is fully valid for upload endpoints.
- If the schema changed, update g4f to the latest version.
Example fix
# before
resp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs, media=["huge_video.mp4"])
# Exception: Failed to upload file: {'code': 413}
# after
resp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs, media=["photo.jpg"]) Defensive patterns
Strategy: try-catch
Validate before calling
def media_uploadable(paths):
allowed = {".jpg", ".jpeg", ".png", ".webp", ".pdf", ".txt", ".docx"}
return all(Path(p).suffix.lower() in allowed and Path(p).stat().st_size < 50 * 1024 * 1024 for p in paths) Try / catch
try:
resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs, media=files)
except Exception as e:
if "Failed to upload file" in str(e):
shrink_or_convert_media(files) Prevention
- Validate file type/size before attaching media.
- Keep the HAR token fresh so upload endpoints accept it.
- Log the response payload embedded in the exception — it names the cause.
When it happens
Trigger: Attaching media (images/files) to a DeepSeek authenticated chat request and the upload API returns an error payload or unexpected schema — e.g. unsupported file type, file too large, auth token accepted for chat but rejected for uploads, or DeepSeek changed the response shape.
Common situations: Uploading files over the size/format limit; expired or partially-scoped HAR token; DeepSeek backend change; empty file passed as media.
Related errors
- Failed to upload file: {res_json}
- Upload failed: {result}
- {data['code']}:{data['details']}
- Failed to parse session response: {session_data}
- Upload timeout for {file_id}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/97e8af8bdc35a57e.
Report an issue: GitHub.