Skip to content

[Feature Request] Support for Custom Anthropic-Compatible API Endpoints #3162

@clergyliu

Description

@clergyliu

Summary

Request support for using custom Anthropic-compatible API endpoints (e.g., internal LLM gateways) instead of only the official Anthropic API.

Current Behavior

When configuring Moltbot with a custom baseUrl for the Anthropic provider, the application crashes with the following error:

Error: Unhandled API in mapOptionsForApi: undefined
    at mapOptionsForApi (file:///usr/local/lib/node_modules/moltbot/node_modules/@mariozechner/pi-ai/src/stream.ts:471:10)
    at streamSimple (file:///usr/local/lib/node_modules/moltbot/node_modules/@mariozechner/pi-ai/src/stream.ts:218:26)

Configuration Attempted

moltbot.json:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "anthropic/claude-sonnet-4.5"
      }
    }
  },
  "models": {
    "providers": {
      "anthropic": {
        "baseUrl": "https://llm-gateway.example.com",
        "apiKey": "sk-xxxxx",
        "models": [...]
      }
    }
  }
}

Expected Behavior

Moltbot should support custom Anthropic-compatible API endpoints similar to Claude Code:

  • ANTHROPIC_BASE_URL environment variable support
  • Custom baseUrl in provider configuration
  • Proper handling in @mariozechner/pi-ai package

Use Case

Internal LLM gateways for:

  • Cost tracking
  • Security and compliance
  • Rate limiting
  • Model routing
  • Audit logging

Environment

  • Moltbot Version: 2026.1.27-beta.1
  • Node.js: v22.22.0
  • OS: macOS Monterey

Proposed Solution

  1. Extend @mariozechner/pi-ai to support custom base URLs
  2. Add proper API provider detection in mapOptionsForApi
  3. Allow baseUrl to pass through to API client

Additional Context

  • Claude Code successfully supports this via ANTHROPIC_BASE_URL
  • Error originates from @mariozechner/pi-ai dependency
  • Would benefit enterprise users with internal infrastructure

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions