Skip to content

OpenAI-compatible gateways (like z.ai) incorrectly detected as Anthropic causing crash #97

@nyrthoughts

Description

@nyrthoughts

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions