-
Notifications
You must be signed in to change notification settings - Fork 636
Description
The current logic in start-moltbot.sh and src/gateway/env.ts assumes that any OpenAI-compatible gateway must have a URL ending in /openai.
Some providers, like z.ai (https://api.z.ai/api/paas/v4), conform to the OpenAI API spec but do not have a URL ending in /openai.
When using z.ai as AI_GATEWAY_BASE_URL, the gateway incorrectly identifies the provider as Anthropic (the fallback).
This leads to the container sending ANTHROPIC_API_KEY instead of OPENAI_API_KEY, causing the Moltbot/Clawdbot process to crash with ProcessExitedBeforeReadyError or fail to initialize correctly.
start-moltbot.sh(Line ~220)src/gateway/env.ts(Line ~14)
Proposed Fix
Update the detection logic to check for known OpenAI-compatible domains or be less restrictive.
start-moltbot.sh
const baseUrl = (process.env.AI_GATEWAY_BASE_URL || process.env.ANTHROPIC_BASE_URL || '').replace(//+$/, '');
// Fix: Include z.ai and other openai-compatible domains
const isOpenAI = baseUrl.endsWith('/openai') ||
baseUrl.includes('z.ai') ||
baseUrl.includes('openai.com');
src/gateway/env.ts
// Fix: Check for z.ai
const isOpenAIGateway = normalizedBaseUrl?.endsWith('/openai') ||
normalizedBaseUrl?.includes('z.ai') ||
normalizedBaseUrl?.includes('openai.com');
Inside start-moltbot.sh:
Use the improved detection logic to set correct keys.