Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to dynamically pass the email address of users to HTTP headers of custom endpoints #4488

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

timmanik
Copy link
Contributor

@timmanik timmanik commented Oct 21, 2024

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.

  • New feature (non-breaking change which adds functionality)

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.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

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