Skip to content
Open
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
24 changes: 22 additions & 2 deletions src/lib/models/providers/anthropic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AnthropicLLM from './anthropicLLM';

interface AnthropicConfig {
apiKey: string;
baseURL: string;
}

const providerConfigFields: UIConfigField[] = [
Expand All @@ -21,15 +22,33 @@ const providerConfigFields: UIConfigField[] = [
env: 'ANTHROPIC_API_KEY',
scope: 'server',
},
{
type: 'string',
name: 'Base URL',
key: 'baseURL',
description: 'The base URL for the Anthropic API',
required: true,
placeholder: 'Anthropic Base URL',
default: 'https://api.anthropic.com/v1',
env: 'ANTHROPIC_BASE_URL',
scope: 'server',
},
];

class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {
constructor(id: string, name: string, config: AnthropicConfig) {
super(id, name, config);
}

private normalizeBaseURL(url: string): string {
const trimmed = url.trim().replace(/\/+$/, '');
return trimmed.endsWith('/v1') ? trimmed : `${trimmed}/v1`;
}

async getDefaultModels(): Promise<ModelList> {
const res = await fetch('https://api.anthropic.com/v1/models?limit=999', {
const baseURL = this.normalizeBaseURL(this.config.baseURL);

const res = await fetch(`${baseURL}/models?limit=999`, {
method: 'GET',
headers: {
'x-api-key': this.config.apiKey,
Expand Down Expand Up @@ -81,7 +100,7 @@ class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {
return new AnthropicLLM({
apiKey: this.config.apiKey,
model: key,
baseURL: 'https://api.anthropic.com/v1',
baseURL: this.normalizeBaseURL(this.config.baseURL),
});
}

Expand All @@ -97,6 +116,7 @@ class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {

return {
apiKey: String(raw.apiKey),
baseURL: String(raw.baseURL ?? 'https://api.anthropic.com/v1'),
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 8, 2026

Choose a reason for hiding this comment

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

P2: baseURL is not validated; invalid config values can normalize to malformed URLs and cause runtime fetch failures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/models/providers/anthropic/index.ts, line 119:

<comment>`baseURL` is not validated; invalid config values can normalize to malformed URLs and cause runtime fetch failures.</comment>

<file context>
@@ -97,6 +116,7 @@ class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {
 
     return {
       apiKey: String(raw.apiKey),
+      baseURL: String(raw.baseURL ?? 'https://api.anthropic.com/v1'),
     };
   }
</file context>
Fix with Cubic

};
}

Expand Down