cURL
curl --request POST \
--url https://api.langtail.com/v2/threads/{threadId}/messages \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"message": {
"content": "<string>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_choice": "auto",
"tool_call_id": "<string>"
},
"metadata": {
"user_id": "user_123",
"conversation_topic": "product_inquiry",
"priority": "high"
}
}
'import requests
url = "https://api.langtail.com/v2/threads/{threadId}/messages"
payload = {
"message": {
"content": "<string>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_choice": "auto",
"tool_call_id": "<string>"
},
"metadata": {
"user_id": "user_123",
"conversation_topic": "product_inquiry",
"priority": "high"
}
}
headers = {
"X-API-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: {
content: '<string>',
name: '<string>',
tool_calls: [
{
id: '<string>',
type: 'function',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_choice: 'auto',
tool_call_id: '<string>'
},
metadata: {user_id: 'user_123', conversation_topic: 'product_inquiry', priority: 'high'}
})
};
fetch('https://api.langtail.com/v2/threads/{threadId}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langtail.com/v2/threads/{threadId}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'message' => [
'content' => '<string>',
'name' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => 'function',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_choice' => 'auto',
'tool_call_id' => '<string>'
],
'metadata' => [
'user_id' => 'user_123',
'conversation_topic' => 'product_inquiry',
'priority' => 'high'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langtail.com/v2/threads/{threadId}/messages"
payload := strings.NewReader("{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langtail.com/v2/threads/{threadId}/messages")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langtail.com/v2/threads/{threadId}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"threadId": "<string>",
"content": [
{
"role": "user",
"content": "Hello"
}
],
"metadata": {},
"requestLog": {
"id": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"request": {},
"response": {}
},
"requestLogId": "<string>"
}{
"error": {
"message": "Invalid request parameters"
}
}{
"error": {
"message": "Thread not found"
}
}Assistant messages in threads
Create Thread Message
Create a new message in a thread.
POST
/
v2
/
threads
/
{threadId}
/
messages
cURL
curl --request POST \
--url https://api.langtail.com/v2/threads/{threadId}/messages \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"message": {
"content": "<string>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_choice": "auto",
"tool_call_id": "<string>"
},
"metadata": {
"user_id": "user_123",
"conversation_topic": "product_inquiry",
"priority": "high"
}
}
'import requests
url = "https://api.langtail.com/v2/threads/{threadId}/messages"
payload = {
"message": {
"content": "<string>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_choice": "auto",
"tool_call_id": "<string>"
},
"metadata": {
"user_id": "user_123",
"conversation_topic": "product_inquiry",
"priority": "high"
}
}
headers = {
"X-API-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: {
content: '<string>',
name: '<string>',
tool_calls: [
{
id: '<string>',
type: 'function',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_choice: 'auto',
tool_call_id: '<string>'
},
metadata: {user_id: 'user_123', conversation_topic: 'product_inquiry', priority: 'high'}
})
};
fetch('https://api.langtail.com/v2/threads/{threadId}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langtail.com/v2/threads/{threadId}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'message' => [
'content' => '<string>',
'name' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => 'function',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_choice' => 'auto',
'tool_call_id' => '<string>'
],
'metadata' => [
'user_id' => 'user_123',
'conversation_topic' => 'product_inquiry',
'priority' => 'high'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langtail.com/v2/threads/{threadId}/messages"
payload := strings.NewReader("{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langtail.com/v2/threads/{threadId}/messages")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langtail.com/v2/threads/{threadId}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_choice\": \"auto\",\n \"tool_call_id\": \"<string>\"\n },\n \"metadata\": {\n \"user_id\": \"user_123\",\n \"conversation_topic\": \"product_inquiry\",\n \"priority\": \"high\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"threadId": "<string>",
"content": [
{
"role": "user",
"content": "Hello"
}
],
"metadata": {},
"requestLog": {
"id": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"request": {},
"response": {}
},
"requestLogId": "<string>"
}{
"error": {
"message": "Invalid request parameters"
}
}{
"error": {
"message": "Thread not found"
}
}Use this endpoint to add a message to a thread without calling the LLM.
In most cases, you should use the Invoke Assistant API to add messages and get a response from the LLM.
However, this endpoint is useful when you need to add messages without immediate LLM processing, such as for creating placeholder messages or updating thread content separately.
Body
application/json
Response
Successful response
Was this page helpful?