Skip to content

Comments

feat: add per-entry base-url support for OpenAI-compatible API keys#769

Closed
hungthai1401 wants to merge 2 commits intorouter-for-me:devfrom
hungthai1401:feature/multiple-openai-compat-base-url
Closed

feat: add per-entry base-url support for OpenAI-compatible API keys#769
hungthai1401 wants to merge 2 commits intorouter-for-me:devfrom
hungthai1401:feature/multiple-openai-compat-base-url

Conversation

@hungthai1401
Copy link
Contributor

Summary

Adds optional base-url field to individual API key entries in OpenAI-compatible configurations. If not specified, falls back to the parent base-url.

Changes

  • Added BaseURL field to OpenAICompatibilityAPIKey struct
  • Updated synthesizer to use per-entry base URL with fallback logic
  • Added test coverage for the new feature

Usage

openai-compatibility:
- name: provider
  base-url: https://default-api.example.com/v1
  api-key-entries:
    - api-key: key1
       base-url: https://custom-api.example.com/v1  # uses custom URL
    - api-key: key2
       # uses https://default-api.example.com/v1 (fallback)

…y providers

Allow individual API key entries to specify their own base URL that overrides
the parent provider's base URL. This enables using different endpoints for
different API keys within the same OpenAI compatibility provider configuration.

When the per-entry BaseURL field is empty, the system falls back to the parent
provider's base URL, maintaining backward compatibility with existing configs.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hungthai1401, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the flexibility of OpenAI-compatible API key configurations by enabling the specification of a unique base URL for each individual API key. This allows for more granular control over where requests are directed, while maintaining a sensible fallback to the provider's default base URL if a specific one isn't provided for an entry.

Highlights

  • Per-entry Base URL: Introduced an optional 'base-url' field for individual API key entries within OpenAI-compatible configurations, allowing specific endpoints for each key.
  • Fallback Logic: Implemented a fallback mechanism where if a 'base-url' is not specified for an individual API key entry, it defaults to the 'base-url' defined at the parent provider level.
  • Configuration Update: The configuration example file has been updated to demonstrate how to use the new per-entry 'base-url' override.
  • Test Coverage: New test cases have been added to ensure the correct behavior of the per-entry 'base-url' and its fallback logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for a per-entry base-url for OpenAI-compatible API keys, with a fallback to the parent base-url. The implementation looks correct across the configuration, synthesizer logic, and example file. A new test has been added to cover this feature. I've provided a couple of suggestions to improve the new test for better maintainability and reproducibility. Overall, the changes are good.

},
},
},
Now: time.Now(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For test reproducibility and consistency with other tests in this file (e.g., TestConfigSynthesizer_GeminiKeys), it's better to use a fixed time instead of time.Now(). This ensures the test is deterministic.

Suggested change
Now: time.Now(),
Now: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),

Comment on lines +541 to +563
// First entry has custom base URL
if auths[0].Attributes["base_url"] != "https://custom.api.com" {
t.Errorf("expected base_url https://custom.api.com, got %s", auths[0].Attributes["base_url"])
}
if auths[0].Attributes["api_key"] != "key-with-custom-base" {
t.Errorf("expected api_key key-with-custom-base, got %s", auths[0].Attributes["api_key"])
}

// Second entry falls back to parent base URL
if auths[1].Attributes["base_url"] != "https://default.api.com" {
t.Errorf("expected base_url https://default.api.com, got %s", auths[1].Attributes["base_url"])
}
if auths[1].Attributes["api_key"] != "key-without-base" {
t.Errorf("expected api_key key-without-base, got %s", auths[1].Attributes["api_key"])
}

// Third entry with empty base URL falls back to parent base URL
if auths[2].Attributes["base_url"] != "https://default.api.com" {
t.Errorf("expected base_url https://default.api.com, got %s", auths[2].Attributes["base_url"])
}
if auths[2].Attributes["api_key"] != "key-with-empty-base" {
t.Errorf("expected api_key key-with-empty-base, got %s", auths[2].Attributes["api_key"])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test assertions are a bit repetitive. Refactoring this to use a table-driven structure would make the test cleaner, more readable, and easier to extend with more test cases in the future.

	testCases := []struct {
		name        string
		expectedKey string
		expectedURL string
		authIndex   int
	}{
		{
			name:        "custom base URL",
			expectedKey: "key-with-custom-base",
			expectedURL: "https://custom.api.com",
			authIndex:   0,
		},
		{
			name:        "fallback to parent base URL",
			expectedKey: "key-without-base",
			expectedURL: "https://default.api.com",
			authIndex:   1,
		},
		{
			name:        "empty base URL falls back to parent",
			expectedKey: "key-with-empty-base",
			expectedURL: "https://default.api.com",
			authIndex:   2,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			auth := auths[tc.authIndex]
			if auth.Attributes["base_url"] != tc.expectedURL {
				t.Errorf("expected base_url %q, got %q", tc.expectedURL, auth.Attributes["base_url"])
			}
			if auth.Attributes["api_key"] != tc.expectedKey {
				t.Errorf("expected api_key %q, got %q", tc.expectedKey, auth.Attributes["api_key"])
			}
		})
	}

@hkfires
Copy link
Collaborator

hkfires commented Dec 29, 2025

Thanks for the contribution. Unfortunately, we follow a "one provider, one base-url" principle, so we cannot merge this.

@hkfires hkfires closed this Dec 29, 2025
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