cURL
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 the request body."
}{
"error": "Invalid API key. Check the key, or create one at https://app.relace.ai."
}{
"error": "Out of credits. Add credits at https://app.relace.ai to continue."
}{
"error": "Route not found: POST /v1/code/edit"
}{
"error": "Rate limit exceeded. Retry after the Retry-After interval, or contact support to raise your limits."
}{
"error": "Internal server error."
}{
"error": "Model server error; retry shortly."
}{
"error": "Model 'relace-apply-3' is temporarily unavailable; retry shortly."
}{
"error": "Request to the model timed out after 60s."
}Relace Models
Compact Trace
Compress an agent trace to only the important details.
POST
/
v1
/
code
/
compact
cURL
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 the request body."
}{
"error": "Invalid API key. Check the key, or create one at https://app.relace.ai."
}{
"error": "Out of credits. Add credits at https://app.relace.ai to continue."
}{
"error": "Route not found: POST /v1/code/edit"
}{
"error": "Rate limit exceeded. Retry after the Retry-After interval, or contact support to raise your limits."
}{
"error": "Internal server error."
}{
"error": "Model server error; retry shortly."
}{
"error": "Model 'relace-apply-3' is temporarily unavailable; retry shortly."
}{
"error": "Request to the model timed out after 60s."
}Relace Compact can process agent traces at >50k tok/s, enabling just-in-time compaction without interrupting the user experience.
The compressed
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
Body
application/json
Agent trace to compact