Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/types/src/__tests__/provider-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ describe("getApiProtocol", () => {
})
})

describe("Vercel AI Gateway provider", () => {
it("should return 'anthropic' for vercel-ai-gateway provider with anthropic models", () => {
expect(getApiProtocol("vercel-ai-gateway", "anthropic/claude-3-opus")).toBe("anthropic")
expect(getApiProtocol("vercel-ai-gateway", "anthropic/claude-3.5-sonnet")).toBe("anthropic")
expect(getApiProtocol("vercel-ai-gateway", "ANTHROPIC/claude-sonnet-4")).toBe("anthropic")
expect(getApiProtocol("vercel-ai-gateway", "anthropic/claude-opus-4.1")).toBe("anthropic")
})

it("should return 'openai' for vercel-ai-gateway provider with non-anthropic models", () => {
expect(getApiProtocol("vercel-ai-gateway", "openai/gpt-4")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "google/gemini-pro")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "meta/llama-3")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "mistral/mixtral")).toBe("openai")
Copy link
Contributor

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:

Suggested change
expect(getApiProtocol("vercel-ai-gateway", "mistral/mixtral")).toBe("openai")
it("should return 'openai' for vercel-ai-gateway provider with non-anthropic models", () => {
expect(getApiProtocol("vercel-ai-gateway", "openai/gpt-4")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "google/gemini-pro")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "meta/llama-3")).toBe("openai")
expect(getApiProtocol("vercel-ai-gateway", "mistral/mixtral")).toBe("openai")
// Edge case: model name contains 'anthropic' but doesn't start with it
expect(getApiProtocol("vercel-ai-gateway", "openai/anthropic-compatible")).toBe("openai")
})

})

it("should return 'openai' for vercel-ai-gateway provider without model", () => {
expect(getApiProtocol("vercel-ai-gateway")).toBe("openai")
})
})

describe("Other providers", () => {
it("should return 'openai' for non-anthropic providers regardless of model", () => {
expect(getApiProtocol("openrouter", "claude-3-opus")).toBe("openai")
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
return "anthropic"
}

// Vercel AI Gateway uses anthropic protocol for anthropic models
Copy link
Contributor

Choose a reason for hiding this comment

The 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
// Vercel AI Gateway uses anthropic protocol for anthropic models
// Vercel AI Gateway uses anthropic protocol for anthropic models
// Models are prefixed with the provider name (e.g., "anthropic/claude-3-opus")
if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) {

if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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
if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) {
const ANTHROPIC_MODEL_PREFIX = "anthropic/";
// ...
if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith(ANTHROPIC_MODEL_PREFIX)) {

This would make it easier to maintain and update if needed, and you could reuse it in tests as well.

return "anthropic"
}

return "openai"
}

Expand Down
Loading