-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add typed model IDs for chat and embedding models across providers #8323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add typed model IDs for chat and embedding models across providers #8323
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
7854af3
to
01ba705
Compare
01ba705
to
8770ac9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @christian-bromann!
I'm not too sure if we want to inline all available models in a union type that we maintain. What i'm thinking is it could lead to some false negatives where someone assumes that we don't support a model when a new one releases because it isn't typed (even though we are just passing the request onto the first party sdk).
I'd redirect you to try and see if the provider SDKs we use export a string union with all of their model types and use that instead. That way whenever the provider SDK upgrades, our types also upgrade. (it could be an 'ugly' type that just picks it off invoke params from the SDK)
@hntrl good call! I was able to find proper types within the OpenAI and Anthropic SDKs. Shall I revert changes for the other packages? This could indeed be maintenance nightmare. An alternative would be to use the Open Router Models API (ref) to generate types from that response into an extra package we consume everywhere. I don't think the added complexity justifies the dev x gain here though. Thoughts? |
|
Add comprehensive type definitions for model IDs across multiple providers: Chat models: Add DeepInfraChatModelId, CerebrasChatModelId, FireworksChatModelId, GroqChatModelId, TogetherAIChatModelId, PerplexityLanguageModelId, MistralChatModelId, OpenAIChatModelId, GoogleGenerativeAIModelId, BedrockChatModelId, ZhipuAIModelId, and CohereChatModelId Embedding models: Add FireworksEmbeddingModelId, TogetherAIEmbeddingModelId, JinaEmbeddingsModelId, PremEmbeddingsModelId, OpenAIEmbeddingModelId, GoogleVertexEmbeddingModelId, WatsonxEmbeddingModelId, and CohereEmbeddingModelId Type safety improvements: Replace generic string types with specific union types for model parameters across all affected classes and interfaces Documentation links: Include provider documentation URLs in type definitions for easy reference to available models Backward compatibility: All model ID types include (string & NonNullable<unknown>) to maintain compatibility with custom model names This change enhances developer experience by providing IntelliSense support and compile-time validation for model selection while maintaining backward compatibility with existing code.
076a718
to
e39b894
Compare
e39b894
to
3e8ed1f
Compare
3e8ed1f
to
e1c9011
Compare
Done. |
e1c9011
to
5b69037
Compare
Description
This PR enhances type safety for model IDs in core OpenAI and Anthropic integrations by leveraging official SDK types. This provides better IntelliSense support and compile-time validation while maintaining full backward compatibility.
Changes
Type Definitions Added
AnthropicMessagesModelId
: UsesAnthropic.Model
from the official Anthropic SDKOpenAIChatModelId
: UsesOpenAIClient.ChatModel
from the official OpenAI SDKOpenAIEmbeddingModelId
: UsesOpenAIClient.EmbeddingModel
from the official OpenAI SDKOpenAIImageModelId
: UsesOpenAIClient.ImageModel
from the official OpenAI SDKBenefits
(string & NonNullable<unknown>)
for custom modelsImplementation Strategy
@anthropic-ai/sdk
andopenai
packagesBackward Compatibility
✅ No breaking changes - all existing code continues to work unchanged
✅ Custom model support - string union allows any custom model name
✅ Deprecation handled - maintains support for deprecated
modelName
parametersTesting