feat: add first-class embedding model support for OpenRouter (v4 & v5) #236
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
This PR adds first-class support for embedding models in the OpenRouter provider, compatible with AI SDK v5 and v4. It introduces the
OpenRouterEmbeddingModelclass for generating embeddings, along with schema validation, API integration, and comprehensive tests. The provider now exposestextEmbeddingModel(v5) and a deprecatedembeddingalias (v4) for parity with other AI SDK providers.This implementation enables semantic search, RAG pipelines, and vector-native features using OpenRouter's embedding API, with support for custom routing preferences and user tracking.
Changes
index.tsimplementing theOpenRouterEmbeddingModelclass,schemas.tsfor response validation using Zod, andindex.test.tswith Vitest tests covering instantiation, single/batch embeddings, custom settings, and edge cases (e.g., missing usage data).textEmbeddingModelandembeddingmethods, creating embedding model instances with configurable settings.Usage Examples
For AI SDK v5
For batch embeddings:
For AI SDK v4 (Deprecated)
Custom settings example (e.g., provider routing):
Tests
src/embedding/index.test.tscovering:textEmbeddingModel,embedding).References
openai/text-embedding-3-small,openai/text-embedding-3-large,openai/text-embedding-ada-002)