Skip to content

Conversation

hongkongkiwi
Copy link
Contributor

Summary

This PR adds support for configuring custom API base URLs, allowing users to use alternative Groq-compatible endpoints for proxies, local development, or alternative services.

Changes

Core Features

  • ✨ Add --base-url CLI argument to set custom API endpoints
  • 📝 Add groqBaseUrl field support in ~/.groq/local-settings.json config file
  • 🔧 Integrate with Groq SDK's native GROQ_BASE_URL environment variable support
  • ✅ Add comprehensive test suite for base URL configuration

Implementation Details

The implementation leverages the Groq SDK's native support for GROQ_BASE_URL environment variable while adding convenient config file support as a fallback, exactly mirroring how API keys are handled.

Priority order (same as API key):

  1. Environment variable (GROQ_BASE_URL) - handled natively by SDK
  2. Config file (groqBaseUrl) - our fallback when env var not set
  3. CLI argument (--base-url) - sets the environment variable

Files Changed

  • src/core/agent.ts - Check config file for base URL when creating Groq client
  • src/core/cli.ts - Add --base-url CLI option
  • src/utils/local-settings.ts - Add groqBaseUrl field and getter/setter methods
  • src/tests/base-url.test.ts - Comprehensive test coverage
  • README.md - Documentation for the new feature

Testing

All tests pass ✅

npm run build
npx ava src/tests/base-url.test.ts

8 test cases covering:

  • CLI argument parsing
  • Environment variable handling
  • Config file storage and retrieval
  • Priority order verification
  • URL validation

Usage Examples

# Via CLI argument
groq --base-url https://custom-api.example.com

# Via environment variable
export GROQ_BASE_URL=https://custom-api.example.com
groq

# Via config file (~/.groq/local-settings.json)
{
  "groqApiKey": "...",
  "groqBaseUrl": "https://custom-api.example.com"
}

Benefits

  • 🌐 Support for proxy configurations
  • 🏠 Local development with custom endpoints
  • 🔄 Alternative Groq-compatible services
  • 🎯 Consistent with existing API key configuration pattern

@hongkongkiwi hongkongkiwi force-pushed the feature/custom-base-url branch 2 times, most recently from 4d49373 to 7ec55af Compare August 12, 2025 11:41
- Add setBaseUrl() and clearBaseUrl() methods for configuring API endpoint
- Support custom base URLs in cURL command generation
- Add JSDoc documentation for base URL configuration
- Apply CodeRabbit review recommendations for improved error handling
@hongkongkiwi hongkongkiwi force-pushed the feature/custom-base-url branch from 7ec55af to 2feab61 Compare August 12, 2025 11:47
@benank
Copy link
Contributor

benank commented Aug 22, 2025

Nice work! This is a very useful feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants