Skip to content

Conversation

@p-
Copy link
Contributor

@p- p- commented Dec 12, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 12, 2025 13:50
@p- p- changed the title add possibility to add a custom headers to calls LLMs add possibility to add a custom headers to calls to LLMs Dec 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the ability to inject custom HTTP headers into LLM API calls via a new environment variable AI_API_CUSTOM_HEADER. The implementation removes the hardcoded COPILOT_INTEGRATION_ID header and introduces a flexible mechanism for adding custom headers.

Key Changes:

  • Added get_custom_header() function to parse custom headers from the AI_API_CUSTOM_HEADER environment variable
  • Removed hardcoded Copilot-Integration-Id header from both list_capi_models() and TaskAgent.__init__()
  • Modified header construction to merge custom headers with standard headers using the dictionary merge operator

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/seclab_taskflow_agent/capi.py Added get_custom_header() function for parsing environment-based custom headers; removed COPILOT_INTEGRATION_ID constant; updated list_capi_models() to use merged headers with custom header support
src/seclab_taskflow_agent/agent.py Updated imports to include get_custom_header instead of COPILOT_INTEGRATION_ID; modified TaskAgent.__init__() to use custom headers for AsyncOpenAI client initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings December 12, 2025 14:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +75
parts = custom_header.split(':', 1)
if len(parts) != 2:
logging.warning(f"Invalid AI_API_CUSTOM_HEADER format. Expected 'name:value', got: {custom_header}")
return {}

name, value = parts
name = name.strip()
value = value.strip()
if not name or not value:
logging.warning(f"Invalid AI_API_CUSTOM_HEADER: header name and value must be non-empty after stripping. Got: '{custom_header}'")
return {}
return {name: value}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
parts = custom_header.split(':', 1)
if len(parts) != 2:
logging.warning(f"Invalid AI_API_CUSTOM_HEADER format. Expected 'name:value', got: {custom_header}")
return {}
name, value = parts
name = name.strip()
value = value.strip()
if not name or not value:
logging.warning(f"Invalid AI_API_CUSTOM_HEADER: header name and value must be non-empty after stripping. Got: '{custom_header}'")
return {}
return {name: value}
return json.loads(custom_header)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a simplified version of JSON supported by the json.loads API?
AI_API_CUSTOM_HEADER={\"key\":\"val\"} seems like a complication of things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that I know of. I agree that it makes the syntax more clunky. But it simplifies the code a lot and adds support for multiple fields, which somebody might find useful. This isn't going to be a frequently used feature is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is actually needed all the time after removing the default integration id, so I'd rather not having to do something like AI_API_CUSTOM_HEADER={\"key\":\"val\"} all the time. Besides nobody will use it for multiple header if they need to add that all those dashes everywhere.

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.

3 participants