cURL
curl --request POST \
--url https://models.relace.ai/v2/code/rank \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "Optimize the search function for better performance with large arrays",
"codebase": [
{
"filename": "src/search.ts",
"content": "function findItem(array: Item[], targetId: string): Item | undefined {\\n for (let i = 0; i < array.length; i++) {\\n const item = array[i];\\n if (item.id === targetId) {\\n return item;\\n}\\n}\\n return undefined;\\n}"
}
],
"token_limit": 100000
}
'import requests
url = "https://models.relace.ai/v2/code/rank"
payload = {
"query": "Optimize the search function for better performance with large arrays",
"codebase": [
{
"filename": "src/search.ts",
"content": "function findItem(array: Item[], targetId: string): Item | undefined {\n for (let i = 0; i < array.length; i++) {\n const item = array[i];\n if (item.id === targetId) {\n return item;\n}\n}\n return undefined;\n}"
}
],
"token_limit": 100000
}
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({
query: 'Optimize the search function for better performance with large arrays',
codebase: [
{
filename: 'src/search.ts',
content: 'function findItem(array: Item[], targetId: string): Item | undefined {\n for (let i = 0; i < array.length; i++) {\n const item = array[i];\n if (item.id === targetId) {\n return item;\n}\n}\n return undefined;\n}'
}
],
token_limit: 100000
})
};
fetch('https://models.relace.ai/v2/code/rank', 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/v2/code/rank",
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([
'query' => 'Optimize the search function for better performance with large arrays',
'codebase' => [
[
'filename' => 'src/search.ts',
'content' => 'function findItem(array: Item[], targetId: string): Item | undefined {\\n for (let i = 0; i < array.length; i++) {\\n const item = array[i];\\n if (item.id === targetId) {\\n return item;\\n}\\n}\\n return undefined;\\n}'
]
],
'token_limit' => 100000
]),
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/v2/code/rank"
payload := strings.NewReader("{\n \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\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/v2/code/rank")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://models.relace.ai/v2/code/rank")
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 \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"filename": "src/search.ts",
"score": 0.953125
}
],
"usage": {
"total_tokens": 96
}
}{
"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/rank"
}{
"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
Rank Code
Assess the relevance of each file in your codebase to a user’s query.
POST
/
v2
/
code
/
rank
cURL
curl --request POST \
--url https://models.relace.ai/v2/code/rank \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "Optimize the search function for better performance with large arrays",
"codebase": [
{
"filename": "src/search.ts",
"content": "function findItem(array: Item[], targetId: string): Item | undefined {\\n for (let i = 0; i < array.length; i++) {\\n const item = array[i];\\n if (item.id === targetId) {\\n return item;\\n}\\n}\\n return undefined;\\n}"
}
],
"token_limit": 100000
}
'import requests
url = "https://models.relace.ai/v2/code/rank"
payload = {
"query": "Optimize the search function for better performance with large arrays",
"codebase": [
{
"filename": "src/search.ts",
"content": "function findItem(array: Item[], targetId: string): Item | undefined {\n for (let i = 0; i < array.length; i++) {\n const item = array[i];\n if (item.id === targetId) {\n return item;\n}\n}\n return undefined;\n}"
}
],
"token_limit": 100000
}
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({
query: 'Optimize the search function for better performance with large arrays',
codebase: [
{
filename: 'src/search.ts',
content: 'function findItem(array: Item[], targetId: string): Item | undefined {\n for (let i = 0; i < array.length; i++) {\n const item = array[i];\n if (item.id === targetId) {\n return item;\n}\n}\n return undefined;\n}'
}
],
token_limit: 100000
})
};
fetch('https://models.relace.ai/v2/code/rank', 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/v2/code/rank",
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([
'query' => 'Optimize the search function for better performance with large arrays',
'codebase' => [
[
'filename' => 'src/search.ts',
'content' => 'function findItem(array: Item[], targetId: string): Item | undefined {\\n for (let i = 0; i < array.length; i++) {\\n const item = array[i];\\n if (item.id === targetId) {\\n return item;\\n}\\n}\\n return undefined;\\n}'
]
],
'token_limit' => 100000
]),
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/v2/code/rank"
payload := strings.NewReader("{\n \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\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/v2/code/rank")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://models.relace.ai/v2/code/rank")
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 \"query\": \"Optimize the search function for better performance with large arrays\",\n \"codebase\": [\n {\n \"filename\": \"src/search.ts\",\n \"content\": \"function findItem(array: Item[], targetId: string): Item | undefined {\\\\n for (let i = 0; i < array.length; i++) {\\\\n const item = array[i];\\\\n if (item.id === targetId) {\\\\n return item;\\\\n}\\\\n}\\\\n return undefined;\\\\n}\"\n }\n ],\n \"token_limit\": 100000\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"filename": "src/search.ts",
"score": 0.953125
}
],
"usage": {
"total_tokens": 96
}
}{
"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/rank"
}{
"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."
}Authorizations
Relace API key Authorization header using the Bearer scheme.
Body
application/json
Query and codebase context for relevance scoring
The natural language query describing the problem to solve
An array of files with their content, providing context for the query
Show child attributes
Show child attributes
Maximum token limit for the response
Optional metadata for logging and tracking purposes. Removed before forwarding to origin server.