Skip to content

Conversation

@waxiangzi
Copy link

@waxiangzi waxiangzi commented Dec 21, 2025

Summary

This PR adds support for configurable API server endpoints through the OPS0_API_BASE_URL environment variable, enabling users to connect to custom Claude-compatible API services while maintaining full backward compatibility.

Changes

Core Implementation

  • definitions.go: Added APIBaseURL field to ClaudeConfig struct
  • llms.go: Updated callClaude() to use configurable endpoint with fallback to default
  • main.go: Added OPS0_API_BASE_URL environment variable reading
  • action.go: Updated interactive mode configuration
  • ansible.go: Updated Ansible AI integration configuration

Key Features

  1. Configurable Endpoint: Set custom API server via OPS0_API_BASE_URL
  2. Backward Compatible: Defaults to https://api.anthropic.com when not set
  3. Consistent Naming: Follows existing OPS0_* environment variable convention
  4. Cross-Platform: Works on all supported platforms (macOS, Linux, Windows)

Usage Examples

Default Behavior (Unchanged)

export ANTHROPIC_API_KEY=sk-xxx
ops0 -m "show docker containers" -ai

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 "show docker containers" -ai

Testing

Compilation: All platforms compile successfully

  • macOS ARM64
  • Linux x86_64
  • Linux ARM64
  • Windows x86_64

Functionality: Tested with both default and custom endpoints

  • Default Anthropic API works unchanged
  • Custom API endpoint correctly used
  • Chinese language support maintained
  • All existing features preserved

Environment Variables: Complete configuration support

export ANTHROPIC_API_KEY=sk-xxx
export OPS0_API_BASE_URL=https://openrouter.ai/api
export OPS0_AI_MODEL=anthropic/claude-3.5-sonnet

Benefits

  • Enterprise Ready: Supports corporate proxies and custom gateways
  • Provider Flexibility: Works with any Claude-compatible API service
  • Regional Support: Enables use of regional endpoints for compliance/latency
  • Development Friendly: Useful for testing with local API servers

Backward Compatibility

This change is 100% backward compatible:

  • Existing users see no change in behavior
  • No breaking changes to existing environment variables
  • Default API endpoint remains https://api.anthropic.com

Closes #9

- Add APIBaseURL field to ClaudeConfig struct in definitions.go
- Update callClaude() function in llms.go to use configurable endpoint
- Read OPS0_API_BASE_URL environment variable in all config creation points:
  - main.go: CLI mode configuration
  - action.go: Interactive mode configuration
  - ansible.go: Ansible AI integration configuration
- Maintain backward compatibility with default Anthropic API
- Tested with multiple platforms and custom API services

Closes ops0-ai#9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Custom API Server Endpoint Support

1 participant