Skip to content
Open
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
13 changes: 10 additions & 3 deletions apps/api/src/utils/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import { chartTypes, operators, timeWindows } from '@openpanel/constants';
import { mapKeys } from '@openpanel/validation';

export const getChatModel = () => {
switch (process.env.AI_MODEL) {
const model = process.env.AI_MODEL;
switch (model) {
case 'gpt-4o':
return openai('gpt-4o');
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.

default:
if (model?.startsWith('claude-')) {
return anthropic(model);
}
if (model?.startsWith('gpt-') || model?.startsWith('o')) {
return openai(model);
Comment on lines +17 to +18
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).

}
return openai('gpt-4.1-mini');
}
};
Expand Down
2 changes: 1 addition & 1 deletion apps/public/content/docs/self-hosting/deploy-coolify.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Coolify will automatically configure most settings, but you may want to customiz
- `RESEND_API_KEY`: Your Resend API key for email features
- `EMAIL_SENDER`: Email sender address
- `OPENAI_API_KEY`: OpenAI API key for AI features (optional)
- `AI_MODEL`: AI model to use (`gpt-4o-mini`, `gpt-4o`, or `claude-3-5`)
- `AI_MODEL`: AI model to use (`gpt-4o`, `claude`, or any model identifier)

<Callout>
Coolify automatically handles:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Enable AI-powered features:

```yaml
config:
aiModel: "gpt-4o-mini" # Options: gpt-4o, gpt-4o-mini, claude-3-5
aiModel: "gpt-4o-mini" # Options: gpt-4o, claude, or any model identifier

secrets:
openaiApiKey: "sk-xxxxxxxxxxxxx" # For OpenAI models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ALLOW_INVITATION=false
**Required**: No
**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.
Comment on lines 269 to +271
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.


**Example**:
```bash
Expand All @@ -294,7 +294,7 @@ OPENAI_API_KEY=sk-your-openai-api-key-here
**Required**: No (required if using Claude models)
**Default**: None

Anthropic API key for Claude AI models. Required if `AI_MODEL` is set to `claude-3-5`.
Anthropic API key for Claude AI models. Required if `AI_MODEL` is set to `claude` or any `claude-*` model.

**Example**:
```bash
Expand Down
5 changes: 3 additions & 2 deletions apps/public/content/docs/self-hosting/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ OpenPanel includes an AI-powered analytics assistant that can help you analyze d
- `gpt-4o` - More powerful but higher cost
- `gpt-4o-mini` - Default model, good balance of performance and cost
- **Anthropic**
- `claude-3-5-haiku-latest` - Fast and cost-effective
- `claude` - Uses `claude-sonnet-4-20250514` by default
- Any `claude-*` model identifier (e.g. `claude-haiku-3-5-20241022`)

#### Configuration

Expand All @@ -141,7 +142,7 @@ AI_MODEL=gpt-4o-mini # Optional: defaults to gpt-4o-mini

```bash title=".env"
ANTHROPIC_API_KEY=your-anthropic-api-key-here
AI_MODEL=claude-3-5
AI_MODEL=claude
```

#### Getting API Keys
Expand Down