cURL
curl --request POST \
--url https://instantapply.endpoint.relace.run/v1/code/apply \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"initial_code": "function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}",
"edit_snippet": "// ... keep existing code\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}",
"stream": false
}
'import requests
url = "https://instantapply.endpoint.relace.run/v1/code/apply"
payload = {
"initial_code": "function calculateTotal(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}",
"edit_snippet": "// ... keep existing code
function applyDiscount(total, discountRules) {
let discountedTotal = total;
if (discountRules.percentOff) {
discountedTotal -= (total * discountRules.percentOff / 100);
}
if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {
discountedTotal -= discountRules.fixedAmount;
}
return Math.max(0, discountedTotal);
}",
"stream": False
}
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({
initial_code: 'function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}',
edit_snippet: '// ... keep existing code\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}',
stream: false
})
};
fetch('https://instantapply.endpoint.relace.run/v1/code/apply', 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://instantapply.endpoint.relace.run/v1/code/apply",
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([
'initial_code' => 'function calculateTotal(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}',
'edit_snippet' => '// ... keep existing code
function applyDiscount(total, discountRules) {
let discountedTotal = total;
if (discountRules.percentOff) {
discountedTotal -= (total * discountRules.percentOff / 100);
}
if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {
discountedTotal -= discountRules.fixedAmount;
}
return Math.max(0, discountedTotal);
}',
'stream' => false
]),
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://instantapply.endpoint.relace.run/v1/code/apply"
payload := strings.NewReader("{\n \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\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://instantapply.endpoint.relace.run/v1/code/apply")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://instantapply.endpoint.relace.run/v1/code/apply")
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 \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"mergedCode": "function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}",
"usage": {
"prompt_tokens": 245,
"completion_tokens": 187,
"total_tokens": 432
}
}{
"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"
}Instant Apply
Apply Code
Merge code snippets from an LLM into your existing codebase.
POST
/
v1
/
code
/
apply
cURL
curl --request POST \
--url https://instantapply.endpoint.relace.run/v1/code/apply \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"initial_code": "function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}",
"edit_snippet": "// ... keep existing code\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}",
"stream": false
}
'import requests
url = "https://instantapply.endpoint.relace.run/v1/code/apply"
payload = {
"initial_code": "function calculateTotal(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}",
"edit_snippet": "// ... keep existing code
function applyDiscount(total, discountRules) {
let discountedTotal = total;
if (discountRules.percentOff) {
discountedTotal -= (total * discountRules.percentOff / 100);
}
if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {
discountedTotal -= discountRules.fixedAmount;
}
return Math.max(0, discountedTotal);
}",
"stream": False
}
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({
initial_code: 'function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}',
edit_snippet: '// ... keep existing code\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}',
stream: false
})
};
fetch('https://instantapply.endpoint.relace.run/v1/code/apply', 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://instantapply.endpoint.relace.run/v1/code/apply",
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([
'initial_code' => 'function calculateTotal(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}',
'edit_snippet' => '// ... keep existing code
function applyDiscount(total, discountRules) {
let discountedTotal = total;
if (discountRules.percentOff) {
discountedTotal -= (total * discountRules.percentOff / 100);
}
if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {
discountedTotal -= discountRules.fixedAmount;
}
return Math.max(0, discountedTotal);
}',
'stream' => false
]),
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://instantapply.endpoint.relace.run/v1/code/apply"
payload := strings.NewReader("{\n \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\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://instantapply.endpoint.relace.run/v1/code/apply")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://instantapply.endpoint.relace.run/v1/code/apply")
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 \"initial_code\": \"function calculateTotal(items) {\\n let total = 0;\\n \\n for (const item of items) {\\n total += item.price * item.quantity;\\n }\\n \\n return total;\\n}\",\n \"edit_snippet\": \"// ... keep existing code\\n\\nfunction applyDiscount(total, discountRules) {\\n let discountedTotal = total;\\n \\n if (discountRules.percentOff) {\\n discountedTotal -= (total * discountRules.percentOff / 100);\\n }\\n \\n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\\n discountedTotal -= discountRules.fixedAmount;\\n }\\n \\n return Math.max(0, discountedTotal);\\n}\",\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"mergedCode": "function calculateTotal(items) {\n let total = 0;\n \n for (const item of items) {\n total += item.price * item.quantity;\n }\n \n return total;\n}\n\nfunction applyDiscount(total, discountRules) {\n let discountedTotal = total;\n \n if (discountRules.percentOff) {\n discountedTotal -= (total * discountRules.percentOff / 100);\n }\n \n if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n discountedTotal -= discountRules.fixedAmount;\n }\n \n return Math.max(0, discountedTotal);\n}",
"usage": {
"prompt_tokens": 245,
"completion_tokens": 187,
"total_tokens": 432
}
}{
"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"
}Relace Apply runs at over 10,000 tok/s, making complicated code merges feel instantaneous.
Models
We have deprecated all previous versions of the apply models in favor ofrelace-apply-3, which is more performant on accuracy, speed, and long context requests.
| Model | Speed | Max Input | Max Output |
|---|---|---|---|
relace-apply-3 | ~10k tokens/s | 128k tokens | 128k tokens |
OpenAI Compatible Endpoint
If the Relace REST API is inconvenient, we also support an OpenAI compatible endpoint for our apply models.import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://instantapply.endpoint.relace.run/v1/apply',
});
const userMessage = `
<instruction>{instruction}</instruction>
<code>{initial_code}</code>
<update>{edit_snippet}</update>
`;
const response = await client.chat.completions.create({
model: 'auto',
messages: [
{
role: 'user',
content: userMessage,
},
],
});
The user message must include
<code> and <update> tags following the format above. The <instruction> tag is optional.OpenRouter
Relace Apply is also available via OpenRouter’s OpenAI-compatible endpoint. See the model page for current availability and details. The performance section of the model page shows our real-time throughput and latency numbers from customer requests.Fallbacks
We recommend using GPT-4.1-mini with predictive edits as a fallback. This option is 10-20x slower than Relace’s apply models, but it’s useful for redundancy. Relace apply models also return a400 error code when input exceeds context limits (see table above). For these cases, GPT-4o-mini’s 1M token context window is a reliable fallback option.
However, even frontier LLMs struggle with long context. We recommend proactive refactoring of files >32k tokens to improve output quality.Authorizations
Relace API key Authorization header using the Bearer scheme.
Body
application/json
Initial code and edits to apply
The original code that needs to be modified
The code changes to be applied to the initial code
Choice of apply model to use
Available options:
relace-apply-3 Optional single line instruction for to disambiguate the edit snippet. e.g. Remove the captcha from the login page
Whether to stream the response back
Optional metadata for logging and tracking purposes.
⌘I