FoundationAgents/MetaGPT · error · RuntimeError

Request failed, msg: {self._event_source.decode('utf-8')}, p

Error message

Request failed, msg: {self._event_source.decode('utf-8')}, please ref to `https://open.bigmodel.cn/dev/api#error-code-v3`

What it means

ZhipuAI's AsyncSSEClient.stream() expects an async iterator of SSE events; when the HTTP layer returns raw bytes instead (which happens when the server responds with a non-SSE error body), it raises RuntimeError embedding the decoded error message and a link to BigModel's error-code docs. It indicates the streaming request failed server-side before any events were produced.

Source

Thrown at metagpt/provider/zhipuai/async_sse_client.py:16

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Desc   : async_sse_client to make keep the use of Event to access response
#           refs to `zhipuai/core/_sse_client.py`

import json
from typing import Any, Iterator


class AsyncSSEClient(object):
    def __init__(self, event_source: Iterator[Any]):
        self._event_source = event_source

    async def stream(self) -> dict:
        if isinstance(self._event_source, bytes):
            raise RuntimeError(
                f"Request failed, msg: {self._event_source.decode('utf-8')}, please ref to `https://open.bigmodel.cn/dev/api#error-code-v3`"
            )
        async for chunk in self._event_source:
            line = chunk.data.decode("utf-8")
            if line.startswith(":") or not line:
                return

            field, _p, value = line.partition(":")
            if value.startswith(" "):
                value = value[1:]
            if field == "data":
                if value.startswith("[DONE]"):
                    break
                data = json.loads(value)
                yield data

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Decode and read the embedded msg in the RuntimeError; it contains Zhipu's official error code.
  2. Validate/refresh the ZhipuAI api_key and confirm the account has quota.
  3. Check the model name against current GLM model ids.
  4. Catch the RuntimeError around stream consumption and surface the upstream error code to your monitoring.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    sse = await api.acreate_stream(**kwargs)
    async for event in sse.stream():
        ...
except RuntimeError as e:
    msg = str(e)
    if "error-code-v3" in msg:
        code = extract_upstream_error_code(msg)  # parse embedded JSON
        handle_zhipu_error(code)  # 401 -> refresh key, 429 -> backoff
    raise

Prevention

When it happens

Trigger: Calling zhipuai acreate_stream where the API returns an error status/body (invalid API key, rate limit, bad model name, malformed request); arequest hands back bytes, and the isinstance(self._event_source, bytes) check fires immediately on the first stream() call.

Common situations: Expired or wrong ZhipuAI API key, hitting QPS/quota limits, specifying a retired model id, or parameter errors (e.g. invalid messages payload) on the GLM endpoints.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/c51598ddc6227d4f. Report an issue: GitHub.