Skip to main content
POST
/
v2
/
threads
/
{threadId}
/
messages
/
{messageId}
cURL
curl --request POST \
  --url https://api.langtail.com/v2/threads/{threadId}/messages/{messageId} \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <x-api-key>' \
  --data '
{
  "metadata": {
    "my_key": "my key value"
  }
}
'
import requests

url = "https://api.langtail.com/v2/threads/{threadId}/messages/{messageId}"

payload = { "metadata": { "my_key": "my key value" } }
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({metadata: {my_key: 'my key value'}})
};

fetch('https://api.langtail.com/v2/threads/{threadId}/messages/{messageId}', 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/{messageId}",
  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([
    'metadata' => [
        'my_key' => 'my key value'
    ]
  ]),
  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/{messageId}"

	payload := strings.NewReader("{\n  \"metadata\": {\n    \"my_key\": \"my key value\"\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/{messageId}")
  .header("X-API-Key", "<x-api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"metadata\": {\n    \"my_key\": \"my key value\"\n  }\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.langtail.com/v2/threads/{threadId}/messages/{messageId}")

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  \"metadata\": {\n    \"my_key\": \"my key value\"\n  }\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "createdAt": "2023-11-07T05:31:56Z",
  "threadId": "<string>",
  "metadata": {
    "my_key": "my key value"
  },
  "deletedAt": "2023-11-07T05:31:56Z",
  "content": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "requestLogId": "<string>"
}
{
  "error": {
    "message": "Metadata is required"
  }
}
{
  "error": {
    "message": "Message not found"
  }
}
This endpoint allows you to update the metadata of a specific message within a thread. It’s useful for adding or modifying additional information associated with a message without changing its core content.

Headers

X-API-Key
string
required

Your Langtail API Key

Example:

"<LANGTAIL_API_KEY>"

Path Parameters

threadId
string
required

The ID of the thread containing the message.

messageId
string
required

The ID of the message to update.

Body

application/json
metadata
object
required

Set of key-value pairs that you can attach to the message. This can be useful for storing additional information about the message in a structured format.

Example:
{ "my_key": "my key value" }

Response

Successful response

id
string
required

The unique identifier for the message.

createdAt
string<date-time>
required

The timestamp when the message was created.

threadId
string
required

The ID of the thread this message belongs to.

metadata
object | null
required

A set of key-value pairs that can be attached to the message.

Example:
{ "my_key": "my key value" }
deletedAt
string<date-time> | null

The timestamp when the message was deleted.

content
object[]

Additional messages. These will be appended to the Prompt Template.

Example:
[{ "role": "user", "content": "Hello" }]
requestLogId
string | null

The ID of the associated request log, if available.