Skip to main content

Create an User

It’s important to note that the concept of User only exists at the thread level, not at the Step level.
import os
from literalai import LiteralClient
literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))

@literal_client.step()
def my_step(input_message):
    # some code, llm call, tool call, etc.
    answer = "answer"
    return answer

async def run(input_message):
    with literal_client.thread() as thread:
        literal_client.message(content=input_message, type="user_message", name="User")
        user = await literal_client.api.create_user(identifier="John Doe")
        # user = await literal_client.api.get_user(identifier="John Doe")
        thread.user = user
        answer = my_step(input_message)
        literal_client.message(content=answer, type="assistant_message", name="Assistant")
    return answer
identifier
string
required
The identifier of the user in your system

Return type

user
User
Return the user

Get an User

user = await client.api.get_user(id="<USER_UUID>")
id
uuid
required
The Literal id of the user

Return type

user
User
Return the user, can be None if the user does not exist

Update an User

updated_user = await client.api.update_user(id="<USER_UUID>", identifier="Jane Doe")
id
uuid
required
The Literal id of the user
identifier
string
The identifier of the user in your system
metadata
dict
The metadata of the user

Return type

user
User
Return the user

Delete an User

user = await client.api.delete_user(id="<USER_UUID>")
id
uuid
required
The Literal id of the user
I