-
Notifications
You must be signed in to change notification settings - Fork 191
fix(providers): add support for ZAI payloads #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Guard ZAI params by supportedParameters to avoid unsupported-field 400s.
ZAI may not accept all OpenAI-shaped fields (e.g., response_format, stream_options, penalties). Use the model mapping’s supportedParameters to set only what’s allowed.
Apply this diff within the ZAI case:
case "zai": { - if (stream) { - requestBody.stream_options = { - include_usage: true, - }; - } - if (response_format) { - requestBody.response_format = response_format; - } + const zaiProviderMapping = modelDef?.providers.find( + (p) => p.providerId === usedProvider, + ); + const supportsParam = (param: string) => + ((zaiProviderMapping as ProviderModelMapping | undefined)?.supportedParameters?.includes(param) ?? true); + + if (stream && supportsParam("stream_options")) { + requestBody.stream_options = { include_usage: true }; + } + if (response_format && supportsParam("response_format")) { + requestBody.response_format = response_format; + } // Add optional parameters if they are provided - if (temperature !== undefined) { + if (temperature !== undefined && supportsParam("temperature")) { requestBody.temperature = temperature; } - if (max_tokens !== undefined) { + if (max_tokens !== undefined && supportsParam("max_tokens")) { requestBody.max_tokens = max_tokens; } - if (top_p !== undefined) { + if (top_p !== undefined && supportsParam("top_p")) { requestBody.top_p = top_p; } - if (frequency_penalty !== undefined) { + if (frequency_penalty !== undefined && supportsParam("frequency_penalty")) { requestBody.frequency_penalty = frequency_penalty; } - if (presence_penalty !== undefined) { + if (presence_penalty !== undefined && supportsParam("presence_penalty")) { requestBody.presence_penalty = presence_penalty; } // ZAI/GLM models use 'thinking' parameter for reasoning instead of 'reasoning_effort' - if (supportsReasoning) { + if (supportsReasoning && supportsParam("thinking")) { requestBody.thinking = { type: "enabled", }; } break; }📝 Committable suggestion
🤖 Prompt for AI Agents
💡 Verification agent
🧩 Analysis chain
Confirm ZAI ‘thinking’ payload shape and feature support.
Docs for ZAI/GLM may require a different shape (e.g., budget tokens/mode) or not support response_format/stream_options. Please verify to avoid runtime errors.
You can also confirm the local model metadata declares allowed params for ZAI:
🏁 Script executed:
Length of output: 3433
🌐 Web query:
💡 Result:
Yes — Z.AI uses a "thinking" object. For GLM-4.5 (and the chat completions endpoint) you enable/disable reasoning with the thinking.type field (allowed values: "enabled" or "disabled"; default is enabled). Example shape: "thinking": { "type": "enabled" }.[1][2]
🌐 Web query:
💡 Result:
Short answer: No — Z.AI's paas/v4 chat/completions supports streaming via "stream": true, but its public API docs do not document a response_format parameter or a stream_options.include_usage flag the way OpenAI/Azure do. Z.AI shows streaming and a usage field in non-streamed responses but does not list stream_options/include_usage. [1][2]
If you need include_usage-like behavior while streaming, try contacting Z.AI support or testing experimentally (their docs/sdk don’t advertise that option). [1][2][3]
Sources:
ZAI: preserve thinking shape; remove response_format and stream_options.include_usage (unsupported)
🤖 Prompt for AI Agents