Append Messages langbase.threads.append()
You can use the threads.append()
function to add new messages to an existing thread. This helps you maintain conversation history and build interactive chat experiences.
Generate a User/Org API key
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
API reference
langbase.threads.append()
Function Signature
langbase.threads.append(options);
// with types
langbase.threads.append(options: ThreadsCreate);
- Name
options
- Type
- ThreadMessagesCreate
- Description
ThreadMessagesCreate Object
threadId: string; messages: ThreadMessage[];
Following are the properties of the options object.
- Name
threadId
- Type
- string
- Description
An optional thread ID. If not provided, a new one will be generated.
- Name
messages
- Type
- ThreadMessage[]
- Description
A list of initial messages for the thread.
ThreadMessage
is an object that extends theMessage
object.ThreadMessage
attachments?: any[]; metadata?: Record<string, string>; role: 'user' | 'assistant' | 'system' | 'tool'; content: string | null; name?: string; tool_call_id?: string; tool_calls?: ToolCall[];
Usage example
Install the SDK
npm i langbase
Environment variables
Environment variables
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
Append messages to a thread
Append messages to a thread on Langbase
const messages = await langbase.threads.append({
threadId: "thread_125",
messages: [{
role: "assistant",
content: "How can I help you today?"
}]
});
Response
- Name
ThreadMessagesBaseResponse
- Type
- array
- Description
The response of the
threads.append()
function is a promise that resolves to an array ofThreadMessagesBaseResponse
objects.ThreadMessagesBaseResponse
id: string; created_at: number; thread_id: string; content: string; role: Role; tool_call_id: string | null; tool_calls: ToolCall[] | []; name: string | null; attachments: any[] | []; metadata: Record<string, string> | {};
ThreadMessagesBaseResponse type of langbase.threads.append()
[
{
"id": "msg_124",
"thread_id": "thread_123",
"created_at": 1709544120,
"role": "user",
"content": "Hello, I need help!",
"tool_call_id": null,
"tool_calls": [],
"name": null,
"attachments": [],
"metadata": {}
},
{
"id": "msg_125",
"thread_id": "thread_123",
"created_at": 1709544120,
"role": "assistant",
"content": "How can I help you today?",
"tool_call_id": null,
"tool_calls": [],
"name": null,
"attachments": [],
"metadata": {}
}
]