Support image inputs for vision chat models#448
Merged
threepointone merged 1 commit intomainfrom Mar 19, 2026
Merged
Conversation
Convert various image sources into OpenAI-compatible image_url parts and send them inline in chat messages so vision-capable models work via both binding and REST paths. Key changes: - convertToWorkersAIChatMessages: accept LanguageModelV3DataContent (Uint8Array, base64, data URL), normalize to bytes, and emit content arrays with image_url data: URLs; removed the separate images array. - workers-ai-provider: allow messages.content to be either string or content-part arrays, normalize binding messages but pass content arrays through at runtime. - workersai-chat-language-model / create-fetcher: stop extracting a separate image payload and instead include content arrays in inputs; cast inputs for binding runtime use. - Tests and e2e fixtures: added/updated tests for base64, data URLs, multiple images, REST & binding vision flows; updated mock binding worker to handle vision route. - Docs: added Vision (Image Inputs) usage examples to READMEs. This enables sending images (Uint8Array, base64, or data URLs) inline as image_url parts so models like Llama 4 Scout and Kimi K2.5 can perform vision tasks.
🦋 Changeset detectedLatest commit: 054ccb8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
workers-ai-providerand@cloudflare/tanstack-aifor vision-capable chat models (Llama 4 Scout, Kimi K2.5, etc.)LanguageModelV3DataContentvariants (Uint8Array, base64 string, data URL) — previously onlyUint8Arraywas handled, silently dropping base64 and data URL inputsimage_urlcontent parts inline in messages, which works with both the binding and REST API pathsWhat changed
workers-ai-providerconvert-to-workersai-chat-messages.ts: AddedtoUint8Array(normalises all data content types) anduint8ArrayToBase64(chunked encoder). File parts are now converted toimage_urlcontent parts in the messages array.workersai-chat-prompt.ts: AddedWorkersAIContentParttype, widenedWorkersAIUserMessage.contenttostring | WorkersAIContentPart[]workersai-chat-language-model.ts: SimplifiedbuildRunInputs— both REST and binding paths pass content arrays through directly@cloudflare/tanstack-ainormalizeMessagesForBindingdocs to reflect that content arrays pass through (binding accepts them at runtime)Test plan
workers-ai-provider: 210 unit tests pass,tsc --noEmitclean@cloudflare/tanstack-ai: 219 unit tests pass,tsc --noEmitcleanMade with Cursor