Auto-Suggest¶
Provide real-time search suggestions to users as they enter text in the search box.
Guide
For a step-by-step guide on how to implement auto-suggest, see Implement Auto-Suggest.
Endpoint¶
API Request¶
-
Required Parameters
query string required
Partial query entered by the user for which suggestions should be retrieved.
MinLength: 1
MaxLength: 50
Optional Parameters
filter object
JSON object specifying the filter criteria.
language string (enum)
Language code (of a supported language) that indicates the language of the documents to search.
Default is
en
.Info
- Ignored if
multilingual_search
istrue
.
limit integer
Limit on the maximum number of suggestions to return. Default is
5
.Min: 1
Max: 10
tenant_id array of strings
Array specifying one or more Tenant IDs.
Info
-
Only documents with a
tenant_id
matching one of the values in the array will be considered. -
Example (single tenant ID):
-
Example (multiple tenant IDs):
-
For each tenant ID string:
MinLength: 1
MaxLength: 250
MinLength: 1
MaxLength: 10
- Ignored if
-
POST /v20241104/auto-suggest
curl -X POST "https://api.gainly.ai/v20241104/auto-suggest" \ -H "Content-Type: application/json" \ -H "X-API-Key: YOUR_API_KEY_HERE" \ # (1)! -d '{ "query": "alpa" }'
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
# Prompt for AI coding assistants/IDEs (e.g., ChatGPT, Claude, GitHub Copilot, Cursor, Windsurf) Using the Gainly API: 1. Write code to call the auto_suggest operation (see OpenAPI spec: https://api.gainly.ai/v20241104/openapi.json) 2. Implement authentication using the header "X-API-Key" as described in the docs: https://docs.gainly.ai/latest/api-reference/authentication/ 3. Implement rate limit handling as described in the docs: https://docs.gainly.ai/latest/api-reference/rate-limits/ 4. Implement error handling 5. Handle the response according to the AutoSuggestResults schema in the OpenAPI spec
using System.Net.Http; using System.Text.Json; using System.Text; var client = new HttpClient(); var url = "https://api.gainly.ai/v20241104/auto-suggest"; var payload = new { query = "alpa" }; var content = new StringContent( JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json" ); client.DefaultRequestHeaders.Add("X-API-Key", "YOUR_API_KEY_HERE"); // (1)! var response = await client.PostAsync(url, content); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result);
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.gainly.ai/v20241104/auto-suggest" payload := map[string]interface{}{ "query": "alpa", } jsonData, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-API-Key", "YOUR_API_KEY_HERE") // (1)! resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) }
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; var client = HttpClient.newHttpClient(); var url = "https://api.gainly.ai/v20241104/auto-suggest"; var payload = """ { "query": "alpa" } """; var request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") .header("X-API-Key", "YOUR_API_KEY_HERE") // (1)! .POST(HttpRequest.BodyPublishers.ofString(payload)) .build(); var response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body());
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
const axios = require('axios'); // or: import axios from 'axios'; const url = 'https://api.gainly.ai/v20241104/auto-suggest'; const payload = { query: 'alpa' }; const headers = { 'Content-Type': 'application/json', 'X-API-Key': 'YOUR_API_KEY_HERE' // (1)! }; axios.post(url, payload, { headers }) .then(response => console.log(response.data)) .catch(error => console.error('Error:', error.message));
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
<?php $client = new \GuzzleHttp\Client(); $url = 'https://api.gainly.ai/v20241104/auto-suggest'; $payload = [ 'query' => 'alpa' ]; $response = $client->request('POST', $url, [ 'json' => $payload, 'headers' => [ 'Content-Type' => 'application/json', 'X-API-Key' => 'YOUR_API_KEY_HERE' # (1)! ], ]); echo $response->getBody();
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
import requests url = "https://api.gainly.ai/v20241104/auto-suggest" payload = { "query": "alpa" } headers = { "Content-Type": "application/json", "X-API-Key": "YOUR_API_KEY_HERE" # (1)! } response = requests.post(url, json=payload, headers=headers) data = response.json() print(data)
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
require 'json' require 'uri' require 'net/http' require 'openssl' url = URI('https://api.gainly.ai/v20241104/auto-suggest') http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request['Content-Type'] = 'application/json' request['X-API-Key'] = 'YOUR_API_KEY_HERE' # (1)! request.body = { query: 'alpa' }.to_json response = http.request(request) puts response.read_body
- Replace
YOUR_API_KEY_HERE
with the value of your API key.
- Replace
API Response¶
{
"object": "auto_suggest_result",
"url": "/v20241104/auto-suggest",
"query": "alpa",
"data": [
{
"id": "B3AegpIB7caKVIeL78nJ",
"title": "Alpacas and Their Role in Sustainable Farming",
"source_uri": "/doc/7-alpacas-role-sustainable-farming",
"metadata": null,
"tenant_id": "tenant123",
"language": "en",
"created_at": "2024-08-15T21:58:53Z",
"updated_at": "2024-08-16T12:28:12Z"
},
{
"id": "4nD1gZIB7caKVIeL2MgL",
"title": "Alpaca Fleece and Its Economic Impact",
"source_uri": "/doc/12-alpaca-fleece-economic-impact",
"metadata": null,
"tenant_id": "tenant123",
"language": "en",
"created_at": "2024-08-16T15:58:53Z",
"updated_at": "2024-08-17T15:58:53Z"
}
],
"tenant_id": null,
"language": "en",
"filter": null,
"total_number_of_results": 2,
"limit": 5,
"token_usage": {
"semantic_tokens": 0,
"llm_tokens": {
"llm_output_tokens": 0,
"llm_input_tokens": 0,
"model": null
}
},
"livemode": false
}