An unofficial Google Apps Script client for the Exa.ai API. This library provides a simple way to use Exa.ai's semantic search capabilities directly in Google Apps Script projects.
- Full compatibility with Exa.ai API
- Similar interface to the official
exa-js
npm package - Easy integration with Google Apps Script
- Support for all Exa.ai search types and filters
- Detailed logging for debugging
- Comprehensive documentation and examples
- An Exa.ai account and API key (Get one here)
- Access to Google Apps Script (script.google.com)
- Open your Google Apps Script project
- Copy the contents of
exa.gs
into your project - Set up your Exa.ai API key in Script Properties:
- Go to File -> Project Settings -> Script Properties
- Add a new property with:
- Name:
EXA_API_KEY
- Value: Your Exa.ai API key
- Name:
- Use the library in your project:
function searchNews() {
const exa = new Exa(PropertiesService.getScriptProperties().getProperty('EXA_API_KEY'));
const results = exa.searchAndContents("Latest AI developments", {
category: "news_article",
numResults: 5
});
return results;
}
const exa = new Exa(apiKey);
exa.setLogging(true); // Optional: Enable debug logging
Searches for content and returns results with full text and summaries.
Parameters:
query
(string): The search queryoptions
(object): Search configuration
Available Options:
{
// Search Type
type: "neural" | "keyword" | "auto", // Default: "neural"
// Content Category
category: "company" | "research_paper" | "news_article" | "pdf" |
"github" | "tweet" | "movie" | "song" | "personal_site",
// Basic Options
useAutoprompt: boolean, // Default: true
numResults: number, // Default: 10
livecrawl: "always" | "fallback",
// Domain Filters
includeDomains: string[], // e.g., ["example.com"]
excludeDomains: string[], // e.g., ["spam.com"]
// Date Filters (ISO format)
startPublishedDate: string, // e.g., "2024-01-01T00:00:00.000Z"
endPublishedDate: string,
startCrawlDate: string,
endCrawlDate: string,
// Text Content Options
text: {
includeHtmlTags: boolean,
maxCharacters: number
},
// Highlight Options
highlights: {
query: string,
numSentences: number,
highlightsPerUrl: number
},
// Summary Options
summary: {
query: string
}
}
Response Structure:
{
requestId: string,
resolvedSearchType: string,
results: [{
score: number,
title: string,
url: string,
publishedDate: string,
author: string,
text: string,
summary: string,
highlights: string[],
highlightScores: number[],
image?: string
}]
}
function searchNews() {
const exa = new Exa(PropertiesService.getScriptProperties().getProperty('EXA_API_KEY'));
return exa.searchAndContents("AI news", {
category: "news_article",
numResults: 5
});
}
function searchAICompanies() {
const exa = new Exa(PropertiesService.getScriptProperties().getProperty('EXA_API_KEY'));
return exa.searchAndContents(
"innovative AI startups in natural language processing",
{
type: "neural",
category: "company",
numResults: 20,
startPublishedDate: "2024-01-01T00:00:00.000Z",
text: {
maxCharacters: 1000
},
highlights: {
query: "AI capabilities and innovations",
numSentences: 2
},
summary: {
query: "What are their main AI products and innovations?"
}
}
);
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to Exa.ai for their excellent API
- Built for the Google Apps Script community