fix: disable TLS verification for IP-based proxy

When ANTHROPIC_BASE_URL points to an IP address (proxy server),
disable TLS certificate verification to allow connection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-09 20:50:15 -08:00
parent 7f2fc153b5
commit f87c089ca2
1 changed files with 8 additions and 1 deletions

View File

@ -34,13 +34,20 @@ export class ClaudeAgentService implements OnModuleInit {
onModuleInit() {
const baseUrl = this.configService.get<string>('ANTHROPIC_BASE_URL');
const isProxyUrl = baseUrl && (baseUrl.includes('67.223.119.33') || baseUrl.match(/^\d+\.\d+\.\d+\.\d+/));
// If using IP-based proxy, disable TLS certificate verification
if (isProxyUrl) {
console.log(`Using Anthropic proxy (TLS verification disabled): ${baseUrl}`);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}
this.client = new Anthropic({
apiKey: this.configService.get<string>('ANTHROPIC_API_KEY'),
baseURL: baseUrl || undefined,
});
if (baseUrl) {
if (baseUrl && !isProxyUrl) {
console.log(`Using Anthropic API base URL: ${baseUrl}`);
}