-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: use anthropic protocol for token counting when using anthropic models via Vercel AI Gateway #7433
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
fix: use anthropic protocol for token counting when using anthropic models via Vercel AI Gateway #7433
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -453,6 +453,11 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str | |||||||||
| return "anthropic" | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Vercel AI Gateway uses anthropic protocol for anthropic models | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that there's no documentation comment here? The Vertex section above has a comment explaining the logic. For consistency, consider adding:
Suggested change
|
||||||||||
| if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider extracting this string into a constant for better maintainability. Something like:
Suggested change
This would make it easier to maintain and update if needed, and you could reuse it in tests as well. |
||||||||||
| return "anthropic" | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return "openai" | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
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.
Good test coverage for uppercase variations! Consider adding an edge case test to ensure models that contain 'anthropic' elsewhere in the name (but don't start with it) are handled correctly: