Skip to content

Feature Request: Custom API Server Endpoint Support #9

@waxiangzi

Description

@waxiangzi

Problem

Currently, ops0-cli is hardcoded to use https://api.anthropic.com as the API endpoint. This limits users who want to:

  • Use proxy servers or custom gateways for API access
  • Connect to Claude-compatible API services (e.g., third-party providers)
  • Work in enterprise environments with custom endpoints or air-gapped setups
  • Use regional API endpoints for better latency or compliance

Proposed Solution

Add support for OPS0_API_BASE_URL environment variable to allow custom API server configuration.

Environment Variable

export OPS0_API_BASE_URL=https://custom-api.example.com

Naming Rationale

  • Uses OPS0_ prefix to match existing convention (OPS0_AI_MODEL, OPS0_MAX_TOKENS)
  • API_BASE_URL clearly indicates it is the base URL for API calls
  • Not tied to specific provider name (more flexible than ANTHROPIC_API_SERVER)

Benefits

  1. Flexibility: Enables use of Claude-compatible services and custom endpoints
  2. Enterprise Support: Works with corporate proxies and custom gateways
  3. Backward Compatibility: Defaults to official Anthropic API when not set
  4. Consistency: Follows existing naming convention for environment variables

Implementation Details

Changes Required

  1. Add APIBaseURL field to ClaudeConfig struct in definitions.go
  2. Update callClaude() function in llms.go to use configurable endpoint
  3. Read OPS0_API_BASE_URL environment variable in all config creation points
  4. Default to https://api.anthropic.com when variable is not set

Example Usage

# Use default Anthropic API
export ANTHROPIC_API_KEY=sk-xxx
ops0 -m "list docker containers" -ai

# Use custom API endpoint
export ANTHROPIC_API_KEY=sk-xxx
export OPS0_API_BASE_URL=https://api.custom-provider.com
export OPS0_AI_MODEL=custom-model-name
ops0 -m "list docker containers" -ai

Testing

Tested with:

  • Default Anthropic API (backward compatibility)
  • Custom Claude-compatible API service
  • Various model configurations
  • All supported platforms (macOS, Linux x86_64, Linux ARM64, Windows)

Related

This feature complements the existing OPS0_AI_MODEL environment variable, providing full flexibility for API configuration.

Implementation Ready

I have a complete implementation ready that:

  • ✅ Maintains 100% backward compatibility
  • ✅ Follows existing code patterns and naming conventions
  • ✅ Includes comprehensive testing across platforms
  • ✅ Works with real Claude-compatible API services

Happy to submit a PR once this issue is created and discussed.

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