#22909: feat(zai): add image format wrapper for Z.AI API
agents
size: S
Cluster:
Wizard Enhancements and Config Fixes
## Summary
Adds a streamFn wrapper that transforms OpenAI-style image_url content to Z.AI expected files array format, enabling vision capabilities with Z.AI models like GLM-4.6V.
## Changes
- Added createZaiImageFormatWrapper() function in extra-params.ts
- Applied wrapper for zai and z-ai providers
## Technical Details
Z.AI API expects images differently than OpenAI:
OpenAI format: content array with type image_url
Z.AI format: files array at message level
## Testing
Tested with z.ai API using GLM-4.6V vision model - image analysis works correctly after this transformation.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a `streamFn` wrapper that transforms OpenAI-style `image_url` content blocks to Z.AI's expected `files` array format, enabling vision capabilities with Z.AI models like GLM-4.6V.
- Implemented `createZaiImageFormatWrapper()` function that intercepts payloads and transforms image content
- Applied wrapper automatically for `zai` and `z-ai` providers
- Extracts MIME type from data URLs to generate appropriate file extensions
- Preserves non-image content blocks while moving images to the `files` array
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change follows established patterns in the codebase (similar to `createZaiToolStreamWrapper`), has clear documentation, handles edge cases properly, and only affects Z.AI providers. The transformation logic is straightforward and defensive.
- No files require special attention
<sub>Last reviewed commit: a564aec</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22893: Add Z.AI image format support
by AlexanderWillner · 2026-02-21
86.3%
#16346: feat: support image attachments in OpenAI chat completions endpoint
by sh1nj1 · 2026-02-14
67.9%
#15327: feat:(models): discover ZAI models dynamically for GLM-5 support [A...
by vincentkoc · 2026-02-13
66.3%
#13814: feat(web-search): add ZAI Search (zsearch) provider
by strelov1 · 2026-02-11
65.7%
#22175: fix: support xai tool stream and compat flags
by ShunsukeHayashi · 2026-02-20
65.6%
#16018: feat: add image support to /v1/chat/completions endpoint
by sebastienb · 2026-02-14
64.0%
#16777: feat(gateway): add multimodal image support to /v1/chat/completions
by dzianisv · 2026-02-15
63.9%
#19326: Agents: improve z.ai GLM-5 integration and failover
by gabrielespinheira · 2026-02-17
63.2%
#4534: fix: packaging and OpenAI vision format conversion
by SalimBinYousuf1 · 2026-01-30
62.3%
#19101: feat: Auto-configure Z.AI MCP tools during onboard
by tianxiao1430-jpg · 2026-02-17
62.1%