fix(api): update deprecated Claude model and support arbitrary model strings#318
fix(api): update deprecated Claude model and support arbitrary model strings#318nielskaspers wants to merge 1 commit intoOpenpanel-dev:mainfrom
Conversation
…strings (Openpanel-dev#314) - Replace deprecated `claude-3-5` config with `claude` shorthand - Allow passing any model identifier via AI_MODEL env var - Models prefixed with `claude-` route to Anthropic, `gpt-`/`o` to OpenAI - Update self-hosting docs to reflect new config options
|
|
📝 WalkthroughWalkthroughThe changes make the AI model configuration dynamic by replacing hardcoded model versions with environment variable-based routing. The code now reads Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/api/src/utils/ai.ts`:
- Around line 17-18: The current prefix check uses model?.startsWith('o') which
is too broad and can misroute models; update the condition that decides to call
openai(model) (the branch returning openai(model)) to match only the intended
OpenAI reasoning model patterns—e.g., replace model?.startsWith('o') with a
stricter test such as a regex like /^o\d/ or an explicit allowed-prefix check
(e.g., allowedOpenaiPrefixes = ['o1','o3'] and test model.startsWith(prefix) or
model.match(/^o(1|3)(-|$)/)) so only valid OpenAI reasoning models route to
openai(model).
- Line 12: Replace the invalid OpenAI model identifier 'gpt-4.1-mini' with the
correct 'gpt-4o-mini' wherever the OpenAI client/model is instantiated in this
file (look for the OpenAI model string used in the OpenAI client creation or
function that returns the OpenAI model); keep the Anthropic call
anthropic('claude-sonnet-4-20250514') unchanged.
In `@apps/public/content/docs/self-hosting/environment-variables.mdx`:
- Around line 269-271: The docs state the analytics assistant default model as
`gpt-4.1-mini` which doesn't match valid OpenAI identifiers and should be
updated to the corrected default used in the code (change the default to
`gpt-4o-mini` to mirror ai.ts); also clarify the sentence about prefixes so it
explicitly says models prefixed with `o` refer to OpenAI's reasoning family
(e.g., o1, o3) rather than any arbitrary model name starting with 'o' to prevent
confusion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 90a8099f-5025-45d1-beef-cd121c56b424
📒 Files selected for processing (5)
apps/api/src/utils/ai.tsapps/public/content/docs/self-hosting/deploy-coolify.mdxapps/public/content/docs/self-hosting/deploy-kubernetes.mdxapps/public/content/docs/self-hosting/environment-variables.mdxapps/public/content/docs/self-hosting/self-hosting.mdx
| case 'claude-3-5': | ||
| return anthropic('claude-3-5-haiku-latest'); | ||
| case 'claude': | ||
| return anthropic('claude-sonnet-4-20250514'); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
What are the valid Anthropic Claude model identifiers as of March 2026?
💡 Result:
The valid Anthropic Claude model identifiers as of March 2026, primarily for the Claude API, are: Latest models (recommended): - claude-opus-4-6 - claude-sonnet-4-6 - claude-haiku-4-5-20251001 (alias: claude-haiku-4-5) Legacy models still available (consider migrating): - claude-sonnet-4-5-20250929 (alias: claude-sonnet-4-5) - claude-opus-4-5-20251101 (alias: claude-opus-4-5) - claude-opus-4-1-20250805 (alias: claude-opus-4-1) - claude-sonnet-4-20250514 (alias: claude-sonnet-4-0) - claude-opus-4-20250514 (alias: claude-opus-4-0) - claude-3-haiku-20240307 (deprecated, retires April 19, 2026) To get the complete, up-to-date list programmatically, use the Anthropic API endpoint GET /v1/models, which lists all available models with their IDs, capabilities, and details. Aliases resolve to the full ID via the API. On AWS Bedrock and Google Vertex AI, IDs differ (e.g., anthropic.claude-opus-4-6-v1).
Citations:
- 1: https://docs.anthropic.com/en/docs/models-overview
- 2: https://platform.claude.com/docs/en/about-claude/models/overview
- 3: https://docs.anthropic.com/en/docs/about-claude/models/all-models
- 4: https://console.anthropic.com/docs/en/api/python/models
- 5: https://platform.claude.com/docs/en/api/go/models
- 6: https://platform.claude.com/docs/en/api/beta/models/list
- 7: https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-5.md
- 8: https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-6
- 9: https://platform.claude.com/docs/en/about-claude/models/choosing-a-model
- 10: https://platform.claude.com/docs/en/release-notes/overview
- 11: https://platform.claude.com/docs/en/about-claude/models/migrating-to-claude-4
🌐 Web query:
What are the valid OpenAI model identifiers as of March 2026, specifically gpt-4-mini or gpt-4o-mini?
💡 Result:
As of March 2026, gpt-4o-mini is a valid OpenAI model identifier. It is listed as a fast, affordable small model for focused tasks in official OpenAI API documentation, with dedicated model pages confirming its availability, pricing ($0.15/$0.60 per 1M input/output tokens), 128K context window, and support for text and image inputs. Specific snapshots include gpt-4o-mini and gpt-4o-mini-2024-07-18. It remains active in the API, distinct from ChatGPT retirements. gpt-4-mini is not a valid OpenAI model identifier. No official documentation, model pages, or lists mention gpt-4-mini. Searches for it return no confirming sources; instead, related models like gpt-4.1-mini, gpt-4o-mini, and o4-mini appear. Deprecation lists do not reference it, confirming it never existed as a standard model.
Citations:
- 1: https://platform.openai.com/docs/models
- 2: https://developers.openai.com/api/docs/models/gpt-4o-mini
- 3: https://platform.openai.com/docs/models/gpt-4o-mini
- 4: https://developers.openai.com/api/docs/models
- 5: https://developers.openai.com/api/docs/models/all
- 6: https://platform.openai.com/docs/deprecations/
- 7: https://help.openai.com/en/articles/20001051-retiring-gpt-4o-and-other-chatgpt-models
Fix OpenAI model identifier on line 20.
gpt-4.1-mini is not a valid OpenAI model. Use gpt-4o-mini instead (fast, affordable small model with 128K context window).
Line 12: claude-sonnet-4-20250514 is a valid Anthropic model identifier as of March 2026 and requires no changes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/api/src/utils/ai.ts` at line 12, Replace the invalid OpenAI model
identifier 'gpt-4.1-mini' with the correct 'gpt-4o-mini' wherever the OpenAI
client/model is instantiated in this file (look for the OpenAI model string used
in the OpenAI client creation or function that returns the OpenAI model); keep
the Anthropic call anthropic('claude-sonnet-4-20250514') unchanged.
| if (model?.startsWith('gpt-') || model?.startsWith('o')) { | ||
| return openai(model); |
There was a problem hiding this comment.
Overly broad prefix match for o may cause unintended routing.
The condition model?.startsWith('o') will match any model string starting with 'o', not just OpenAI reasoning models (o1, o3, etc.). This could incorrectly route models like opus-something or other arbitrary strings to OpenAI.
Consider a more specific pattern:
Proposed fix
- if (model?.startsWith('gpt-') || model?.startsWith('o')) {
+ if (model?.startsWith('gpt-') || /^o\d/.test(model ?? '')) {
return openai(model);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (model?.startsWith('gpt-') || model?.startsWith('o')) { | |
| return openai(model); | |
| if (model?.startsWith('gpt-') || /^o\d/.test(model ?? '')) { | |
| return openai(model); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/api/src/utils/ai.ts` around lines 17 - 18, The current prefix check uses
model?.startsWith('o') which is too broad and can misroute models; update the
condition that decides to call openai(model) (the branch returning
openai(model)) to match only the intended OpenAI reasoning model patterns—e.g.,
replace model?.startsWith('o') with a stricter test such as a regex like /^o\d/
or an explicit allowed-prefix check (e.g., allowedOpenaiPrefixes = ['o1','o3']
and test model.startsWith(prefix) or model.match(/^o(1|3)(-|$)/)) so only valid
OpenAI reasoning models route to openai(model).
| **Default**: `gpt-4.1-mini` | ||
|
|
||
| AI model to use for the analytics assistant. Options: `gpt-4o`, `gpt-4o-mini`, `claude-3-5`. | ||
| AI model to use for the analytics assistant. Options: `gpt-4o`, `claude`, or any model identifier (e.g. `claude-sonnet-4-20250514`, `gpt-4.1-mini`). Models prefixed with `claude-` use Anthropic; models prefixed with `gpt-` or `o` use OpenAI. |
There was a problem hiding this comment.
Verify the default model identifier.
Line 269 documents the default as gpt-4.1-mini, which matches the code in ai.ts. However, this doesn't appear to be a valid OpenAI model name. If the code is corrected to use gpt-4o-mini, this documentation should be updated accordingly.
Additionally, line 271 mentions models prefixed with o route to OpenAI. Consider clarifying this refers to OpenAI reasoning models (o1, o3, etc.) to avoid confusion with arbitrary model names starting with 'o'.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/public/content/docs/self-hosting/environment-variables.mdx` around lines
269 - 271, The docs state the analytics assistant default model as
`gpt-4.1-mini` which doesn't match valid OpenAI identifiers and should be
updated to the corrected default used in the code (change the default to
`gpt-4o-mini` to mirror ai.ts); also clarify the sentence about prefixes so it
explicitly says models prefixed with `o` refer to OpenAI's reasoning family
(e.g., o1, o3) rather than any arbitrary model name starting with 'o' to prevent
confusion.
|
I have read the CLA Document and I hereby sign the CLA |
Summary
claude-3-5config value withclaude(defaults toclaude-sonnet-4-20250514)AI_MODELenv var — models prefixed withclaude-route to Anthropic,gpt-/oprefix routes to OpenAIIssue
Fixes #314
Changes
apps/api/src/utils/ai.ts— Updated model selection logic to support arbitrary model stringsapps/public/content/docs/self-hosting/self-hosting.mdx— Updated supported models list and exampleapps/public/content/docs/self-hosting/environment-variables.mdx— Updated AI_MODEL descriptionapps/public/content/docs/self-hosting/deploy-coolify.mdx— Updated model optionsapps/public/content/docs/self-hosting/deploy-kubernetes.mdx— Updated model options commentMigration
Users with
AI_MODEL=claude-3-5should update to either:AI_MODEL=claude(uses latest default Claude model)AI_MODEL=claude-sonnet-4-20250514(or any specific model identifier)The old
claude-3-5value will no longer match a named shortcut but will still be passed through to Anthropic since it starts withclaude-.Summary by CodeRabbit
New Features
claude-*for Anthropic,gpt-*oro*for OpenAI).Documentation
claude-*models.