PluginsTavily
Tavily
Integrate Tavily AI-powered web search
Quick Start
Install the plugin:
pnpm install @corsair-dev/tavilyAdd the Tavily plugin to your Corsair instance:
import { createCorsair } from "corsair";
import { tavily } from "@corsair-dev/tavily";
export const corsair = createCorsair({
plugins: [
tavily(),
],
});Once configured, you can search the web:
// Search the web
const results = await corsair.tavily.api.search({
query: "latest AI research papers 2024",
});Authentication
Supported Auth Types
The Tavily plugin supports:
api_key(default) - Use a Tavily API key
Default Auth Type
If no authType is specified, the plugin defaults to api_key.
Configuring API Key Authentication
Store credentials with the CLI:
pnpm corsair setup --tavily api_key=your-api-keyAlternatively, provide credentials directly in the config:
tavily({
key: process.env.TAVILY_API_KEY,
})See Authentication for details on managing credentials.
Options
| Option | Type | Description |
|---|---|---|
authType | 'api_key' | Authentication method (defaults to 'api_key') |
key | string | API key (optional, uses database if not provided) |
hooks | object | Endpoint hooks for custom logic |
errorHandlers | object | Custom error handlers |
permissions | object | Permission configuration for AI agent access |
Hooks
tavily({
hooks: {
search: {
before: async (ctx, input) => {
console.log("Searching for:", input.query);
return { ctx, input };
},
},
},
})See Hooks for complete documentation.
Error Handling
The plugin includes built-in error handlers for common scenarios. For complete documentation, see the Error Handlers reference.
Usage
Accessing the API
// Basic search
const results = await corsair.tavily.api.search({
query: "TypeScript best practices 2024",
});
// Advanced search with options
const detailed = await corsair.tavily.api.search({
query: "React server components tutorial",
search_depth: "advanced",
max_results: 10,
include_answer: true,
});See API Endpoints for the complete reference.
Multi-Tenancy
const tenant = corsair.withTenant("user-123");
const results = await tenant.tavily.api.search({
query: "machine learning news",
});Examples
Example 1: AI Research Assistant
export const researchTopic = inngest.createFunction(
{ id: "research-topic" },
{ event: "app/research-requested" },
async ({ event }) => {
const tenant = corsair.withTenant(event.data.tenantId);
const results = await tenant.tavily.api.search({
query: event.data.topic,
search_depth: "advanced",
include_answer: true,
max_results: 5,
});
return {
answer: results.data.answer,
sources: results.data.results.map(r => r.url),
};
}
);Example 2: Real-time News Aggregation
export const fetchNewsDigest = inngest.createFunction(
{ id: "fetch-news-digest" },
{ cron: "0 9 * * *" },
async () => {
const topics = ["AI", "TypeScript", "web development"];
const searches = await Promise.all(
topics.map(topic =>
corsair.tavily.api.search({
query: `${topic} news today`,
topic: "news",
time_range: "day",
max_results: 3,
})
)
);
return searches.map((s, i) => ({
topic: topics[i],
results: s.data.results,
}));
}
);