Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Oct 29, 2025

Summary

This PR addresses Issue #8909 by adding support for custom headers when configuring OpenAI compatible gateways for the code base indexing feature. This allows users to add required headers (like API keys or version headers) that some gateways require beyond the standard Authorization header.

Changes

Core Implementation

  • ✅ Added codebaseIndexOpenAiCompatibleHeaders field to type definitions in packages/types/src/codebase-index.ts
  • ✅ Updated config manager to read and handle custom headers configuration
  • ✅ Modified OpenAICompatibleEmbedder to accept custom headers as an optional parameter
  • ✅ Updated service factory to pass custom headers when creating the embedder instance
  • ✅ Custom headers are properly merged with default headers in both SDK and direct fetch requests

Testing

  • ✅ Added comprehensive test coverage for custom headers functionality
  • ✅ Tests verify headers are passed correctly to OpenAI client
  • ✅ Tests verify headers are included in direct fetch requests
  • ✅ Tests verify header override behavior
  • ✅ All existing tests continue to pass

Usage

Users can now configure custom headers for OpenAI compatible gateways through the codebase index configuration:

{
  "codebaseIndexOpenAiCompatibleHeaders": {
    "X-Custom-Header": "custom-value",
    "X-API-Version": "v2"
  }
}

These headers will be automatically included in all embedding API requests.

Security Considerations

⚠️ Note: Custom headers are stored as configuration (not as secrets). Users should be aware that sensitive API keys should preferably use the dedicated codebaseIndexOpenAiCompatibleApiKey field which is stored securely as a secret.

Testing

  • All tests pass: npx vitest run services/code-index/embedders/__tests__/openai-compatible.spec.ts
  • Linting and type checking pass
  • 57 tests total, including 3 new tests for custom headers

Fixes #8909


Important

Adds support for custom headers in OpenAI-compatible embeddings, allowing configuration of additional headers like API keys.

  • Behavior:
    • Adds codebaseIndexOpenAiCompatibleHeaders to configuration schema in codebase-index.ts and config.ts.
    • Updates CodeIndexConfigManager to read and handle custom headers.
    • Modifies OpenAICompatibleEmbedder to accept custom headers and merge them with default headers.
    • Updates service-factory.ts to pass custom headers when creating OpenAICompatibleEmbedder.
  • Testing:
    • Adds tests in openai-compatible.spec.ts to verify custom headers are passed correctly and override default headers.
    • Tests include scenarios for direct fetch requests and SDK usage.
  • Misc:
    • Updates config-manager.ts to include custom headers in openAiCompatibleOptions.

This description was created by Ellipsis for d089fb2. You can customize this summary. It will automatically update as commits are pushed.

- Add codebaseIndexOpenAiCompatibleHeaders field to types
- Update config manager to handle custom headers
- Modify OpenAICompatibleEmbedder to accept and use custom headers
- Update service factory to pass headers to embedder
- Add comprehensive test coverage for custom headers

Fixes #8909
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 29, 2025 16:15
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Oct 29, 2025
@roomote
Copy link
Author

roomote bot commented Oct 29, 2025

Review Summary

I've reviewed this PR and found 1 issue that needs to be addressed:

Issues to Resolve

  • Service restart detection: Custom header changes don't trigger a service restart. The doesConfigChangeRequireRestart() method should check for header changes, and PreviousConfigSnapshot type needs an openAiCompatibleHeaders field to track previous state.

Follow Along on Roo Code Cloud

? {
baseUrl: openAiCompatibleBaseUrl,
apiKey: openAiCompatibleApiKey,
headers: openAiCompatibleHeaders,
Copy link
Author

Choose a reason for hiding this comment

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

Custom header changes don't trigger a service restart. When users update their headers, the doesConfigChangeRequireRestart() method (lines 259-357) should detect this change and return true, similar to how it checks openAiCompatibleBaseUrl and openAiCompatibleApiKey changes. You'll also need to add an openAiCompatibleHeaders field to the PreviousConfigSnapshot type and update the snapshot capture logic in loadConfiguration() to track previous header state.

Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Review complete. Found 1 issue that needs to be addressed before approval. Please see the inline comment for details.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 29, 2025
@daniel-lxs daniel-lxs closed this Oct 29, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 29, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Allow specifying custom headers when configuring code base indexing

4 participants