Skip to content

feat: include UID in requests per OpenAI guidance #48

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickytonline
Copy link
Member

@nickytonline nickytonline commented Jun 4, 2025

This PR adds support for including a unique end-user ID (uid) in outbound requests to OpenAI, in line with their abuse monitoring recommendations. OpenAI recommends sending a unique end-user ID with each request to help them detect and prevent abuse more effectively. This allows them to provide more actionable feedback if any policy violations are identified in our application.

Closes #46

@nickytonline nickytonline requested a review from wasaga June 4, 2025 06:20
@nickytonline nickytonline marked this pull request as ready for review June 4, 2025 06:21
@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 06:21
Copy link

@Copilot 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 a user identifier to the OpenAI API requests to meet updated requirements as discussed in issue #46.

  • The API route now extracts and passes a user ID from the result data.
  • The chat request schema has been updated to require a userId field.
  • The user context and Chat component are updated to incorporate the user identifier in client-side logic.

Reviewed Changes

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

File Description
src/routes/api/chat.ts Destructure userId from result data and pass it to the stream call.
src/lib/schemas.ts Add a required userId string to the chat request schema.
src/contexts/UserContext.tsx Update the user information mapping to include an id field.
src/components/Chat.tsx Include user?.id as userId in the Chat component’s payload and dependency list.
Comments suppressed due to low confidence (4)

src/lib/schemas.ts:68

  • Including userId as a required string in the schema is appropriate; confirm that all clients sending requests conform to this updated schema.
userId: z.string(),

src/contexts/UserContext.tsx:26

  • [nitpick] Mapping userInfo.user to id is acceptable, but consider adding a comment clarifying this choice to ensure consistency for future developers.
id: userInfo.user,

src/routes/api/chat.ts:38

  • The addition of userId looks correct; please ensure that the downstream API consumer properly validates and handles the new 'user' field in the streamText call.
const { messages, servers, model, userId } = result.data

src/components/Chat.tsx:55

  • Including user?.id in the payload and dependency list is correct; ensure that the component gracefully handles scenarios where user?.id might be undefined.
userId: user?.id,

@nickytonline
Copy link
Member Author

nickytonline commented Jun 4, 2025

@wasaga, in the end, I didn't need to make changes to the @pomerium/js-sdk package. I think the spotty Internet today at the conference caused issues leading me to think that info wasn't surfaced in UserInfo.

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.

add user id to openai request
1 participant