Skip to content

feat: include UID in requests per OpenAI guidance#48

Merged
wasaga merged 1 commit intomainfrom
add-user-id-to-open-ai-requests
Jun 13, 2025
Merged

feat: include UID in requests per OpenAI guidance#48
wasaga merged 1 commit intomainfrom
add-user-id-to-open-ai-requests

Conversation

@nickytonline
Copy link
Copy Markdown
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 AI review requested due to automatic review settings June 4, 2025 06:21
Copy link
Copy Markdown
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 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
Copy Markdown
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.

@nickytonline nickytonline force-pushed the add-user-id-to-open-ai-requests branch from 0a88d6e to 1afe10d Compare June 12, 2025 01:19
@nickytonline
Copy link
Copy Markdown
Member Author

Just wondering if anything is blocking this @wasaga from being merged.

@nickytonline nickytonline force-pushed the add-user-id-to-open-ai-requests branch from 1afe10d to 2963d39 Compare June 13, 2025 17:07
@nickytonline nickytonline force-pushed the add-user-id-to-open-ai-requests branch from 09c2880 to 017e899 Compare June 13, 2025 20:35
@wasaga wasaga merged commit 31bcb87 into main Jun 13, 2025
2 checks passed
@wasaga wasaga deleted the add-user-id-to-open-ai-requests branch June 13, 2025 20:40
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

3 participants