Skip to content

feat(providers): add default_headers support for custom providers#1552

Open
nphenix wants to merge 2 commits intoagentscope-ai:mainfrom
nphenix:feature/add-default-headers-support
Open

feat(providers): add default_headers support for custom providers#1552
nphenix wants to merge 2 commits intoagentscope-ai:mainfrom
nphenix:feature/add-default-headers-support

Conversation

@nphenix
Copy link
Contributor

@nphenix nphenix commented Mar 16, 2026

Summary

Add custom HTTP headers support to custom providers for better API compatibility. This enables providers that require special headers (e.g., authentication headers, custom User-Agent) to work with CoPaw.

Motivation

Some OpenAI-compatible APIs require custom HTTP headers for proper functionality:

  • Certain providers validate User-Agent to identify client types
  • Some APIs require custom authentication headers
  • Future-proofing for various provider-specific requirements

Changes

Backend

  • CustomProviderData: add default_headers field (Dict[str, str])
  • ProviderInfo/Provider: add default_headers field with backward-compatible defaults
  • OpenAIProvider: merge default_headers into API client requests
  • Provider.update_config(): support updating default_headers
  • Provider.get_info(): include default_headers in response
  • providers.py API: add default_headers to ProviderConfigRequest, CreateCustomProviderRequest, TestModelRequest
  • test_provider/test_model: apply headers during connection testing

Frontend

  • Type definitions: add default_headers to ProviderInfo, ProviderConfigRequest, CreateCustomProviderRequest, TestProviderRequest, TestModelRequest
  • CustomProviderModal: add headers configuration UI with smart prefill (first header suggests User-Agent)
  • ProviderConfigModal: add headers editing UI with add/remove functionality
  • RemoteModelManageModal: pass default_headers when testing model connections

Testing

  • Backend unit tests pass (pytest tests/unit/providers/)
  • Frontend builds successfully (npm run build)
  • Manual testing: Verified with providers requiring custom headers including:
    • Kimi Coding Plan (requires User-Agent: KimiCLI/0.77)
    • MiniMax API (header-based authentication)

Backward Compatibility

Fully backward compatible:

  • Existing providers without default_headers continue to work normally
  • Empty headers object {} is the default (no behavioral change)
  • Only custom providers can set headers (built-in providers unchanged)

Usage Example

For providers requiring custom headers:

  1. Create custom provider with base URL
  2. Expand "Advanced Config" → "Custom Headers"
  3. Add required headers (e.g., User-Agent: CustomClient/1.0)
  4. Save and test connection

@nphenix nphenix requested a deployment to maintainer-approved March 16, 2026 03:28 — with GitHub Actions Waiting
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 significantly improves the flexibility and compatibility of custom providers by enabling the configuration of custom HTTP headers. This change addresses the need for specific headers, such as User-Agent or authentication tokens, which are often required by various OpenAI-compatible APIs. The update includes comprehensive modifications across backend data models, API endpoints, and the frontend user interface, allowing users to easily manage these headers. The implementation ensures that connection tests accurately reflect the configured headers, providing a more robust and adaptable system for integrating diverse external services.

Highlights

  • Custom HTTP Headers for Providers: Introduced support for default_headers in custom providers, allowing users to specify custom HTTP headers (e.g., User-Agent, authentication tokens) for API requests. This enhances compatibility with various OpenAI-compatible APIs that require specific headers.
  • Backend API and Data Model Updates: Modified core backend data models (CustomProviderData, ProviderInfo, Provider) and API request schemas (ProviderConfigRequest, CreateCustomProviderRequest, TestModelRequest) to include the default_headers field. The OpenAIProvider was updated to merge these custom headers into its API client requests, ensuring proper application.
  • Frontend User Interface for Header Configuration: Implemented new UI elements in the CustomProviderModal (for creating new custom providers) and ProviderConfigModal (for editing existing provider configurations) to allow users to add, edit, and remove custom HTTP headers. This includes an 'Advanced Config' section with a smart pre-fill for 'User-Agent' for the first header.
  • Enhanced Connection Testing: Updated the provider and model connection testing mechanisms (test_provider, test_model endpoints and their frontend counterparts) to pass and apply the default_headers during the connection verification process, ensuring accurate testing for providers requiring custom headers.
  • Backward Compatibility: Ensured full backward compatibility, with existing providers continuing to function normally without custom headers. The default_headers field defaults to an empty object, causing no behavioral changes for configurations that do not specify headers.

🧠 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.

Changelog
  • console/src/api/types/provider.ts
    • Added default_headers field to ProviderInfo, ProviderConfigRequest, CreateCustomProviderRequest, TestProviderRequest, and TestModelRequest interfaces.
  • console/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx
    • Introduced HeaderItem interface for managing header key-value pairs.
    • Added state for headers and advancedOpen to manage custom header input.
    • Implemented addHeader, removeHeader, and updateHeader functions for header manipulation.
    • Modified handleSubmit to convert header array to an object for API submission.
    • Integrated a new 'Advanced Config' section with UI for adding and managing custom headers, including a 'User-Agent' pre-fill suggestion.
  • console/src/pages/Settings/Models/components/modals/ProviderConfigModal.tsx
    • Imported Ant Design Space, DeleteOutlined, and PlusOutlined components.
    • Defined HeaderItem interface for header key-value pairs.
    • Added default_headers to ProviderConfigModalProps interface.
    • Implemented useEffect to initialize headers state from provider.default_headers.
    • Added addHeader, removeHeader, and updateHeader functions, setting formDirty on changes.
    • Modified handleSave and handleTestConnection to convert header array to an object and include default_headers in API calls.
    • Integrated a 'Custom Headers' section within the 'Advanced Config' UI for editing headers.
  • console/src/pages/Settings/Models/components/modals/RemoteModelManageModal.tsx
    • Passed provider.default_headers to api.testModelConnection in handleSave and handleTestConnection functions.
  • src/copaw/app/routers/providers.py
    • Imported Dict from typing.
    • Added default_headers field to ProviderConfigRequest, CreateCustomProviderRequest, and TestModelRequest Pydantic models.
    • Included body.default_headers when calling manager.configure_provider in configure_provider endpoint.
    • Passed default_headers to manager.create_custom_provider in create_custom_provider_endpoint.
    • Applied body.default_headers to tmp_provider in test_provider endpoint before checking connection.
    • Deep-copied provider and applied body.default_headers to tmp_provider in test_model endpoint before checking model connection.
  • src/copaw/providers/models.py
    • Imported Dict from typing.
    • Added default_headers field with default_factory=dict to CustomProviderData Pydantic model.
  • src/copaw/providers/openai_provider.py
    • Modified _client method to conditionally add self.default_headers to AsyncOpenAI client kwargs.
    • Updated get_chat_model_instance to merge self.default_headers with existing DashScope headers before passing them to OpenAIChatModelCompat.
  • src/copaw/providers/provider.py
    • Added default_headers field with default_factory=dict to ProviderInfo Pydantic model.
    • Updated update_config method to handle and set default_headers if provided in the config.
    • Included self.default_headers in the ProviderInfo object returned by get_info.
Activity
  • The pull request introduces a new feature to support custom HTTP headers for custom providers.
  • Backend changes were implemented to update data models and API endpoints to handle default_headers.
  • Frontend UI was developed to allow users to configure these custom headers through modals.
  • Connection testing logic was adjusted to incorporate the new header functionality.
  • Unit tests for the backend and frontend build processes were confirmed to pass.
  • Manual testing was performed with specific providers (Kimi Coding Plan, MiniMax API) requiring custom headers to verify functionality.
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 Generative AI Prohibited Use Policy, 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 introduces a valuable feature by adding support for custom HTTP headers to providers, enhancing API compatibility. The changes are well-implemented across both the frontend and backend. The backend logic for handling, storing, and merging headers is robust. The frontend provides a clear user interface for managing these headers. I have a couple of minor suggestions for the frontend code to improve maintainability and adherence to React best practices.

Add custom HTTP headers support to custom providers, enabling
Kimi Coding Plan and other providers requiring special headers.

Backend changes:
- CustomProviderData: add default_headers field (Dict[str, str])
- ProviderInfo/Provider: add default_headers field
- OpenAIProvider: use default_headers in _client() and get_chat_model_instance()
- Provider.update_config(): support updating default_headers
- Provider.get_info(): include default_headers in response
- providers.py API: add default_headers to ProviderConfigRequest,
  CreateCustomProviderRequest, TestModelRequest
- test_provider/test_model: apply headers during connection testing

Frontend changes:
- ProviderInfo/ProviderConfigRequest/CreateCustomProviderRequest/
  TestProviderRequest/TestModelRequest: add default_headers field
- CustomProviderModal: add headers configuration UI with User-Agent prefill
- ProviderConfigModal: add headers editing UI with add/remove functionality
- RemoteModelManageModal: pass default_headers when testing models

This allows users to configure Kimi Coding Plan via custom provider
with User-Agent header set to KimiCLI/0.77.
@nphenix nphenix force-pushed the feature/add-default-headers-support branch from 0d2053c to 841cbff Compare March 16, 2026 03:34
@nphenix nphenix requested a deployment to maintainer-approved March 16, 2026 03:34 — with GitHub Actions Waiting
…feature

- Add unique 'id' field to HeaderItem interface to fix React key anti-pattern
- Use crypto.randomUUID() to generate stable identifiers for headers
- Extract headersToObject() helper function to eliminate DRY violation
- Update updateHeader type to exclude 'id' field
- Fix black formatting in providers.py
@nphenix nphenix requested a deployment to maintainer-approved March 16, 2026 03:50 — with GitHub Actions Waiting
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.

1 participant