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

Get userId from body of request to OpenAI rather then header #8

Open
mattiapomelli opened this issue Aug 18, 2023 · 3 comments
Open

Comments

@mattiapomelli
Copy link

Currently the userId for a specific request is set through the X-User-Id header, like this:

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY, 
  basePath: "https://api.openai.withlogging.com/v1",  
  baseOptions: { 
    headers: {
      "X-Api-Key": `Bearer ${process.env.LLM_REPORT_API_KEY}`, 
      "X-User-Id": `[email protected]`,  // user Id
    },
  }
});

This means that, if different requests need to be associated to different users, the request header needs to be dynamic and change on each request (and therefore we need to create a new Configuration object on each request).

However, OpenAI API already accepts a user field in the body of the request, which has a similar purpose.

const completion = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  user: "userid",
});

It would be handy to optionally get the userId for LLM Report from this field of the request body, rather than the X-User-Id header. This would avoid having to set new headers for each request.

@dillionverma
Copy link
Owner

Good suggestion! Didn't even know OpenAI provided this field. I'll update the code to account for that too :)

@mattiapomelli
Copy link
Author

Awesome!

@picsoung
Copy link

picsoung commented Sep 4, 2023

Exactly had the same question. I already pass the user field via the OpenAI SDK. Would love to see it reflected on the logs.
Thanks

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

No branches or pull requests

3 participants