Skip to content

github-copilot (Claude): 400 "text content blocks must contain non-whitespace text" from whitespace-only assistant message #31259

Closed as not planned

Description

@Tushar49

Description

github-copilot Claude models hit a hard 400 from the Anthropic /v1/messages endpoint once the conversation history contains an assistant turn whose only text block is whitespace.

Error:

AI_APICallError: messages: text content blocks must contain non-whitespace text
POST https://api.githubcopilot.com/v1/messages

The offending entry in the request body is a single space:

{"role":"assistant","content":[{"type":"text","text":" "}]}

Root cause: ProviderTransform.message (packages/opencode/src/provider/transform.ts) already strips empty text parts before sending to Anthropic, but the @ai-sdk/anthropic branch filters text with part.text !== "" (exact empty), so a whitespace-only " " slips through. The reasoning filter right beside it already uses .trim() — so the two are inconsistent. A lone-space text block reaches Anthropic and is rejected.

Affected Claude models (e.g. claude-opus-4.7, claude-opus-4.7-1m-internal) are listed and selectable — they just 400 on the next request once a whitespace-only assistant turn is in history. This is easy to hit when a model-fallback setup replays an empty/whitespace response to Claude.

I have a fix + tests ready and will open a PR referencing this issue.

Plugins

model-fallback plugin in use, but the bug is in core ProviderTransform and is plugin-independent

OpenCode version

1.16.2

Steps to reproduce

  1. Use a github-copilot Claude model (e.g. claude-opus-4.7).
  2. Get an assistant turn into history whose only text content is whitespace (e.g. an empty/whitespace response that is replayed to Claude — common with a model-fallback chain).
  3. Send another message. The request to /v1/messages fails with 400 "text content blocks must contain non-whitespace text".

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. github-actions commented on Jun 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Your issue adds useful specificity (whitespace-only " " vs strictly empty "", and the inconsistency between the reasoning filter using .trim() vs the text filter using exact equality). If your upcoming PR addresses that gap, please reference all three issues so the fixes can be coordinated.

  2. rekram1-node commented on Jun 7, 2026

    @rekram1-node
    Collaborator

    Send the session this occurred in?

  3. rekram1-node commented on Jun 7, 2026

    @rekram1-node
    Collaborator

    opencode export > session.json

  4. Guikingone commented on Jul 3, 2026

    @Guikingone

    Hi @rekram1-node 👋🏻

    Faced the same situation than @Tushar49, here's the export.json:

    {
      "info": {
        "id": "ses_0d8930a8cffesh0qUXuzUQDsgs",
        "slug": "neon-garden",
        "projectID": "global",
        "directory": "/Users/guillaumeloulier/Desktop",
        "path": "Users/guillaumeloulier/Desktop",
        "title": "New session - 2026-07-03T10:01:19.987Z",
        "agent": "build",
        "model": {
          "id": "claude-opus-4-8",
          "providerID": "venice",
          "variant": "high"
        },
        "version": "1.17.13",
        "summary": {
          "additions": 0,
          "deletions": 0,
          "files": 0
        },
        "cost": 0,
        "tokens": {
          "input": 0,
          "output": 0,
          "reasoning": 0,
          "cache": {
            "read": 0,
            "write": 0
          }
        },
        "time": {
          "created": 1783072879987,
          "updated": 1783072880560
        }
      },
      "messages": [
        {
          "info": {
            "role": "user",
            "time": {
              "created": 1783072880039
            },
            "agent": "build",
            "model": {
              "providerID": "venice",
              "modelID": "claude-opus-4-8",
              "variant": "high"
            },
            "summary": {
              "diffs": []
            },
            "id": "msg_f276cf5a7001JYH5KD5J41bzdH",
            "sessionID": "ses_0d8930a8cffesh0qUXuzUQDsgs"
          },
          "parts": [
            {
              "type": "text",
              "text": "hey, what's up?",
              "id": "prt_f276cf5ab001wkMoZu4Rk107SB",
              "sessionID": "ses_0d8930a8cffesh0qUXuzUQDsgs",
              "messageID": "msg_f276cf5a7001JYH5KD5J41bzdH"
            }
          ]
        },
        {
          "info": {
            "parentID": "msg_f276cf5a7001JYH5KD5J41bzdH",
            "role": "assistant",
            "mode": "build",
            "agent": "build",
            "variant": "high",
            "path": {
              "cwd": "/Users/guillaumeloulier/Desktop",
              "root": "/"
            },
            "cost": 0,
            "tokens": {
              "input": 0,
              "output": 0,
              "reasoning": 0,
              "cache": {
                "read": 0,
                "write": 0
              }
            },
            "modelID": "claude-opus-4-8",
            "providerID": "venice",
            "time": {
              "created": 1783072880470,
              "completed": 1783072893318
            },
            "error": {
              "name": "APIError",
              "data": {
                "message": "Bad Request: system: text content blocks must contain non-whitespace text",
                "statusCode": 400,
                "isRetryable": false,
                "responseHeaders": {
                  "access-control-allow-origin": "*",
                  "access-control-expose-headers": "*",
                  "cache-control": "no-store, no-cache, private, must-revalidate",
                  "cdn-cache-control": "no-store",
                  "cf-cache-status": "DYNAMIC",
                  "cf-ray": "a1550cac7e253108-MRS",
                  "connection": "keep-alive",
                  "content-length": "109",
                  "content-security-policy": "default-src 'none'; frame-ancestors 'none'; upgrade-insecure-requests",
                  "content-type": "application/json; charset=utf-8",
                  "date": "Fri, 03 Jul 2026 10:01:33 GMT",
                  "etag": "W/\"6d-OK52g8Jjj/gLF45b81vxTnzmebk\"",
                  "permissions-policy": "geolocation=(), camera=()",
                  "referrer-policy": "strict-origin",
                  "server": "cloudflare",
                  "strict-transport-security": "max-age=31536000; includeSubDomains; preload",
                  "vary": "Accept-Encoding",
                  "x-cloud-trace-context": "366f44a9ad1ed18b67ef8fd45f83143d",
                  "x-content-type-options": "nosniff",
                  "x-frame-options": "SAMEORIGIN",
                  "x-ratelimit-limit-requests": "500",
                  "x-ratelimit-limit-tokens": "5000000",
                  "x-ratelimit-remaining": "20",
                  "x-ratelimit-remaining-requests": "498",
                  "x-ratelimit-remaining-tokens": "5000000",
                  "x-ratelimit-reset-requests": "1783072953103",
                  "x-ratelimit-reset-tokens": "1783072953104",
                  "x-ratelimit-resets": "1783072923091",
                  "x-venice-version": "outerface-api-server-us-east1-04659-2gz",
                  "set-cookie": "_cfuvid=KS23uDuy04T9.i2VnNzbXd6JXRYcC.dI4V1gwnJRhsQ-1783072892.8773532-1.0.1.1-OR9PW4SdfMTRXFgf0KyGQZgGw.LgZB6wc1S8DJvBXL4; HttpOnly; SameSite=None; Secure; Path=/; Domain=venice.ai"
                },
                "responseBody": "{\"error\":\"system: text content blocks must contain non-whitespace text\",\"request_id\":\"IBzvybzHGEeYWTo7vLT7A\"}",
                "metadata": {
                  "url": "https://api.venice.ai/api/v1/chat/completions"
                }
              }
            },
            "id": "msg_f276cf756001njNRjuGRE7WoYn",
            "sessionID": "ses_0d8930a8cffesh0qUXuzUQDsgs"
          },
          "parts": []
        }
      ]
    }

    PS: I'm using Venice here but the error message is the same.

  5. github-actions commented on Sep 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions