Web Search langbase.tools.webSearch()
You can use the tools.webSearch()
function to search the web for relevant information. This functionality is powered by Exa, and you'll need to obtain an API key from them to use this feature.
Pre-requisites
- Langbase API Key: Generate your API key from the User/Org API key documentation.
- Exa API Key: Sign up at Exa Dashboard to get your web search API key.
API reference
langbase.tools.webSearch(options)
Search the web by running the langbase.tools.webSearch()
function.
Function Signature
langbase.tools.webSearch(options);
// with types
langbase.tools.webSearch(options: ToolWebSearchOptions);
options
- Name
options
- Type
- ToolWebSearchOptions
- Description
ToolWebSearchOptions Object
interface ToolWebSearchOptions { query: string; service: 'exa'; apiKey: string; totalResults?: number; domains?: string[]; }
Following are the properties of the options object.
query
- Name
query
- Type
- string
- Required
- Required
- Description
The search query to execute.
service
- Name
service
- Type
- string
- Required
- Required
- Description
Currently only supports
'exa'
as the search service provider.
apiKey
- Name
apiKey
- Type
- string
- Required
- Required
- Description
Your Exa API key – get one from the Exa Dashboard.
totalResults
- Name
totalResults
- Type
- number
- Description
The maximum number of results to return from the search.
domains
- Name
domains
- Type
- string[]
- Description
Optional array of domains to restrict the search to.
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
EXA_API_KEY="<EXA-API-KEY>"
langbase.tools.webSearch()
examples
langbase.tools.webSearch()
import { Langbase } from 'langbase';
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
const results = await langbase.tools.webSearch({
query: 'What is Langbase?',
service: 'exa',
apiKey: process.env.EXA_API_KEY!,
totalResults: 2
});
console.log('Search results:', results);
}
main();
Response
- Name
ToolWebSearchResponse[]
- Type
- Array<object>
- Description
An array of web search result objects returned by the
langbase.tools.webSearch()
function.ToolWebSearchResponse Type
interface ToolWebSearchResponse { url: string; content: string; }
- Name
url
- Type
- string
- Description
The URL of the search result.
- Name
content
- Type
- string
- Description
The extracted content from the search result.
ToolWebSearchResponse Example
[
{
"url": "https://langbase.com/docs/introduction",
"content": "Langbase is a powerful AI development platform..."
},
{
"url": "https://langbase.com/docs/getting-started",
"content": "Get started with Langbase by installing our SDK..."
}
]