data
Tavily Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Tavily KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.tavily.*.
Use lua_read_doc("integrations.tavily") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Tavily workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"}))' --json kosmo integrations:lua --eval 'print(docs.read("tavily"))' --json
kosmo integrations:lua --eval 'print(docs.read("tavily.search"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local tavily = app.integrations.tavily
local result = tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.tavily, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.tavily.default.* or app.integrations.tavily.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Tavily, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Tavily — Lua API Reference
The tavily integration exposes Tavily’s AI-oriented search, extraction, crawl, map, research, and usage APIs.
Use it when an agent needs current web information, clean source content, a site map, documentation crawl material, or a longer asynchronous research report.
All calls require a Tavily API key. If a project_id is configured, the integration sends it as X-Project-ID so usage can be tracked per project.
search
Execute a web search and return Tavily’s JSON response. Results are kept in Tavily’s native shape: top-level query, optional answer, optional images, results, response_time, optional usage, and request_id.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
query | string | yes | Search query. |
search_depth | string | no | basic, advanced, fast, or ultra-fast. |
chunks_per_source | integer | no | Chunks per source for advanced search, 1-3. |
max_results | integer | no | Maximum results, 0-20. |
topic | string | no | general, news, or finance. |
time_range | string | no | day, week, month, year, or shorthand d, w, m, y. |
start_date | string | no | Start date in YYYY-MM-DD format. |
end_date | string | no | End date in YYYY-MM-DD format. |
include_answer | boolean | string | no |
include_raw_content | boolean | string | no |
include_images | boolean | no | Include query and per-result images. |
include_image_descriptions | boolean | no | Include image descriptions when images are enabled. |
include_favicon | boolean | no | Include result favicons. |
include_domains | string[] | no | Only include these domains. |
exclude_domains | string[] | no | Exclude these domains. |
country | string | no | Boost results from a Tavily-supported country value. |
auto_parameters | boolean | no | Let Tavily pick some search parameters. |
exact_match | boolean | no | Require exact quoted phrases in results. |
include_usage | boolean | no | Include credit usage details. |
safe_search | boolean | no | Enterprise-only unsafe-content filtering. |
Example
local result = app.integrations.tavily.search({
query = "latest Laravel release notes",
search_depth = "advanced",
include_answer = "basic",
include_raw_content = "markdown",
include_favicon = true,
max_results = 5
})
for _, item in ipairs(result.results or {}) do
print(item.title .. " " .. item.url)
end
extract
Extract clean content from one or more URLs. The output keeps Tavily’s native results, failed_results, response_time, optional usage, and request_id fields.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
urls | string | string[] | yes |
query | string | no | Intent used to rerank extracted chunks. |
chunks_per_source | integer | no | Chunks per source when query is supplied, 1-5. |
extract_depth | string | no | basic or advanced. |
include_images | boolean | no | Include extracted images. |
include_favicon | boolean | no | Include favicon URL for each result. |
format | string | no | markdown or text. |
timeout | number | no | Timeout in seconds, 1-60. |
include_usage | boolean | no | Include credit usage details. |
Example
local extracted = app.integrations.tavily.extract({
urls = {
"https://example.test/docs/getting-started",
"https://example.test/docs/api"
},
extract_depth = "advanced",
format = "markdown"
})
crawl
Crawl a site and extract content from discovered pages. Use this for RAG ingestion or documentation snapshots when full content is needed.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | yes | Root URL. |
instructions | string | no | Natural language crawl instructions. |
chunks_per_source | integer | no | Chunks per source when instructions are supplied, 1-5. |
max_depth | integer | no | Crawl depth, 1-5. |
max_breadth | integer | no | Links followed per level, 1-500. |
limit | integer | no | Total links to process. |
select_paths | string[] | no | Regex path patterns to include. |
select_domains | string[] | no | Regex domain patterns to include. |
exclude_paths | string[] | no | Regex path patterns to exclude. |
exclude_domains | string[] | no | Regex domain patterns to exclude. |
allow_external | boolean | no | Whether external links may be included. |
include_images | boolean | no | Include images in results. |
extract_depth | string | no | basic or advanced. |
format | string | no | markdown or text. |
include_favicon | boolean | no | Include favicon URL for each result. |
timeout | number | no | Timeout in seconds, 10-150. |
include_usage | boolean | no | Include credit usage details. |
Example
local crawl = app.integrations.tavily.crawl({
url = "https://example.test/docs",
instructions = "Find API reference pages",
select_paths = {"/docs/.*"},
max_depth = 2,
limit = 25,
format = "markdown"
})
map
Map a website and return discovered URLs only. Use this before extract or crawl when the agent needs to decide which URLs matter.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | yes | Root URL. |
instructions | string | no | Natural language mapping instructions. |
max_depth | integer | no | Mapping depth, 1-5. |
max_breadth | integer | no | Links followed per level, 1-500. |
limit | integer | no | Total links to process. |
select_paths | string[] | no | Regex path patterns to include. |
select_domains | string[] | no | Regex domain patterns to include. |
exclude_paths | string[] | no | Regex path patterns to exclude. |
exclude_domains | string[] | no | Regex domain patterns to exclude. |
allow_external | boolean | no | Whether external links may be included. |
timeout | number | no | Timeout in seconds, 10-150. |
include_usage | boolean | no | Include credit usage details. |
Example
local mapped = app.integrations.tavily.map({
url = "https://example.test/docs",
select_paths = {"/docs/.*"},
limit = 100
})
create_research_task
Queue an asynchronous Tavily Research task. The result includes request_id, which can be passed to get_research_task.
Streaming is not supported by this integration tool because Tavily streaming returns Server-Sent Events rather than a JSON tool result.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
input | string | yes | Research task or question. |
model | string | no | mini, pro, or auto. |
output_schema | object | no | JSON Schema with properties and optional required. |
citation_format | string | no | numbered, mla, apa, or chicago. |
Example
local task = app.integrations.tavily.create_research_task({
input = "Compare current EU AI Act compliance guidance for SaaS vendors",
model = "pro",
citation_format = "numbered"
})
print(task.request_id)
get_research_task
Retrieve status or completed content for a research task.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
request_id | string | yes | Tavily research request ID. |
Example
local report = app.integrations.tavily.get_research_task({
request_id = "123e4567-e89b-12d3-a456-426614174111"
})
print(report.status)
print(report.content)
get_usage
Retrieve API key and account usage. The response contains key and account usage objects when available.
Parameters
None.
Example
local usage = app.integrations.tavily.get_usage()
print(usage.key and usage.key.usage)
Multi-Account Usage
If multiple Tavily accounts are configured, use account-specific namespaces:
app.integrations.tavily.search({ query = "default account search" })
app.integrations.tavily.default.search({ query = "explicit default account" })
app.integrations.tavily.research.search({ query = "named account search" })Raw agent markdown
# Tavily — Lua API Reference
The `tavily` integration exposes Tavily's AI-oriented search, extraction, crawl, map, research, and usage APIs.
Use it when an agent needs current web information, clean source content, a site map, documentation crawl material, or a longer asynchronous research report.
All calls require a Tavily API key. If a `project_id` is configured, the integration sends it as `X-Project-ID` so usage can be tracked per project.
## search
Execute a web search and return Tavily's JSON response. Results are kept in Tavily's native shape: top-level `query`, optional `answer`, optional `images`, `results`, `response_time`, optional `usage`, and `request_id`.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | yes | Search query. |
| `search_depth` | string | no | `basic`, `advanced`, `fast`, or `ultra-fast`. |
| `chunks_per_source` | integer | no | Chunks per source for advanced search, 1-3. |
| `max_results` | integer | no | Maximum results, 0-20. |
| `topic` | string | no | `general`, `news`, or `finance`. |
| `time_range` | string | no | `day`, `week`, `month`, `year`, or shorthand `d`, `w`, `m`, `y`. |
| `start_date` | string | no | Start date in `YYYY-MM-DD` format. |
| `end_date` | string | no | End date in `YYYY-MM-DD` format. |
| `include_answer` | boolean|string | no | `true`, `basic`, or `advanced` to include an answer. |
| `include_raw_content` | boolean|string | no | `true`, `markdown`, or `text` to include page content. |
| `include_images` | boolean | no | Include query and per-result images. |
| `include_image_descriptions` | boolean | no | Include image descriptions when images are enabled. |
| `include_favicon` | boolean | no | Include result favicons. |
| `include_domains` | string[] | no | Only include these domains. |
| `exclude_domains` | string[] | no | Exclude these domains. |
| `country` | string | no | Boost results from a Tavily-supported country value. |
| `auto_parameters` | boolean | no | Let Tavily pick some search parameters. |
| `exact_match` | boolean | no | Require exact quoted phrases in results. |
| `include_usage` | boolean | no | Include credit usage details. |
| `safe_search` | boolean | no | Enterprise-only unsafe-content filtering. |
### Example
```lua
local result = app.integrations.tavily.search({
query = "latest Laravel release notes",
search_depth = "advanced",
include_answer = "basic",
include_raw_content = "markdown",
include_favicon = true,
max_results = 5
})
for _, item in ipairs(result.results or {}) do
print(item.title .. " " .. item.url)
end
```
## extract
Extract clean content from one or more URLs. The output keeps Tavily's native `results`, `failed_results`, `response_time`, optional `usage`, and `request_id` fields.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `urls` | string|string[] | yes | URL or URLs to extract. |
| `query` | string | no | Intent used to rerank extracted chunks. |
| `chunks_per_source` | integer | no | Chunks per source when `query` is supplied, 1-5. |
| `extract_depth` | string | no | `basic` or `advanced`. |
| `include_images` | boolean | no | Include extracted images. |
| `include_favicon` | boolean | no | Include favicon URL for each result. |
| `format` | string | no | `markdown` or `text`. |
| `timeout` | number | no | Timeout in seconds, 1-60. |
| `include_usage` | boolean | no | Include credit usage details. |
### Example
```lua
local extracted = app.integrations.tavily.extract({
urls = {
"https://example.test/docs/getting-started",
"https://example.test/docs/api"
},
extract_depth = "advanced",
format = "markdown"
})
```
## crawl
Crawl a site and extract content from discovered pages. Use this for RAG ingestion or documentation snapshots when full content is needed.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `url` | string | yes | Root URL. |
| `instructions` | string | no | Natural language crawl instructions. |
| `chunks_per_source` | integer | no | Chunks per source when instructions are supplied, 1-5. |
| `max_depth` | integer | no | Crawl depth, 1-5. |
| `max_breadth` | integer | no | Links followed per level, 1-500. |
| `limit` | integer | no | Total links to process. |
| `select_paths` | string[] | no | Regex path patterns to include. |
| `select_domains` | string[] | no | Regex domain patterns to include. |
| `exclude_paths` | string[] | no | Regex path patterns to exclude. |
| `exclude_domains` | string[] | no | Regex domain patterns to exclude. |
| `allow_external` | boolean | no | Whether external links may be included. |
| `include_images` | boolean | no | Include images in results. |
| `extract_depth` | string | no | `basic` or `advanced`. |
| `format` | string | no | `markdown` or `text`. |
| `include_favicon` | boolean | no | Include favicon URL for each result. |
| `timeout` | number | no | Timeout in seconds, 10-150. |
| `include_usage` | boolean | no | Include credit usage details. |
### Example
```lua
local crawl = app.integrations.tavily.crawl({
url = "https://example.test/docs",
instructions = "Find API reference pages",
select_paths = {"/docs/.*"},
max_depth = 2,
limit = 25,
format = "markdown"
})
```
## map
Map a website and return discovered URLs only. Use this before `extract` or `crawl` when the agent needs to decide which URLs matter.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `url` | string | yes | Root URL. |
| `instructions` | string | no | Natural language mapping instructions. |
| `max_depth` | integer | no | Mapping depth, 1-5. |
| `max_breadth` | integer | no | Links followed per level, 1-500. |
| `limit` | integer | no | Total links to process. |
| `select_paths` | string[] | no | Regex path patterns to include. |
| `select_domains` | string[] | no | Regex domain patterns to include. |
| `exclude_paths` | string[] | no | Regex path patterns to exclude. |
| `exclude_domains` | string[] | no | Regex domain patterns to exclude. |
| `allow_external` | boolean | no | Whether external links may be included. |
| `timeout` | number | no | Timeout in seconds, 10-150. |
| `include_usage` | boolean | no | Include credit usage details. |
### Example
```lua
local mapped = app.integrations.tavily.map({
url = "https://example.test/docs",
select_paths = {"/docs/.*"},
limit = 100
})
```
## create_research_task
Queue an asynchronous Tavily Research task. The result includes `request_id`, which can be passed to `get_research_task`.
Streaming is not supported by this integration tool because Tavily streaming returns Server-Sent Events rather than a JSON tool result.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `input` | string | yes | Research task or question. |
| `model` | string | no | `mini`, `pro`, or `auto`. |
| `output_schema` | object | no | JSON Schema with `properties` and optional `required`. |
| `citation_format` | string | no | `numbered`, `mla`, `apa`, or `chicago`. |
### Example
```lua
local task = app.integrations.tavily.create_research_task({
input = "Compare current EU AI Act compliance guidance for SaaS vendors",
model = "pro",
citation_format = "numbered"
})
print(task.request_id)
```
## get_research_task
Retrieve status or completed content for a research task.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `request_id` | string | yes | Tavily research request ID. |
### Example
```lua
local report = app.integrations.tavily.get_research_task({
request_id = "123e4567-e89b-12d3-a456-426614174111"
})
print(report.status)
print(report.content)
```
## get_usage
Retrieve API key and account usage. The response contains `key` and `account` usage objects when available.
### Parameters
None.
### Example
```lua
local usage = app.integrations.tavily.get_usage()
print(usage.key and usage.key.usage)
```
## Multi-Account Usage
If multiple Tavily accounts are configured, use account-specific namespaces:
```lua
app.integrations.tavily.search({ query = "default account search" })
app.integrations.tavily.default.search({ query = "explicit default account" })
app.integrations.tavily.research.search({ query = "named account search" })
``` local result = app.integrations.tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"})
print(result) Functions
search Read
Search the web with Tavily. Use for current information, source discovery, and AI-ready snippets. Supports answer generation, raw page content, images, recency/date filters, domain filters, country boosting, and usage details.
- Lua path
app.integrations.tavily.search- Full name
tavily.tavily_search
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | yes | Search query to execute. |
search_depth | string | no | Latency/relevance tradeoff. advanced costs more and can return multiple chunks. |
chunks_per_source | integer | no | Relevant chunks per source for advanced search. Range: 1-3. |
max_results | integer | no | Maximum results to return. Range: 0-20. Default: 5. |
topic | string | no | Search topic. |
time_range | string | no | Relative publish/update time range. |
start_date | string | no | Return results after this YYYY-MM-DD date. |
end_date | string | no | Return results before this YYYY-MM-DD date. |
include_answer | boolean,string | no | false, true, basic, or advanced. Adds an LLM-generated answer. |
include_raw_content | boolean,string | no | false, true, markdown, or text. Adds cleaned page content to results. |
include_images | boolean | no | Include query and per-result images. |
include_image_descriptions | boolean | no | Add descriptions for images when include_images is true. |
include_favicon | boolean | no | Include favicon URL for each result. |
include_domains | array | no | Only include these domains. Maximum 300 domains. |
exclude_domains | array | no | Exclude these domains. Maximum 150 domains. |
country | string | no | Boost results from a documented Tavily country value. Only applies to general topic. |
auto_parameters | boolean | no | Let Tavily select search parameters from query intent. Explicit values override auto values. |
exact_match | boolean | no | Require exact quoted phrases in results. |
include_usage | boolean | no | Include credit usage details. |
safe_search | boolean | no | Enterprise-only unsafe-content filtering. Not supported for fast or ultra-fast depth. |
extract Read
Extract clean markdown or text content from one or more URLs with Tavily. Use after search or map when an agent needs full page content.
- Lua path
app.integrations.tavily.extract- Full name
tavily.tavily_extract
| Parameter | Type | Required | Description |
|---|---|---|---|
urls | string,array | yes | URL or array of URLs to extract. |
query | string | no | Optional user intent for reranking extracted content chunks. |
chunks_per_source | integer | no | Chunks per source when query is provided. Range: 1-5. |
extract_depth | string | no | Extraction depth. advanced retrieves more data with higher latency/cost. |
include_images | boolean | no | Include images extracted from URLs. |
include_favicon | boolean | no | Include favicon URL for each result. |
format | string | no | Output format for raw_content. |
timeout | number | no | Extraction timeout in seconds. Range: 1-60. |
include_usage | boolean | no | Include credit usage details. |
crawl Read
Crawl a website with Tavily and return extracted content from discovered pages. Use for documentation ingestion, RAG source collection, and targeted site extraction.
- Lua path
app.integrations.tavily.crawl- Full name
tavily.tavily_crawl
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | Root URL to begin the crawl. |
instructions | string | no | Natural language crawl instructions. Increases mapping cost when supplied. |
chunks_per_source | integer | no | Chunks per source when instructions are supplied. Range: 1-5. |
max_depth | integer | no | Maximum crawl depth. Range: 1-5. |
max_breadth | integer | no | Maximum links to follow per level. Range: 1-500. |
limit | integer | no | Maximum number of links to process. |
select_paths | array | no | Regex path patterns to include. |
select_domains | array | no | Regex domain patterns to include. |
exclude_paths | array | no | Regex path patterns to exclude. |
exclude_domains | array | no | Regex domain patterns to exclude. |
allow_external | boolean | no | Whether external links may appear in final results. |
include_images | boolean | no | Include images in crawl results. |
extract_depth | string | no | Extraction depth for crawled pages. |
format | string | no | Output format for raw_content. |
include_favicon | boolean | no | Include favicon URL for each result. |
timeout | number | no | Crawl timeout in seconds. Range: 10-150. |
include_usage | boolean | no | Include credit usage details. |
map Read
Map a website with Tavily and return discovered URLs without extracting full page content. Use before targeted extract or crawl jobs.
- Lua path
app.integrations.tavily.map- Full name
tavily.tavily_map
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | Root URL to begin mapping. |
instructions | string | no | Natural language mapping instructions. Increases cost when supplied. |
max_depth | integer | no | Maximum mapping depth. Range: 1-5. |
max_breadth | integer | no | Maximum links to follow per level. Range: 1-500. |
limit | integer | no | Maximum number of links to process. |
select_paths | array | no | Regex path patterns to include. |
select_domains | array | no | Regex domain patterns to include. |
exclude_paths | array | no | Regex path patterns to exclude. |
exclude_domains | array | no | Regex domain patterns to exclude. |
allow_external | boolean | no | Whether external links may appear in final results. |
timeout | number | no | Map timeout in seconds. Range: 10-150. |
include_usage | boolean | no | Include credit usage details. |
create_research_task Read
Create a Tavily Research task for comprehensive multi-source research. The returned request_id can be passed to tavily_get_research_task.
- Lua path
app.integrations.tavily.create_research_task- Full name
tavily.tavily_create_research_task
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | yes | Research question or task to investigate. |
model | string | no | Research agent model. mini is targeted, pro is comprehensive, auto lets Tavily choose. |
output_schema | object | no | Optional JSON Schema with properties and optional required fields for structured output. |
citation_format | string | no | Citation format for the research report. |
stream | boolean | no | Not supported by this tool. Tavily streaming returns SSE rather than JSON. |
get_research_task Read
Get the current status and, when complete, the content and sources for a Tavily Research task by request_id.
- Lua path
app.integrations.tavily.get_research_task- Full name
tavily.tavily_get_research_task
| Parameter | Type | Required | Description |
|---|---|---|---|
request_id | string | yes | Research task request_id returned by tavily_create_research_task. |
get_usage Read
Get Tavily API key and account usage details, including per-endpoint credit usage and plan limits.
- Lua path
app.integrations.tavily.get_usage- Full name
tavily.tavily_get_usage
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||