curl --request POST \
--url https://api.affinity.co/v2/files/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "revenue projections pitch deck",
"fileIds": [
1,
2
],
"limit": 20
}
'import requests
url = "https://api.affinity.co/v2/files/search"
payload = {
"prompt": "revenue projections pitch deck",
"fileIds": [1, 2],
"limit": 20
}
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({prompt: 'revenue projections pitch deck', fileIds: [1, 2], limit: 20})
};
fetch('https://api.affinity.co/v2/files/search', 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.affinity.co/v2/files/search",
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([
'prompt' => 'revenue projections pitch deck',
'fileIds' => [
1,
2
],
'limit' => 20
]),
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.affinity.co/v2/files/search"
payload := strings.NewReader("{\n \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\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://api.affinity.co/v2/files/search")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.affinity.co/v2/files/search")
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 \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"file": {
"id": 1,
"name": "pitch-deck-q3-2024.pdf"
},
"pageNumber": 3,
"preview": "Projected ARR of $12M by end of Q4 2024, with 80% gross margin."
}
]
}{
"errors": [
{
"code": "bad-request",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "not-found",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "authentication",
"message": "<string>"
}
]
}Search Files by Keyword
Search files by keyword. The scope of the search is controlled by the request body:
- Provide
fileIdsto limit the search to specific files. - Provide
companyIdto limit the search to files associated with a specific company. - Omit both to search across your entire account.
fileIds and companyId are mutually exclusive.
Returns up to limit files ordered by relevance. Prompts with no strong matches may
still return low-relevance results.
Each result contains a matched file and a single representative excerpt (a matching passage from that file). Even if a file contains multiple matching passages, it appears exactly once in the response with one excerpt.
curl --request POST \
--url https://api.affinity.co/v2/files/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "revenue projections pitch deck",
"fileIds": [
1,
2
],
"limit": 20
}
'import requests
url = "https://api.affinity.co/v2/files/search"
payload = {
"prompt": "revenue projections pitch deck",
"fileIds": [1, 2],
"limit": 20
}
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({prompt: 'revenue projections pitch deck', fileIds: [1, 2], limit: 20})
};
fetch('https://api.affinity.co/v2/files/search', 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.affinity.co/v2/files/search",
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([
'prompt' => 'revenue projections pitch deck',
'fileIds' => [
1,
2
],
'limit' => 20
]),
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.affinity.co/v2/files/search"
payload := strings.NewReader("{\n \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\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://api.affinity.co/v2/files/search")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.affinity.co/v2/files/search")
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 \"prompt\": \"revenue projections pitch deck\",\n \"fileIds\": [\n 1,\n 2\n ],\n \"limit\": 20\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"file": {
"id": 1,
"name": "pitch-deck-q3-2024.pdf"
},
"pageNumber": 3,
"preview": "Projected ARR of $12M by end of Q4 2024, with 80% gross margin."
}
]
}{
"errors": [
{
"code": "bad-request",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "not-found",
"message": "<string>"
}
]
}{
"errors": [
{
"code": "authentication",
"message": "<string>"
}
]
}Authorizations
A static Affinity API key, presented as a bearer token.
Body
- File Keyword Search Criteria (org-wide or by file IDs)
- File Keyword Search Criteria (by company)
Search all files in the org, or limit to specific file IDs.
The search query. Returns up to limit files ordered by relevance. Prompts with
no strong matches may still return low-relevance results.
3 - 500"revenue projections pitch deck"
Limit search to these specific files. Omit for org-wide search.
1001 <= x <= 2147483647[1, 2]
Maximum number of files to return.
1 <= x <= 10020
Response
Created
Results of a keyword search over files.
Matching file results, one per file, ordered by relevance.
100Show child attributes
Show child attributes
Was this page helpful?