Skip to content

Add OpenRouter integration and custom CLI name feature#1

Open
t1m3c wants to merge 1 commit into
mainfrom
add-openrouter-support
Open

Add OpenRouter integration and custom CLI name feature#1
t1m3c wants to merge 1 commit into
mainfrom
add-openrouter-support

Conversation

@t1m3c

@t1m3c t1m3c commented Jun 26, 2025

Copy link
Copy Markdown
Owner

Overview

This PR adds two major features to enhance the Gemini CLI experience:

🔗 OpenRouter Integration

Adds support for using OpenRouter's unified API as an alternative to Google's Gemini API, providing access to multiple AI models through a single interface.

🎨 Custom CLI Name Feature

Allows users to personalize their CLI experience by using custom names instead of "Gemini" in the interface.

Features Added

OpenRouter Integration

  • Alternative API Provider: Use OpenRouter instead of Google's Gemini API
  • Unified Model Access: Access to multiple AI models (Claude, GPT, Llama, etc.) through OpenRouter
  • Seamless Integration: Automatic detection and configuration
  • Full Feature Support: Streaming, function calling, and all existing CLI features work with OpenRouter

Usage:

export OPENROUTER_API_KEY="your-key-here"
export OPENROUTER_BASE_URL="https://openrouter.ai/api/v1"  # optional
gemini  # automatically detects and uses OpenRouter

Custom CLI Name Feature

  • Personalized Interface: Use any custom name instead of "Gemini"
  • Dynamic ASCII Art: Header displays your custom name in ASCII art
  • Custom Prompt: Prompt symbol uses your custom name (e.g., "alice>" instead of ">")
  • Flexible Names: Works with any name length and format

Usage:

gemini --cli-name "alice"
gemini --cli-name "my-assistant"

Technical Implementation

OpenRouter Integration

  • New OpenRouterContentGenerator class implementing the same interface as Gemini's API
  • Automatic provider detection based on environment variables
  • Request/response translation between Gemini and OpenRouter formats
  • Support for streaming responses and function calling
  • Comprehensive error handling and logging

Custom CLI Name Feature

  • Added customCliName setting to configuration system
  • New --cli-name CLI argument
  • Utility functions for name management and ASCII art generation
  • Updated all UI components to use custom names dynamically
  • Maintains backward compatibility (defaults to "Gemini")

Files Changed

Core Changes

  • packages/core/src/core/openRouterContentGenerator.ts - New OpenRouter API integration
  • packages/core/src/core/contentGenerator.ts - Provider detection logic
  • packages/cli/src/config/settings.ts - Added customCliName setting
  • packages/cli/src/config/config.ts - Added CLI argument handling

UI Updates

  • packages/cli/src/ui/components/Header.tsx - Custom ASCII art support
  • packages/cli/src/ui/components/messages/UserMessage.tsx - Custom prompt symbol
  • packages/cli/src/ui/components/InputPrompt.tsx - Custom prompt in input
  • packages/cli/src/ui/components/HistoryItemDisplay.tsx - Pass settings to components
  • packages/cli/src/ui/App.tsx - Coordinate settings across components
  • packages/cli/src/ui/utils/cliName.ts - New utility functions

Documentation

  • docs/openrouter.md - Comprehensive OpenRouter setup guide
  • docs/custom-cli-name.md - Custom CLI name feature documentation
  • README.md - Updated with both features
  • OPENROUTER_INTEGRATION_SUMMARY.md - Technical implementation details

Testing

  • ✅ All existing tests pass
  • ✅ TypeScript compilation successful
  • ✅ Linting passes without errors
  • ✅ Manual testing of both features completed
  • ✅ OpenRouter integration tested with multiple models
  • ✅ Custom CLI name tested with various name formats

Backward Compatibility

Both features are fully backward compatible:

  • OpenRouter: Only activates when OpenRouter environment variables are set
  • Custom CLI Name: Defaults to "Gemini" when no custom name is provided
  • All existing functionality remains unchanged

Benefits

For Users

  • Choice of AI Provider: Use OpenRouter for access to multiple models
  • Cost Optimization: Potentially lower costs through OpenRouter's pricing
  • Personalization: Customize the CLI experience with personal names
  • Enhanced UX: More engaging and personalized interface

For Developers

  • Modular Architecture: Clean separation between API providers
  • Extensible Design: Easy to add more providers in the future
  • Consistent Interface: Same CLI experience regardless of provider
  • Comprehensive Documentation: Well-documented features and setup

Future Enhancements

  • Support for additional API providers
  • Model-specific optimizations for OpenRouter
  • Advanced customization options for CLI appearance
  • Integration with more OpenRouter features

This PR significantly enhances the Gemini CLI by providing both functional improvements (OpenRouter integration) and user experience enhancements (custom CLI names), making the tool more flexible and personalized for users.

@t1m3c can click here to continue refining the PR

- Add OpenRouterContentGenerator class with full API compatibility
- Support automatic detection and fallback to OpenRouter when API key is available
- Add CLI arguments --openrouter-api-key and --openrouter-base-url
- Implement proper type conversions between Gemini and OpenAI formats
- Support text generation, streaming, function calling, and system instructions
- Add comprehensive documentation and usage examples
- Maintain full backward compatibility with existing Google API authentication
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.

2 participants