xtekky/gpt4free · error · ResponseError
Invalid response: {result}
Error message
Invalid response: {result} What it means
Raised as ResponseError after POSTing to {base_url}/{model}/predictions when the returned JSON has no 'id' key. Replicate normally returns a prediction object with an id used to open the streaming URL; anything else means the creation call did not produce a usable prediction.
Source
Thrown at g4f/Provider/needs_auth/Replicate.py:71
"prompt": format_prompt(messages),
**filter_none(
system_prompt=system_prompt,
max_new_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
top_k=top_k,
stop_sequences=",".join(stop) if stop else None,
),
**extra_body,
},
}
url = f"{base_url.rstrip('/')}/{model}/predictions"
async with session.post(url, json=data) as response:
message = "Model not found" if response.status == 404 else None
await raise_for_status(response, message)
result = await response.json()
if "id" not in result:
raise ResponseError(f"Invalid response: {result}")
async with session.get(
result["urls"]["stream"], headers={"Accept": "text/event-stream"}
) as response:
await raise_for_status(response)
event = None
async for line in response.iter_lines():
if line.startswith(b"event: "):
event = line[7:]
if event == b"done":
break
elif event == b"output":
if line.startswith(b"data: "):
new_text = line[6:].decode()
if new_text:
yield new_text
else:
yield "\n"
View on GitHub (pinned to 973504e177)
Solutions
- Inspect the raised message — it contains the full JSON body returned by Replicate
- Verify the api_key is a valid Replicate token (starts with r8_)
- Verify the model slug exists and is hosted on api.replicate.com when using a key
Example fix
# before
response = client.chat.completions.create(model='owner/model', provider=g4f.Provider.Replicate, api_key=key)
# after
try:
response = client.chat.completions.create(model='owner/model', provider=g4f.Provider.Replicate, api_key=key)
except g4f.errors.ResponseError as e:
logging.error('Replicate prediction creation failed: %s', e)
raise Defensive patterns
Strategy: try-catch
Try / catch
from g4f.errors import ResponseError
try:
result = ...create(provider=g4f.Provider.Replicate)
except ResponseError as e:
logging.error('Replicate body: %s', e)
if 'auth' in str(e).lower():
rotate_replicate_token()
else:
raise Prevention
- Log the raw response body carried in the error — it names the real cause
- Validate model slugs (owner/name) against Replicate's catalog before calling
When it happens
Trigger: The prediction-creation endpoint returns an error object (missing/invalid token with 200-style handling, model not deployable, malformed input) so the response JSON lacks 'id'.
Common situations: Replicate API token invalid so the POST returns an auth error document, model slug typo handled as JSON error, upstream schema change.
Related errors
- result
- api_key is missing
- Failed to upload file: {response.status} {error_text}
- Cohere API Error: {data['error']}
- Failed to upload file: {result}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/372e8dfd2ade07db.
Report an issue: GitHub.