diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index 8ac73ca9e..f4bd54cf5 100644 --- a/libs/sdk-js/src/react/stream.tsx +++ b/libs/sdk-js/src/react/stream.tsx @@ -516,6 +516,13 @@ export interface UseStreamOptions< */ threadId?: string | null; + /** + * The ID to use when creating a new thread. When provided, this ID will be used + * for thread creation when threadId is null. This enables optimistic UI updates + * where you know the thread ID before the thread is actually created. + */ + newThreadId?: string; + /** * Callback that is called when the thread ID is updated (ie when a new thread is created). */ @@ -1013,7 +1020,9 @@ export function useStream< let usableThreadId = threadId; if (!usableThreadId) { - const thread = await client.threads.create(); + const thread = await client.threads.create({ + threadId: options.newThreadId, + }); onThreadId(thread.thread_id); usableThreadId = thread.thread_id; }