← Back to PRs

#22909: feat(zai): add image format wrapper for Z.AI API

by AlexanderWillner open 2026-02-21 20:23 View on GitHub →
agents size: S
## 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