Skip to content

fix(api): update deprecated Claude model and support arbitrary model strings#318

Open
nielskaspers wants to merge 1 commit intoOpenpanel-dev:mainfrom
nielskaspers:fix/update-ai-model-config
Open

fix(api): update deprecated Claude model and support arbitrary model strings#318
nielskaspers wants to merge 1 commit intoOpenpanel-dev:mainfrom
nielskaspers:fix/update-ai-model-config

Conversation

@nielskaspers
Copy link

@nielskaspers nielskaspers commented Mar 23, 2026

Summary

  • Replaces the deprecated claude-3-5 config value with claude (defaults to claude-sonnet-4-20250514)
  • Adds pass-through support for arbitrary model identifiers via AI_MODEL env var — models prefixed with claude- route to Anthropic, gpt-/o prefix routes to OpenAI
  • Updates all self-hosting docs to reflect the new configuration options

Issue

Fixes #314

Changes

  • apps/api/src/utils/ai.ts — Updated model selection logic to support arbitrary model strings
  • apps/public/content/docs/self-hosting/self-hosting.mdx — Updated supported models list and example
  • apps/public/content/docs/self-hosting/environment-variables.mdx — Updated AI_MODEL description
  • apps/public/content/docs/self-hosting/deploy-coolify.mdx — Updated model options
  • apps/public/content/docs/self-hosting/deploy-kubernetes.mdx — Updated model options comment

Migration

Users with AI_MODEL=claude-3-5 should 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-5 value will no longer match a named shortcut but will still be passed through to Anthropic since it starts with claude-.

Summary by CodeRabbit

  • New Features

    • Flexible AI model configuration now supports any model identifier via environment variables, with automatic provider routing based on model prefixes (e.g., claude-* for Anthropic, gpt-* or o* for OpenAI).
  • Documentation

    • Updated deployment guides to reflect expanded model selection options and updated Anthropic API key requirements for all claude-* models.

…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
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

The changes make the AI model configuration dynamic by replacing hardcoded model versions with environment variable-based routing. The code now reads process.env.AI_MODEL and dispatches to providers based on model name prefixes (claude-*, gpt-*, o*), with sensible fallbacks. Documentation updated to reflect the broader model support.

Changes

Cohort / File(s) Summary
AI Model Routing
apps/api/src/utils/ai.ts
Updated getChatModel to read from process.env.AI_MODEL and dynamically route based on model name prefixes. Changed default Claude mapping from hardcoded claude-3-5-haiku-latest to claude-sonnet-4-20250514. Added fallback logic for claude-*, gpt-*, and o* prefixes before final gpt-4.1-mini fallback.
Documentation Updates
apps/public/content/docs/self-hosting/{deploy-coolify.mdx, deploy-kubernetes.mdx, environment-variables.mdx, self-hosting.mdx}
Updated environment variable documentation for AI_MODEL to list supported models as gpt-4o, claude, or any model identifier. Updated ANTHROPIC_API_KEY requirement condition from exact claude-3-5 match to claude or any claude-* model. Updated Anthropic section examples and added prefix-based provider guidance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 No hardcoded models now reign,
The ENV vars share the domain!
Claude, GPT, or custom names flow,
Flexible routing steals the show,
Openpanel's AI can surely grow! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: updating deprecated Claude model (claude-3-5 to claude) and adding support for arbitrary model strings.
Linked Issues check ✅ Passed The PR fully addresses issue #314: removes hardcoded claude-3-5, adds flexible model configuration via environment variables, routes requests by model prefix (claude-/gpt-/o-), and respects externally provided model identifiers.
Out of Scope Changes check ✅ Passed All changes are scope-aligned: code modifications update model routing logic, and documentation updates reflect the new configuration scheme without introducing unrelated functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21e51da and ddb311d.

📒 Files selected for processing (5)
  • apps/api/src/utils/ai.ts
  • apps/public/content/docs/self-hosting/deploy-coolify.mdx
  • apps/public/content/docs/self-hosting/deploy-kubernetes.mdx
  • apps/public/content/docs/self-hosting/environment-variables.mdx
  • apps/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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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:


🌐 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:


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.

Comment on lines +17 to +18
if (model?.startsWith('gpt-') || model?.startsWith('o')) {
return openai(model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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).

Comment on lines 269 to +271
**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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@nielskaspers
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude 3.5 doesn't exist anymore and Static AI Model config

2 participants