Skip to content

AI_APICallError: The messages parameter is illegal. Please check the documentation. - Zhipu AI GLM-4.5 #2557

Closed

Description

@jgwhite0111

Zhipu AI GLM-4.5 regularly hangs mid edit and waits for a response after the message "AI_APICallError: The messages parameter is illegal. Please check the documentation."

Edit: I don't think it is mid-edit. It seems to happen after session compaction. And it seems to then start its memory again from the last session.

Only settings that are none default are z.ai's recommended setup for 'Coding Plan' on opencode. In ~/.config/opencode/opencode.json I have:

{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "zhipuai": {
            "api": "https://api.z.ai/api/coding/paas/v4"
        }
    }
}

Activity

  1. github-actions commented on Sep 12, 2025

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Sep 13, 2025

    @rekram1-node
    Contributor

    if this was happening at random intervals (like after compacts) can you try latest? There were some fixes shipped today

  3. jgwhite0111 commented on Sep 14, 2025

    @jgwhite0111
    Author

    I'm still getting the message in the latest version. It's a shame, because apart from that, glm-4.5 runs very fast and intelligently in opencode compared to other cli tools I'm testing. Sadly, this error makes it pretty unusable, as I can't leave it unattended, and need to re-prompt the AI constantly to get it to continue after this error. My workflow is to set all permissions to allow and run it sandboxed in a VM, then connect through a mosh session on my phone. I'm not the only person that uses this type of workflow.

  4. rekram1-node commented on Sep 14, 2025

    @rekram1-node
    Contributor

    I haven't tested but someone in the discord said:

    use the anthropic endpoint and it will fix it

    ex:

    "zai": {
          "name": "zai-anth-base",
          "npm": "@ai-sdk/anthropic",
          "models": {
            "glm-4.5": {
              "id": "glm-4.5",
              "name": "GLM-4.5",
              "attachment": true,
              "tool_call": true,
              },
              "limit": {
                "context": 131072,
                "output": 98304
              },
            },
          "options": {
            "baseURL": "https://api.z.ai/api/anthropic/v1"
          },
        },
    
  5. jgwhite0111 commented on Sep 14, 2025

    @jgwhite0111
    Author

    Yea, I just saw that and tested it. It solves the issue. Thanks! I won't close for now in case anyone has any tweaks or recommendations to offer. Otherwise, feel free to close.

  6. shekohex commented on Sep 14, 2025

    @shekohex
    Contributor

    But you now would lose the CoT and reasoning from the model.

  7. jgwhite0111 commented on Sep 15, 2025

    @jgwhite0111
    Author

    OK so the Anthropic API doesn't suport reasoning? I think I'd rather put up with re-prompting it than lose reasoning for now.

  8. vinaychilukuri commented on Sep 15, 2025

    @vinaychilukuri

    Have been facing the same issue! And, I also don't want to lose reasoning at this point.

  9. 0serna commented on Sep 16, 2025

    @0serna

    Same problem here, today I've been getting this error repeatedly in opencode v0.9.5

  10. rekram1-node commented on Sep 16, 2025

    @rekram1-node
    Contributor

    Where does it say you lose CoT reasoning? just curious maybe I missed it

  11. jgwhite0111 commented on Sep 16, 2025

    @jgwhite0111
    Author

    Where does it say you lose CoT reasoning? just curious maybe I missed it

    In the replies above from shekohex:

    But you now would lose the CoT and reasoning from the model.

  12. rekram1-node commented on Sep 16, 2025

    @rekram1-node
    Contributor

    Yeah I meant like where does the provider say this

  13. shekohex commented on Sep 16, 2025

    @shekohex
    Contributor

    Yeah I meant like where does the provider say this

    Nowhere in the docs, but looks like the OpenAI format shows the CoT/Thinking but using the Anthropic compatible API DOES NOT show it, or maybe it is missing it altogether.

  14. aemr3 commented on Sep 16, 2025

    @aemr3

    would love to see this fixed as well, I am using GLM-4.5 heavily as well, with subscription. I didn't switch to anthropic, this model is better with reasoning.

  15. 18 remaining items

  16. aemr3 commented on Sep 17, 2025

    @aemr3

    Expected 'id' to be a string

    I suspect that one is unrelated.

    My best guess from diagnosing the problem is that it's an upstream issue with the inference software. The tool call template might not be able to handle hallucinated output from the model gracefully (i.e. when it makes up a tool name that wasn't provided in the request).

    That guess is based on the fact that this occurs far more often when tools are restricted, or nearly guaranteed if I ask it to use a nonexistent tool.

    Now try calling a made up tool: `foogah`.
    User (03:35 PM)
    
    The tool foogah doesn't exist. Available tools are: bash, edit, webfetch, glob, grep, list, read, write, todowrite, toread, task.
    Build glm-4.5 (03:35 PM)
    
    Try anyway. It should cause an error.
    User (03:36 PM)
    
    AI_InvalidResponseDataError: Expected 'id' to be a string.
    

    oh shoot, you're right. I did reproduce it too. can we silently ignore this error or maybe report it to llm?

  17. jdiaz5513 commented on Sep 17, 2025

    @jdiaz5513
    Contributor

    silently ignore this error

    That depends on if there's something to salvage, but I think in this situation you see no streaming response at all.

    Technically z.ai and other inference providers need to patch the bug and have the API behave more like OpenAI: GPT will happily return a hallucinated tool name in the response, leaving it up to the client (OpenCode) to deal with. Not sure what a good workaround here would be.

    The chat template for GLM 4.5 is tricky, so I have some sympathy.

  18. jgwhite0111 commented on Sep 18, 2025

    @jgwhite0111
    Author

    Just want to say thankyou for this fix. glm-4.5 coder plan with opencode and openai endpoint is now ridiculously powerful -- almost too good to be true. I'll enjoy it while it lasts and z.ai sustain these prices. opencode has the best cli implementation I've tested.

  19. jgwhite0111 commented on Sep 18, 2025

    @jgwhite0111
    Author

    Though unfortunately "AI_InvalidResponseDataError: Expected 'id' to be a string." is still bringing it to a halt at times, but it's still an improvement.

  20. brokechubb commented on Sep 20, 2025

    @brokechubb

    It is worse than ever using 0.10.3

  21. michabbb commented on Sep 28, 2025

    @michabbb

    opencode v0.12.1
    Zhipu AI GLM-4.5

    Whatever I send (for example, a simple "hi") shows the error: AI_APICallError: API 调用参数有误,请检查文档。

  22. rekram1-node commented on Sep 28, 2025

    @rekram1-node
    Contributor

    @michabbb can u share your opencode.json?

  23. michabbb commented on Sep 28, 2025

    @michabbb

    @rekram1-node sure, but there´s nothing special in there, i only removed the mcps and one custom provider that is NOT used here....
    here´s what's left:

    {
      "$schema": "https://opencode.ai/config.json",
      "theme": "github",
      "model": "groq/moonshotai/kimi-k2-instruct-0905",
      "autoupdate": true,
      "permission": {
        "bash": {
          "rm": "ask"
        }
      },
      "agent": { "ask": { "mode": "primary", "tools": { "*": false }, "prompt": " " } },
    }
  24. rekram1-node commented on Sep 28, 2025

    @rekram1-node
    Contributor

    @michabbb are you on their coding plan subscription?

  25. michabbb commented on Sep 28, 2025

    @michabbb

    @rekram1-node nope, just using an api key that is connected to a pre-pay account with some $ in it.
    in hope i am not mixing things up, i am talking about using a key from: https://z.ai/manage-apikey/apikey-list

    i am confused, because: https://models.dev/?sort=output-costper&order=asc&search=GLM-4.5

    shows "z.ai" and "Zhipu AI" as two different providers but in opencode i can only choose "Zhipu AI" - but whats the difference here ? 🙈

  26. fwang commented on Sep 28, 2025

    @fwang
    Contributor

    Z.AI and Zhipu AI are marketed as two separate providers from the company Zhipu. Former facing international users, and the latter facing Chinese users. If you obtained the API key from https://z.ai, use the Z.AI provider.

    Image
  27. michabbb commented on Sep 28, 2025

    @michabbb

    @fwang thanks a lot for clarification, i was wondering why i do see "Zhipu Ai" but not "Z.Ai", now i know. because i used the wrong one 🙈

    @rekram1-node sorry for the noise! 😞

  28. rekram1-node commented on Sep 28, 2025

    @rekram1-node
    Contributor

    hey no problem

  29. ShamanicArts commented on Oct 2, 2025

    @ShamanicArts

    I am also seeing a lot of AI_APICallError: Invalid API parameter, please check the documentation. errors suddenly. not sure the cause

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