Add feature to dynamically pass the email address of users to HTTP headers of custom endpoints #4488
+23
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I encountered a use cases that needed me to pass the user email address to the HTTP header of my endpoint. My endpoint is a custom endpoint: Portkey, an LLM Gateway. Porktey requires email addresses or unique identifiers of users be sent through HTTP headers so that each user's request/usage can be tracked granularly.
Given this need, I modified the way that LibreChat passes its header to custom endpoints (like Portkey) via the
initialize.js
for custom endpoints.The updated code block iterates over the headers in endpointConfig, and for each header that contains the ${USER_EMAIL} placeholder, it replaces it with the corresponding user's email fetched from the database.
For headers without ${USER_EMAIL}, it resolves any other environment variables using extractEnvVariable, and handles errors by assigning 'null' as a fallback.
More info on the use case can be found here.
Change Type
Please delete any irrelevant options.
Testing
The pre-requisites needed for testing is Portkey account and creating a virtual key within your Portkey account. I have already done so. I created a virtual key to point to my AWS Bedrock endpoint so then when making requests via LibreChat it looks like: LibreChat -> Portkey -> AWS Bedrock.
I defined my Portkey API key and virtual key in my .env file. I also defined my Portkey endpoint in my librechat.yml.
After doing a local build, I was able to see unique user requests being passed through in the Portkey dashboard.
FYI, there is a free tier for a Portkey account which is what I used.
Test Configuration:
Checklist
Please delete any irrelevant options.