API Recipes
Explore common API patterns and use cases for building with Vectara. Each recipe shows complete request and response examples you can adapt for your application.
Start with the Developer Quickstart for a fast 5-minute introduction to the basics.
How to use these recipesβ
These examples demonstrate real-world patterns for working with the Vectara API:
- Search for answers in a corpus
- Add content to a corpus
- Query with result limits
- List and delete corpora
Ready to explore? Each recipe includes complete code examples with explanations.
Search for answers in a corpusβ
Use case: Query an existing corpus and get AI-generated answers with context.
In this example, you have a corpus with uploaded data from an Employee Handbook. You want to ask, "How much PTO is offered to employees each year?"
To issue the cURL command in the example, you input the following field values:
x-api-key=YOUR_API_KEYcorpus_key=employee-handbookquery= How much PTO is offered to employees each year?
Example cURL commandβ
This example queries the corpus with the question about annual PTO.
VECTARA API QUERY
Code example with bash syntax.1
Example JSON responseβ
Letβs take a closer look at the first response:
EXAMPLE JSON RESPONSE
Code example with json syntax.1
The example API call provided the following response:
"Employee Handbook PTO is 20 days a year for all new employees. Employees earn more vacation days per year of service up to 5 extra days. Example: Once you begin your 5th year, you now have 25 vacation days."
The result answers the question and returns additional details about the query, such as the language, section, and offset.
Let's take a look at some other API calls that you can make.
Add content to a corpusβ
Use case: Upload files or index structured documents into an existing corpus.
You can add content to a corpus in two ways: upload files (PDF, Word, etc.) or index structured documents with JSON. Choose the method that fits your data format.
You need to input the following information:
x-api-keycorpus_key- File path (for file upload) or document content (for direct indexing)
Option 1: Upload a fileβ
In this example, you have a local doc.rtf file that you want to
upload the corpus with the corpus_key as employee-handbook:
UPLOAD FILE TO CORPUS
Code example with bash syntax.1
Example JSON responseβ
The file uploads successfully and you get the following response:
UPLOAD FILE RESPONSE
Code example with json syntax.1
Option 2: Index a document directlyβ
If you don't have a file to upload, you can create a document directly with text content:
INDEX DOCUMENT WITH CONTENT
Code example with bash syntax.1
Query with result limitsβ
Use case: Control how many search results are returned and processed.
In this example, you want to search for "technology" and limit the results to 50, then use those results for generating a summary.
Example cURL commandβ
QUERY WITH 50 RESULTS
Code example with bash syntax.1
Example JSON response with 5 resultsβ
RESPONSE WITH 5 RESULTS
Code example with json syntax.1
List and delete corporaβ
Use case: Manage your corpora by listing, filtering, and deleting them.
In this example, you'll list all corpora that contain "handbook" in the name, then delete a specific corpus.
- Execute the following curl command to list the corpora:
LIST CORPORA WITH FILTER
Code example with bash syntax.1?
You get the following response:
LIST CORPORA RESPONSE
Code example with json syntax.1
- Execute the following curl command to delete a specific corpus with
corpus_key=2025-handbook.
DELETE CORPUS
Code example with bash syntax.1?
You get the following response:
DELETE CORPUS RESPONSE
Code example with json syntax.1
- Execute the curl command from Step 1 again and the corpus you deleted no longer exists.