Skip to content

feat(ai): image model middleware#11547

Merged
lgrammel merged 4 commits intovercel:mainfrom
codylittle:feat/image-middleware
Jan 6, 2026
Merged

feat(ai): image model middleware#11547
lgrammel merged 4 commits intovercel:mainfrom
codylittle:feat/image-middleware

Conversation

@codylittle
Copy link
Contributor

Background

The ability to run middleware on ImageModels to support semantic caching or safety guardrails without requiring adhoc implementations is desirable. Extend wrapProvider to accept newly created ImageModelMiddleware for consistent implementation as LanguageModelMiddleware

Summary

  • Added ImageModelV3Middleware to @ai-sdk/provider (packages/provider/src/image-model-middleware/v3/image-model-v3-middleware.ts)

  • Added wrapImageModel to ai (packages/ai/src/middleware/wrap-image-model.ts) and ImageModelMiddleware alias (packages/ai/src/types/image-model-middleware.ts).

  • Extended middleware plumbing to support images in wrapProvider (packages/ai/src/middleware/wrap-provider.ts) and createProviderRegistry (packages/ai/src/registry/provider-registry.ts).

  • Tests: new wrapImageModel suite (packages/ai/src/middleware/wrap-image-model.test.ts) + updated registry/provider wrapper tests.

  • Docs: added Image Middleware section (content/docs/03-ai-sdk-core/35-image-generation.mdx), new reference page (content/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx)

Manual Verification

Manually built and implemented migrated our existing middleware approach to use new middleware implementation

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

Create a defaultImageSettingsMiddleware to be used for reference implementation.

Extend wrapProvider to accept wrapping embedding models too

Related Issues

Resolves #11546

@vercel-ai-sdk vercel-ai-sdk bot added the ai/core label Jan 6, 2026
@codylittle codylittle marked this pull request as ready for review January 6, 2026 00:36
@lgrammel lgrammel changed the title feat(core): support image model middleware feat(ai): image model middleware Jan 6, 2026
@@ -0,0 +1,6 @@
---
'@ai-sdk/provider': patch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh. changing the provider package is potentially problematic. since this is file-additive it might be fine, but we need to watch for versioning issues in the coming days.

cc @gr2m

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers for approving, just for future reference, why is this problematic? We have another feature branch we're working on which proposes some changes to the provider package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past there have been issues when people had multiple @ai-sdk/provider packages with different versions installed. I will keep an eye out for that, if it happens again we may need to freeze any changes to @ai-sdk/provider in a given major release.

@lgrammel lgrammel merged commit d937c8f into vercel:main Jan 6, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Support image model middleware

2 participants

Comments