Skip to content

Commit 6afaf62

Browse files
DeJeuneEurFelux
andauthored
Fix Anthropic API URL and add endpoint path handling (#10229)
* Fix Anthropic API URL and add endpoint path handling - Remove trailing slash from Anthropic API base URL - Add isAnthropicProvider utility function - Update provider settings to show full endpoint URL for Anthropic - Add migration to clean up existing Anthropic provider URLs * Update src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx Co-authored-by: Phantom <59059173+EurFelux@users.noreply.github.com> --------- Co-authored-by: Phantom <59059173+EurFelux@users.noreply.github.com>
1 parent 77535b0 commit 6afaf62

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

src/renderer/src/config/providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ export const PROVIDER_URLS: Record<SystemProviderId, ProviderUrls> = {
10201020
},
10211021
anthropic: {
10221022
api: {
1023-
url: 'https://api.anthropic.com/'
1023+
url: 'https://api.anthropic.com'
10241024
},
10251025
websites: {
10261026
official: 'https://anthropic.com/',

src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import { useAppDispatch } from '@renderer/store'
1616
import { updateWebSearchProvider } from '@renderer/store/websearch'
1717
import { isSystemProvider } from '@renderer/types'
1818
import { ApiKeyConnectivity, HealthStatus } from '@renderer/types/healthCheck'
19-
import { formatApiHost, formatApiKeys, getFancyProviderName, isOpenAIProvider } from '@renderer/utils'
19+
import {
20+
formatApiHost,
21+
formatApiKeys,
22+
getFancyProviderName,
23+
isAnthropicProvider,
24+
isOpenAIProvider
25+
} from '@renderer/utils'
2026
import { formatErrorMessage } from '@renderer/utils/error'
2127
import { Button, Divider, Flex, Input, Select, Space, Switch, Tooltip } from 'antd'
2228
import Link from 'antd/es/typography/Link'
@@ -212,6 +218,10 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
212218
if (provider.type === 'azure-openai') {
213219
return formatApiHost(apiHost) + 'openai/v1'
214220
}
221+
222+
if (provider.type === 'anthropic') {
223+
return formatApiHost(apiHost) + 'messages'
224+
}
215225
return formatApiHost(apiHost) + 'responses'
216226
}
217227

@@ -361,7 +371,7 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
361371
</Button>
362372
)}
363373
</Space.Compact>
364-
{isOpenAIProvider(provider) && (
374+
{(isOpenAIProvider(provider) || isAnthropicProvider(provider)) && (
365375
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
366376
<SettingHelpText
367377
style={{ marginLeft: 6, marginRight: '1em', whiteSpace: 'break-spaces', wordBreak: 'break-all' }}>

src/renderer/src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const persistedReducer = persistReducer(
6767
{
6868
key: 'cherry-studio',
6969
storage,
70-
version: 155,
70+
version: 156,
7171
blacklist: ['runtime', 'messages', 'messageBlocks', 'tabs'],
7272
migrate
7373
},

src/renderer/src/store/migrate.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,21 @@ const migrateConfig = {
24762476
logger.error('migrate 155 error', error as Error)
24772477
return state
24782478
}
2479+
},
2480+
'156': (state: RootState) => {
2481+
try {
2482+
state.llm.providers.forEach((provider) => {
2483+
if (provider.id === SystemProviderIds.anthropic) {
2484+
if (provider.apiHost.endsWith('/')) {
2485+
provider.apiHost = provider.apiHost.slice(0, -1)
2486+
}
2487+
}
2488+
})
2489+
return state
2490+
} catch (error) {
2491+
logger.error('migrate 156 error', error as Error)
2492+
return state
2493+
}
24792494
}
24802495
}
24812496

src/renderer/src/utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export function isOpenAIProvider(provider: Provider): boolean {
205205
return !['anthropic', 'gemini', 'vertexai'].includes(provider.type)
206206
}
207207

208+
export function isAnthropicProvider(provider: Provider): boolean {
209+
return provider.type === 'anthropic'
210+
}
211+
208212
/**
209213
* 判断模型是否为用户手动选择
210214
* @param {Model} model 模型对象

0 commit comments

Comments
 (0)