xtekky/gpt4free · error · ResponseError
Unexpected content type: {mime_type}
Error message
Unexpected content type: {mime_type} What it means
Raised as ResponseError at the end of Puter's response handling when the HTTP content-type is none of text/plain, text/event-stream, or application/json. The provider only knows how to parse those three shapes; anything else (e.g. text/html from a proxy or WAF page) is rejected.
Source
Thrown at g4f/Provider/needs_auth/Puter.py:565
[
{
"id": tools_idx,
"type": "function",
"id": data.get("id"),
"function": {
"name": data.get("name"),
"arguments": data.get("input"),
},
}
]
)
tools_idx += 1
elif data.get("type") == "tool_calls":
yield ToolCalls(data.get("tool_calls", []))
elif data.get("type") == "usage":
yield Usage.from_dict(data.get("usage", {}))
else:
raise ResponseError(f"Unexpected content type: {mime_type}")
View on GitHub (pinned to 973504e177)
Solutions
- Retry without a proxy or with a different proxy to rule out HTML injection by an intermediary
- Check whether the Puter endpoint is reachable directly (curl the endpoint and inspect content-type)
- Update g4f if a newer release handles the new content type
Example fix
# before response = client.chat.completions.create(model=..., messages=msgs) # Unexpected content type: text/html # after client = g4f.Client(proxies=None) # bypass proxy that injects HTML response = client.chat.completions.create(model=..., messages=msgs)
Defensive patterns
Strategy: fallback
Try / catch
from g4f.errors import ResponseError
try:
result = ...create(...)
except ResponseError as e:
if 'Unexpected content type' in str(e):
result = retry_without_proxy() # proxy likely injected HTML
else:
raise Prevention
- Test provider reachability from the deployment network before relying on it
- Avoid proxies that rewrite/inject content for API traffic
When it happens
Trigger: Puter (or an intermediary proxy/CDN) responds with text/html — a login page, captcha, or error page — or a content type introduced by an upstream change.
Common situations: Requests routed through a corporate proxy that injects HTML block pages, Puter under maintenance returning an HTML error page, region-blocked access returning an HTML notice.
Related errors
- API key is required for Puter.js API
- result["error"].get("message", result["error"])
- result
- Create images failed. Code: {response.status}
- Polling images faild. Code: {response.status}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/76456619a6d04150.
Report an issue: GitHub.