Tools: Web Search v1
The web-search
API endpoint allows you to search the web for relevant information. This is particularly useful when you need to gather up-to-date information from the internet for your AI applications.
The web search functionality is powered by Exa.
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.
Search the web
Search the web for relevant information by sending queries to the web search API endpoint.
Headers
- Name
Content-Type
- Type
- string
- Required
- Required
- Description
Request content type. Needs to be
application/json
.
- Name
Authorization
- Type
- string
- Required
- Required
- Description
Replace
<YOUR_API_KEY>
with your user/org API key.
- Name
LB-WEB-SEARCH-KEY
- Type
- string
- Required
- Required
- Description
Your Exa API key – obtain one from Exa Dashboard. Replace
YOUR_EXA_API_KEY
with your key.
Request Body
- Name
query
- Type
- string
- Required
- Required
- Description
The search query to execute.
- Name
service
- Type
- string
- Required
- Required
- Description
Currently only supports
'exa'
as the search service provider.
- Name
totalResults
- Type
- number
- Description
The maximum number of results to return from the search.
- Name
domains
- Type
- string[]
- Description
Optional array of domains to restrict the search to.
Usage example
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
EXA_API_KEY="<EXA-API-KEY>"
Search the web
Web Searching
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 objects containing the URL and the extracted content returned by the web search operation.
Web Search API Response
interface ToolWebSearchResponse { url: string; content: string; } type WebSearchResponse = ToolWebSearchResponse[];
- Name
url
- Type
- string
- Description
The URL of the search result.
- Name
content
- Type
- string
- Description
The extracted content from the search result.
API Response
[
{
"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..."
}
]