Skip to content

Users and Threads

Basic example showing how to create users, threads, and add messages.

This example assumes using Zep; is in scope and apiKey contains your Zep API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Create a Zep client with your API key.
using var client = new ZepClient(apiKey);

// Create a user to associate with threads.
var user = await client.SubpackageUser.AddAsync(
    userId: "test-user-" + Guid.NewGuid().ToString("N")[..8],
    firstName: "Test",
    lastName: "User",
    email: "test@example.com");

// Start a new thread for the user.
var thread = await client.SubpackageThread.StartANewThreadAsync(
    threadId: "thread-" + Guid.NewGuid().ToString("N")[..8],
    userId: user.UserId!);

// Add messages to the thread.
var response = await client.SubpackageThread.AddMessagesToAThreadAsync(
    threadId: thread.ThreadId!,
    messages:
    [
        new ApidataThreadMessage
        {
            Content = "Hi, I'm interested in learning about temporal knowledge graphs.",
            Role = ApidataRoleType.User,
        },
        new ApidataThreadMessage
        {
            Content = "Temporal knowledge graphs track how facts and relationships change over time.",
            Role = ApidataRoleType.Assistant,
        },
    ],
    returnContext: true);

// Get context for the thread based on recent messages.
var context = await client.SubpackageThread.GetUserContextAsync(
    threadId: thread.ThreadId!);