HKUDS/Vibe-Trading · error · RuntimeError

{source} produces a non-ASCII HTTP header ({name!r}). Use an

Error message

{source} produces a non-ASCII HTTP header ({name!r}). Use an ASCII-only header value.

What it means

Raised by _validate_explicit_headers when an explicitly configured provider header (name or value) contains non-ASCII characters. HTTPX/httpcore only accept ASCII header bytes, so encoding would fail later at request time; the library fails fast with a clear message instead.

Source

Thrown at agent/src/providers/llm.py:773

    if not value.isascii():
        raise RuntimeError(
            f"{source} contains non-ASCII characters and cannot be sent in an "
            "HTTP Authorization header. Replace it with the raw provider API key "
            "instead of pasted JSON, HTML, or formatted text."
        )
    if any(ord(char) < 33 or ord(char) > 126 for char in value):
        raise RuntimeError(
            f"{source} contains whitespace or control characters and cannot be "
            "sent in an HTTP Authorization header. Replace it with the raw "
            "provider API key."
        )


def _validate_explicit_headers(headers: Mapping[str, str], *, source: str) -> None:
    """Reject explicit provider headers that HTTPX cannot encode safely."""
    for name, value in headers.items():
        if not name.isascii() or not value.isascii():
            raise RuntimeError(
                f"{source} produces a non-ASCII HTTP header ({name!r}). "
                "Use an ASCII-only header value."
            )
        if "\r" in value or "\n" in value:
            raise RuntimeError(
                f"{source} produces an invalid multiline HTTP header ({name!r})."
            )


def _redact_proxy_url(name: str, raw: str | None) -> str:
    """Return a credential-free proxy URL label."""
    if not raw:
        return "unset"
    if name.upper().endswith("NO_PROXY"):
        return "set"
    return _redact_base_url_for_log(raw)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Make the header value ASCII-only (strip/replace non-ASCII characters)
  2. Percent-encode or base64-encode any non-ASCII payload and put it in the request body instead of a header
  3. If the value is meant to be Unicode metadata, send it as a JSON body field rather than an HTTP header

Example fix

# before
extra_headers = {"X-Title": "Vibe Trading – 分析"}

# after
extra_headers = {"X-Title": "Vibe Trading - analytics"}
Defensive patterns

Strategy: validation

Validate before calling

def is_ascii_headers(headers: Mapping[str, str]) -> bool:
    return all(name.isascii() and value.isascii() for name, value in headers.items())

assert is_ascii_headers(extra_headers), 'headers must be ASCII'

Type guard

def is_ascii_headers(headers: Mapping[str, str]) -> bool:
    return all(n.isascii() and v.isascii() for n, v in headers.items())

Prevention

When it happens

Trigger: Passing extra_headers (e.g. via build_llm provider config) where a header name or value contains non-ASCII characters, such as a descriptive Authorization token, a Unicode organization name, or metadata copied from a browser request.

Common situations: Copy-pasting headers from browser devtools or curl with UTF-8 characters (e.g. 'X-Title: Vibe Trading – 分析'); non-ASCII API keys or user-agent strings; localized labels embedded in header values.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/7cf9a6df266e9578. Report an issue: GitHub.