How to set the user parameter using Assistants API

Do you know how could I set the user parameter when using the Assistants API? (https://platform.openai.com/docs/api-reference/messages/createMessage) Should I just include a “user” entry within the metadata Map?

https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids

1 Like

Hi there! Any infos regarding my previous question? Many thanks in advance!

Hi!

Could you clarify your question by referring to the example provided in the link you posted earlier?

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[
    {"role": "user", "content": "This is a test"}
  ],
  max_tokens=5,
  user="user_123456"
)

I think it’s clear that when a user makes a request, they already have an ID, and this ID or a reference to it should be passed along. Including the reference in the request to OpenAI indicates that best practices are being followed. In case of policy violations, the ID helps to identify the specific user and take appropriate actions.

Hi, thanks for your quick reply. I’m using the assistants API, not the completions API. There is no “user” parameter in the createMessage endpoint (https://platform.openai.com/docs/api-reference/messages/createMessage). That is why I was asking if I should send the user id in the metadata map. Many thanks in advance for your support!

1 Like

Ok.
Ultimately you want to know which user added which message/ to whom a message belongs to. So your initial thought is correct.
If you know that a assistant or thread belongs to a single user then you can opt for another solution. The metadata object is available at the thread level as well.

https://platform.openai.com/docs/api-reference/messages/object#messages/object-metadata

https://platform.openai.com/docs/api-reference/threads/object#threads/object-metadata

Thanks. I will be sending a “user” entry with a hashed id in all the threads I generate. My main concern here is that my API-Key does not get banned because of user misuse.

1 Like

When policy violations are being detected by the system the user parameter helps to identify the problematic user.
Also, when you receive a warning from OpenAI you can point to your best practice implementation to acquire good will before they make a decision.

Ultimately the user parameter does exactly what you need to protect your account.

Hope this helps.

1 Like

I do set the user parameter, but the ID they included in the email doesn’t seem to be in the same format as what I was sending them.