bytebot icon indicating copy to clipboard operation
bytebot copied to clipboard

feat: Add multi-provider support for OpenRouter, Gemini, and enhanced provider management

Open somdipto opened this issue 4 months ago โ€ข 1 comments

Multi-Provider Support for ByteBot

Fixes #144

๐ŸŽฏ Overview

This PR implements comprehensive multi-provider support for ByteBot, allowing users to seamlessly switch between different AI providers (OpenRouter, Gemini, Anthropic, OpenAI) based on their needs, costs, and preferences.

โœจ Features Added

๐Ÿ—๏ธ Core Architecture

  • BaseProvider Interface: Unified contract for all AI providers with methods for send(), stream(), healthCheck(), and getAvailableModels()
  • Provider Manager Service: Central service for managing provider discovery, status, and switching
  • Dynamic Provider Detection: Automatic enable/disable based on API key configuration

๐Ÿค– New Provider Implementation

  • OpenRouter Service: Complete implementation supporting multiple models through unified API
  • OpenAI-Compatible Integration: Seamless integration with OpenRouter's API
  • Model Enumeration: Support for various models (Claude, GPT, Llama, Mistral, etc.)

๐Ÿ”ง Enhanced Existing Providers

  • Anthropic Service: Added BaseProvider interface implementation
  • OpenAI Service: Enhanced with health checks and model listing
  • Google Gemini Service: Improved with BaseProvider compliance

๐ŸŒ API Endpoints

New REST endpoints for provider management:

  • GET /providers - List all providers with status
  • GET /providers/enabled - Get only enabled providers
  • GET /providers/models - Get all available models
  • GET /providers/:id/models - Get provider-specific models
  • POST /providers/:id/test - Test provider connectivity
  • POST /providers/refresh - Refresh provider status

๐Ÿ”‘ Enhanced API Key Management

  • Support for multiple provider API keys
  • Secure key storage and validation
  • Provider-specific key testing
  • Environment variable configuration

๐Ÿงช Testing

  • Unit Tests: Comprehensive test coverage for all services
  • Integration Tests: End-to-end API endpoint testing
  • Provider-Specific Tests: OpenRouter service validation
  • Mock Testing: Proper mocking of external API calls

๐Ÿ“ Files Added/Modified

New Files:

packages/bytebot-agent/src/
โ”œโ”€โ”€ providers/
โ”‚   โ”œโ”€โ”€ base-provider.interface.ts
โ”‚   โ”œโ”€โ”€ provider-manager.service.ts
โ”‚   โ”œโ”€โ”€ providers.controller.ts
โ”‚   โ”œโ”€โ”€ providers.module.ts
โ”‚   โ””โ”€โ”€ tests/
โ”œโ”€โ”€ openrouter/
โ”‚   โ”œโ”€โ”€ openrouter.service.ts
โ”‚   โ”œโ”€โ”€ openrouter.constants.ts
โ”‚   โ”œโ”€โ”€ openrouter.tools.ts
โ”‚   โ”œโ”€โ”€ openrouter.module.ts
โ”‚   โ””โ”€โ”€ tests/
โ”œโ”€โ”€ api-keys/
โ”‚   โ”œโ”€โ”€ api-keys.service.ts
โ”‚   โ”œโ”€โ”€ api-keys.controller.ts
โ”‚   โ””โ”€โ”€ dto/
โ””โ”€โ”€ docs/multi-provider-support.md

Modified Files:

  • Enhanced existing provider services (Anthropic, OpenAI, Google)
  • Updated agent processor and modules
  • Extended type definitions

๐Ÿš€ Usage

Environment Configuration

ANTHROPIC_API_KEY=your_anthropic_key
OPENAI_API_KEY=your_openai_key
GEMINI_API_KEY=your_gemini_key
OPENROUTER_API_KEY=your_openrouter_key

API Usage Examples

# Get available providers
curl http://localhost:3000/providers

# Get all models
curl http://localhost:3000/providers/models

# Test provider connectivity
curl -X POST http://localhost:3000/providers/openrouter/test

๐ŸŽฏ Benefits

  • Cost Optimization: Switch providers based on pricing
  • Reliability: Graceful fallback when providers are unavailable
  • Future-Proof: Easy addition of new providers
  • Unified Interface: Consistent API across all providers
  • Health Monitoring: Built-in provider status monitoring

๐Ÿ”„ Backward Compatibility

  • โœ… Fully backward compatible with existing installations
  • โœ… No breaking changes to existing APIs
  • โœ… Existing provider configurations continue to work
  • โœ… Optional feature - providers work independently

๐Ÿ“‹ Testing Instructions

  1. Install dependencies: npm install
  2. Build project: npm run build
  3. Run tests: npm test
  4. Test specific providers: npm test -- --testPathPattern="providers"

๐Ÿ“š Documentation

Complete documentation added in docs/multi-provider-support.md including:

  • Architecture overview
  • Implementation guide
  • Usage examples
  • Provider addition instructions

โœ… Issue Requirements Fulfilled

  • [x] Define a base provider interface โœ…
  • [x] Build adapters for OpenRouter and Gemini โœ…
  • [x] Make config/UI switch to select provider โœ…
  • [x] Add tests (unit & integration) โœ…
  • [x] Update documentation and usage examples โœ…

๐Ÿ” Review Notes

  • All changes follow existing code patterns and conventions
  • Comprehensive error handling and logging
  • Production-ready with proper TypeScript types
  • Follows NestJS best practices
  • Maintains security standards for API key handling

Ready for review and testing! ๐Ÿš€

somdipto avatar Sep 30 '25 09:09 somdipto

May I ask can't we use the existing LiteLLM proxy with the multi-providers you mentioned?

samkoesnadi avatar Oct 28 '25 17:10 samkoesnadi