curl --request POST \
--url https://models.relace.ai/v1/code/compact \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "grep",
"arguments": "{\"pattern\": \"rate_limit\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "config/limits.py:14: RATE_LIMIT_RPS = 100"
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"target_tokens": 96000,
"agent_model": "gpt-5.5"
}
'import requests
url = "https://models.relace.ai/v1/code/compact"
payload = {
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "grep",
"arguments": "{\"pattern\": \"rate_limit\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "config/limits.py:14: RATE_LIMIT_RPS = 100"
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"target_tokens": 96000,
"agent_model": "gpt-5.5"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: 'user',
content: 'Find where the rate limiter is configured and raise the ceiling to 200 rps.'
},
{
role: 'assistant',
content: '',
tool_calls: [
{
id: 'call_abc123',
type: 'function',
function: {name: 'grep', arguments: '{"pattern": "rate_limit"}'}
}
]
},
{
role: 'tool',
tool_call_id: 'call_abc123',
content: 'config/limits.py:14: RATE_LIMIT_RPS = 100'
},
{
role: 'assistant',
content: 'Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.'
}
],
target_tokens: 96000,
agent_model: 'gpt-5.5'
})
};
fetch('https://models.relace.ai/v1/code/compact', 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://models.relace.ai/v1/code/compact",
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([
'messages' => [
[
'role' => 'user',
'content' => 'Find where the rate limiter is configured and raise the ceiling to 200 rps.'
],
[
'role' => 'assistant',
'content' => '',
'tool_calls' => [
[
'id' => 'call_abc123',
'type' => 'function',
'function' => [
'name' => 'grep',
'arguments' => '{"pattern": "rate_limit"}'
]
]
]
],
[
'role' => 'tool',
'tool_call_id' => 'call_abc123',
'content' => 'config/limits.py:14: RATE_LIMIT_RPS = 100'
],
[
'role' => 'assistant',
'content' => 'Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.'
]
],
'target_tokens' => 96000,
'agent_model' => 'gpt-5.5'
]),
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://models.relace.ai/v1/code/compact"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://models.relace.ai/v1/code/compact")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://models.relace.ai/v1/code/compact")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"usage": {
"prompt_tokens": 135407,
"completion_tokens": 17323,
"total_tokens": 152730
}
}{
"error": "Invalid JSON in request body"
}{
"error": "Authorized header required"
}{
"error": "Bad Request: Route not found"
}{
"error": "Rate limit exceeded"
}{
"error": "Error fetching from origin server"
}Compact Trace
Compress an agent trace to only the important details.
curl --request POST \
--url https://models.relace.ai/v1/code/compact \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "grep",
"arguments": "{\"pattern\": \"rate_limit\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "config/limits.py:14: RATE_LIMIT_RPS = 100"
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"target_tokens": 96000,
"agent_model": "gpt-5.5"
}
'import requests
url = "https://models.relace.ai/v1/code/compact"
payload = {
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "grep",
"arguments": "{\"pattern\": \"rate_limit\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "config/limits.py:14: RATE_LIMIT_RPS = 100"
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"target_tokens": 96000,
"agent_model": "gpt-5.5"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: 'user',
content: 'Find where the rate limiter is configured and raise the ceiling to 200 rps.'
},
{
role: 'assistant',
content: '',
tool_calls: [
{
id: 'call_abc123',
type: 'function',
function: {name: 'grep', arguments: '{"pattern": "rate_limit"}'}
}
]
},
{
role: 'tool',
tool_call_id: 'call_abc123',
content: 'config/limits.py:14: RATE_LIMIT_RPS = 100'
},
{
role: 'assistant',
content: 'Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.'
}
],
target_tokens: 96000,
agent_model: 'gpt-5.5'
})
};
fetch('https://models.relace.ai/v1/code/compact', 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://models.relace.ai/v1/code/compact",
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([
'messages' => [
[
'role' => 'user',
'content' => 'Find where the rate limiter is configured and raise the ceiling to 200 rps.'
],
[
'role' => 'assistant',
'content' => '',
'tool_calls' => [
[
'id' => 'call_abc123',
'type' => 'function',
'function' => [
'name' => 'grep',
'arguments' => '{"pattern": "rate_limit"}'
]
]
]
],
[
'role' => 'tool',
'tool_call_id' => 'call_abc123',
'content' => 'config/limits.py:14: RATE_LIMIT_RPS = 100'
],
[
'role' => 'assistant',
'content' => 'Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.'
]
],
'target_tokens' => 96000,
'agent_model' => 'gpt-5.5'
]),
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://models.relace.ai/v1/code/compact"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://models.relace.ai/v1/code/compact")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://models.relace.ai/v1/code/compact")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Find where the rate limiter is configured and raise the ceiling to 200 rps.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"grep\",\n \"arguments\": \"{\\\"pattern\\\": \\\"rate_limit\\\"}\"\n }\n }\n ]\n },\n {\n \"role\": \"tool\",\n \"tool_call_id\": \"call_abc123\",\n \"content\": \"config/limits.py:14: RATE_LIMIT_RPS = 100\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Found it — the ceiling is set in config/limits.py line 14. Raising it to 200.\"\n }\n ],\n \"target_tokens\": 96000,\n \"agent_model\": \"gpt-5.5\"\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"role": "user",
"content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
},
{
"role": "assistant",
"content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
}
],
"usage": {
"prompt_tokens": 135407,
"completion_tokens": 17323,
"total_tokens": 152730
}
}{
"error": "Invalid JSON in request body"
}{
"error": "Authorized header required"
}{
"error": "Bad Request: Route not found"
}{
"error": "Rate limit exceeded"
}{
"error": "Error fetching from origin server"
}Input Formats
Sendmessages in any of the three standard API formats — the format is detected automatically:
| API Format Docs | Native endpoint |
|---|---|
| OpenAI Chat Completions | /v1/chat/completions |
| OpenAI Responses | /v1/responses |
| Anthropic Messages | /v1/messages |
messages in the response come back in the same format you sent, and can replace your live message list directly.Authorizations
Relace API key Authorization header using the Bearer scheme.
Body
Agent trace to compact
The agent trace to compact, in OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages format. The format is detected automatically, and the compressed trace is returned in the same format.
Approximate token budget for the retained context, in your agent model's tokens. Defaults to 96k tokens. Counts are computed with a heuristic lookup table to reduce API latency; your provider's count may differ slightly.
The model that generated the trace, as its API model id (e.g. claude-fable-5, gpt-5.5, grok-4.5). Relace uses this to apply model-specific compaction improvements and count tokens more accurately.