xtekky/gpt4free · error · MissingAuthError

Invalid response: {last_msg}

Error message

Invalid response: {last_msg}

What it means

CopilotSession finished reading the WebSocket event stream without receiving the completion signal, so 'done' stayed False. MissingAuthError is raised with the last raw message, reflecting that truncated Copilot streams are most often caused by session/auth rejection rather than payload problems.

Source

Thrown at g4f/Provider/CopilotSession.py:231

                mime_type = is_accepted_format(
                    base64.b64decode(msg.get("content")[:12])
                )
                yield ImagePreview(
                    f"data:{mime_type};base64,{msg.get('content')}", image_prompt
                )
            elif msg.get("event") == "chainOfThought":
                yield Reasoning(msg.get("text"))
            elif msg.get("event") == "error":
                raise RuntimeError(f"Error: {msg}")
            elif msg.get("event") not in [
                "received",
                "startMessage",
                "partCompleted",
                "connected",
            ]:
                debug.log(f"Copilot Message: {msg_txt[:100]}...")
        if not done:
            raise MissingAuthError(f"Invalid response: {last_msg}")
        if sources:
            yield Sources(sources.values())


if has_nodriver:

    async def click_trunstile(
        page: nodriver.Tab, element='document.getElementById("cf-turnstile")'
    ):
        for _ in range(3):
            size = None
            for idx in range(15):
                size = await page.js_dumps(f"{element}?.getBoundingClientRect()||{{}}")
                debug.log(f"Found size: {size.get('x'), size.get('y')}")
                if "x" not in size:
                    break
                await page.flash_point(size.get("x") + idx * 3, size.get("y") + idx * 3)
                await page.mouse_click(size.get("x") + idx * 3, size.get("y") + idx * 3)

View on GitHub (pinned to 973504e177)

Solutions

  1. Inspect last_msg from the exception to see the final event received
  2. Refresh auth and retry with a new conversation
  3. If a renamed completion event is visible in logs, update the done-detection logic in the provider
Defensive patterns

Strategy: fallback

Try / catch

from g4f.errors import MissingAuthError

try:
    async for chunk in CopilotSession.create_async_generator(model, messages):
        yield chunk
except MissingAuthError as e:
    if 'Invalid response' in str(e):
        async for chunk in AlternativeProvider.create_async_generator(model, messages):
            yield chunk
    else:
        raise

Prevention

When it happens

Trigger: Stream ended after handshake/start events with no content events; websocket closed mid-turn; completion event renamed so it is not recognized; session invalidated server-side mid-conversation.

Common situations: Expired cookies/token mid-session; new event types from Microsoft breaking completion detection; rate limiting ending streams early; network drop.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/3af6647e0dcf83f6. Report an issue: GitHub.