curl --request POST \
--url https://api.example.com/threads \
--header 'Content-Type: application/json' \
--data '
{
"metadata": {},
"initial_state": {},
"threadId": "<string>",
"ifExists": "raise",
"ttl": {
"default_ttl": 500000000
}
}
'import requests
url = "https://api.example.com/threads"
payload = {
"metadata": {},
"initial_state": {},
"threadId": "<string>",
"ifExists": "raise",
"ttl": { "default_ttl": 500000000 }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
metadata: {},
initial_state: {},
threadId: '<string>',
ifExists: 'raise',
ttl: {default_ttl: 500000000}
})
};
fetch('https://api.example.com/threads', 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.example.com/threads",
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' => [
],
'initial_state' => [
],
'threadId' => '<string>',
'ifExists' => 'raise',
'ttl' => [
'default_ttl' => 500000000
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/threads"
payload := strings.NewReader("{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
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.example.com/threads")
.header("Content-Type", "application/json")
.body("{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/threads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}"
response = http.request(request)
puts response.read_body{
"thread_id": "<string>",
"user_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"status": "idle",
"metadata": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Create Thread
Create a new conversation thread.
Threads hold conversation state and checkpoint history. Provide a
thread_id for idempotent creation, or let the server generate one.
Set if_exists to "do_nothing" to return the existing thread when the
ID already exists instead of raising a 409 conflict.
curl --request POST \
--url https://api.example.com/threads \
--header 'Content-Type: application/json' \
--data '
{
"metadata": {},
"initial_state": {},
"threadId": "<string>",
"ifExists": "raise",
"ttl": {
"default_ttl": 500000000
}
}
'import requests
url = "https://api.example.com/threads"
payload = {
"metadata": {},
"initial_state": {},
"threadId": "<string>",
"ifExists": "raise",
"ttl": { "default_ttl": 500000000 }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
metadata: {},
initial_state: {},
threadId: '<string>',
ifExists: 'raise',
ttl: {default_ttl: 500000000}
})
};
fetch('https://api.example.com/threads', 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.example.com/threads",
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' => [
],
'initial_state' => [
],
'threadId' => '<string>',
'ifExists' => 'raise',
'ttl' => [
'default_ttl' => 500000000
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/threads"
payload := strings.NewReader("{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
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.example.com/threads")
.header("Content-Type", "application/json")
.body("{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/threads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"metadata\": {},\n \"initial_state\": {},\n \"threadId\": \"<string>\",\n \"ifExists\": \"raise\",\n \"ttl\": {\n \"default_ttl\": 500000000\n }\n}"
response = http.request(request)
puts response.read_body{
"thread_id": "<string>",
"user_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"status": "idle",
"metadata": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Body
Request model for creating threads
Thread metadata
LangGraph initial state
Optional client-provided thread ID for idempotent creation. Omit or null to let the server generate a UUID. When set, 1–255 characters and not blank (must fit PostgreSQL btree keys uncompressed).
1 - 255\SBehavior when thread exists: 'raise' (default) or 'do_nothing'
Per-thread TTL override; requires TTL to be configured server-side or default_ttl set
Show child attributes
Show child attributes
Response
Successful Response
Thread entity model
Status values: idle, busy, interrupted, error
Unique identifier for the thread.
Identifier of the user who owns this thread.
Timestamp when the thread was created.
Timestamp when the thread was last updated.
Current thread status: idle, busy, interrupted, or error.
Arbitrary metadata attached to the thread.