Analysis of Issue #774
Title: pi-ai auto detection of features based on base url is confusing
Problem: When using a custom base URL for providers like Cerebras (e.g., for proxying LLM calls), model configuration breaks because provider-specific settings (like "no support for developer message") are determined by checking if the URL contains cerebras.ai, rather than using the explicitly configured provider field.
Root Cause
In packages/ai/src/providers/openai-completions.ts, the detectCompatFromUrl() function (lines 495-521) only examines the baseUrl to determine provider-specific compatibility:
When a user sets a custom baseUrl (e.g., https://my-proxy.com/v1) but keeps provider: "cerebras", the URL check fails and the model gets incorrect OpenAI-standard settings (like trying to use developer role, which Cerebras doesn't support).
Proposed Fix
Modify detectCompatFromUrl to also check model.provider, giving it precedence over URL-based detection since it's explicitly configured:
File: packages/ai/src/providers/openai-completions.ts
Changes:
-
Rename detectCompatFromUrl(baseUrl: string) to detectCompat(model: Model<"openai-completions">)
-
Update the detection logic to check both provider and URL:
- Update
getCompat() to call detectCompat(model) instead of detectCompatFromUrl(model.baseUrl).
Backwards Compatibility: URL-based detection continues to work for users who don't explicitly set a provider. Provider-based detection takes precedence when set, which is the expected behavior since it's an explicit configuration.
Affected Files:
packages/ai/src/providers/openai-completions.ts (only file needing changes)