mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import type { AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS } from '../../services/analytics/index.js'
|
|
import { getInitialSettings } from '../settings/settings.js'
|
|
import { isEnvTruthy } from '../envUtils.js'
|
|
|
|
export type APIProvider =
|
|
| 'firstParty'
|
|
| 'bedrock'
|
|
| 'vertex'
|
|
| 'foundry'
|
|
| 'openai'
|
|
| 'gemini'
|
|
|
|
export function getAPIProvider(): APIProvider {
|
|
const modelType = getInitialSettings().modelType
|
|
if (modelType === 'openai') return 'openai'
|
|
if (modelType === 'gemini') return 'gemini'
|
|
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)) return 'bedrock'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_VERTEX)) return 'vertex'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_FOUNDRY)) return 'foundry'
|
|
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI)) return 'openai'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_GEMINI)) return 'gemini'
|
|
|
|
return 'firstParty'
|
|
}
|
|
|
|
export function getAPIProviderForStatsig(): AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS {
|
|
return getAPIProvider() as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
|
}
|
|
|
|
/**
|
|
* Check if ANTHROPIC_BASE_URL is a first-party Anthropic API URL.
|
|
* Returns true if not set (default API) or points to api.anthropic.com
|
|
* (or api-staging.anthropic.com for ant users).
|
|
*/
|
|
export function isFirstPartyAnthropicBaseUrl(): boolean {
|
|
const baseUrl = process.env.ANTHROPIC_BASE_URL
|
|
if (!baseUrl) {
|
|
return true
|
|
}
|
|
try {
|
|
const host = new URL(baseUrl).host
|
|
const allowedHosts = ['api.anthropic.com']
|
|
if (process.env.USER_TYPE === 'ant') {
|
|
allowedHosts.push('api-staging.anthropic.com')
|
|
}
|
|
return allowedHosts.includes(host)
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|