TypeScript
// Update by id
const { data, version } = await uc.update('ctx_abc123', { id: 'msg_xyz', content: 'Fixed!' })
// Update by index (0 = first message, -1 = last)
const { data, version } = await uc.update('ctx_abc123', { index: 0, content: 'New system prompt' })
const { data, version } = await uc.update('ctx_abc123', { index: -1, content: 'Fix last msg' })
// With audit metadata
const { data, version } = await uc.update('ctx_abc123',
{ id: 'msg_xyz', content: 'Fixed!' },
{ metadata: { reason: 'typo fix', author: 'alice' } }
)
// Multiple updates
await uc.update('ctx_abc123', [
{ index: 0, content: 'Updated system prompt' },
{ id: 'msg_bbb', content: 'Updated 2' }
])
// Multiple updates with audit metadata
await uc.update('ctx_abc123', [
{ index: 0, content: 'Updated system prompt' },
{ id: 'msg_bbb', content: 'Updated 2' }
], { metadata: { reason: 'batch fix', ticket: 'JIRA-456' } })# Update by id
result = uc.update('ctx_abc123', id='msg_xyz', content='Fixed!')
# Update by index (0 = first message, -1 = last)
result = uc.update('ctx_abc123', index=0, content='New system prompt')
result = uc.update('ctx_abc123', index=-1, content='Fix last msg')
# With audit metadata
result = uc.update('ctx_abc123',
index=0, content='Fixed!',
metadata={'reason': 'typo fix', 'author': 'alice'}
)
# Multiple updates
uc.update('ctx_abc123', [
{'index': 0, 'content': 'Updated system prompt'},
{'id': 'msg_bbb', 'content': 'Updated 2'}
])
# Multiple updates with audit metadata
uc.update('ctx_abc123', [
{'index': 0, 'content': 'Updated system prompt'},
{'id': 'msg_bbb', 'content': 'Updated 2'}
], metadata={'reason': 'batch fix', 'ticket': 'JIRA-456'})# Update by id
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"id": "msg_xyz", "content": "Fixed typo!"}'
# Update by index (0 = first, -1 = last)
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"index": 0, "content": "New system prompt"}'
# Update last message
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"index": -1, "content": "Fixed last message"}'
# With audit metadata
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"updates": [{"index": 0, "content": "Fixed!"}], "metadata": {"reason": "typo fix"}}'const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({id: '<string>', index: 123})
};
fetch('https://api.ultracontext.ai/contexts/{id}', 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.ultracontext.ai/contexts/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'index' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.ultracontext.ai/contexts/{id}"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"index\": 123\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.patch("https://api.ultracontext.ai/contexts/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"index\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ultracontext.ai/contexts/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"index\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"id": "msg_x1y2z3",
"index": 0,
"metadata": {}
}
],
"version": 123
}{
"error": "<string>"
}{
"error": "<string>"
}Contexts
Update messages
Update one or more messages by id or index. Each update automatically creates a new version.
PATCH
/
contexts
/
{id}
TypeScript
// Update by id
const { data, version } = await uc.update('ctx_abc123', { id: 'msg_xyz', content: 'Fixed!' })
// Update by index (0 = first message, -1 = last)
const { data, version } = await uc.update('ctx_abc123', { index: 0, content: 'New system prompt' })
const { data, version } = await uc.update('ctx_abc123', { index: -1, content: 'Fix last msg' })
// With audit metadata
const { data, version } = await uc.update('ctx_abc123',
{ id: 'msg_xyz', content: 'Fixed!' },
{ metadata: { reason: 'typo fix', author: 'alice' } }
)
// Multiple updates
await uc.update('ctx_abc123', [
{ index: 0, content: 'Updated system prompt' },
{ id: 'msg_bbb', content: 'Updated 2' }
])
// Multiple updates with audit metadata
await uc.update('ctx_abc123', [
{ index: 0, content: 'Updated system prompt' },
{ id: 'msg_bbb', content: 'Updated 2' }
], { metadata: { reason: 'batch fix', ticket: 'JIRA-456' } })# Update by id
result = uc.update('ctx_abc123', id='msg_xyz', content='Fixed!')
# Update by index (0 = first message, -1 = last)
result = uc.update('ctx_abc123', index=0, content='New system prompt')
result = uc.update('ctx_abc123', index=-1, content='Fix last msg')
# With audit metadata
result = uc.update('ctx_abc123',
index=0, content='Fixed!',
metadata={'reason': 'typo fix', 'author': 'alice'}
)
# Multiple updates
uc.update('ctx_abc123', [
{'index': 0, 'content': 'Updated system prompt'},
{'id': 'msg_bbb', 'content': 'Updated 2'}
])
# Multiple updates with audit metadata
uc.update('ctx_abc123', [
{'index': 0, 'content': 'Updated system prompt'},
{'id': 'msg_bbb', 'content': 'Updated 2'}
], metadata={'reason': 'batch fix', 'ticket': 'JIRA-456'})# Update by id
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"id": "msg_xyz", "content": "Fixed typo!"}'
# Update by index (0 = first, -1 = last)
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"index": 0, "content": "New system prompt"}'
# Update last message
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"index": -1, "content": "Fixed last message"}'
# With audit metadata
curl -X PATCH https://api.ultracontext.ai/contexts/ctx_abc123 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"updates": [{"index": 0, "content": "Fixed!"}], "metadata": {"reason": "typo fix"}}'const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({id: '<string>', index: 123})
};
fetch('https://api.ultracontext.ai/contexts/{id}', 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.ultracontext.ai/contexts/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'index' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.ultracontext.ai/contexts/{id}"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"index\": 123\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.patch("https://api.ultracontext.ai/contexts/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"index\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ultracontext.ai/contexts/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"index\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"id": "msg_x1y2z3",
"index": 0,
"metadata": {}
}
],
"version": 123
}{
"error": "<string>"
}{
"error": "<string>"
}Include
metadata in the request body to record why this update was made. It is optional, but recommended to make audit trail easier to understand.Authorizations
API key from your UltraContext dashboard
Path Parameters
Context ID (ctx_...)
Body
application/json
Single update, array of updates, or object with updates array and metadata for audit trail.
⌘I