# language_models: Filter out whitespace-only text content parts for OpenAI and OpenAI compatible providers \(\#40316\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/160bf915aa4661dd3f5a0991be09bfb9cb2223df)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 160bf915aa4661dd3f5a0991be09bfb9cb2223df

Requested commit: 160bf915aa4661dd3f5a0991be09bfb9cb2223df

Commit: 160bf915aa4661dd3f5a0991be09bfb9cb2223df

Tree: 85b82953f03278d07253f80896254b0bf57ae3e6

Author: Maokaman1

Committer: GitHub

## Message

````
language_models: Filter out whitespace-only text content parts for OpenAI and OpenAI compatible providers (#40316)

Closes #40097

When multiple files are added sequentially to the agent panel, the
request JSON incorrectly includes "text" elements containing only
spaces. These empty elements cause the Zhipu AI API to return a "text
cannot be empty" error.
The fix filters out any "text" elements that are empty or contain only
whitespaces.

UI state when the error occurs:
<img width="300" alt="Image"
src="https://github.com/user-attachments/assets/c55e5272-3f03-42c0-b412-fa24be2b0043"
/>

Request JSON (causing the error):
```
{
  "model": "glm-4.6",
  "messages": [
    {
      "role": "system",
      "content": "<<CUT>>"
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "[@1.txt](zed:///agent/file?path=C%3A%5CTemp%5CTest%5C1.txt)"
        },
        { "type": "text", "text": " " },
        {
          "type": "text",
          "text": "[@2.txt](zed:///agent/file?path=C%3A%5CTemp%5CTest%5C2.txt)"
        },
        { "type": "text", "text": " describe" },
```

Release Notes:

- Fixed an issue when an OpenAI request contained whitespace-only text content

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
````

## Parents

- [aff4c25a472228e7071600a6102d7bbecb9df980](https://git.cafe/gitcafe/zed/commit/aff4c25a472228e7071600a6102d7bbecb9df980?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/160bf915aa4661dd3f5a0991be09bfb9cb2223df?format=markdown)
