File size: 628 Bytes
0bcc252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import axios from 'axios';
import {BRAVE_API_KEY} from "../config";

import { BraveSearchResponse } from '../types';

export async function braveSearch(query: string): Promise<{ response: BraveSearchResponse }> {
  const response = await axios.get<BraveSearchResponse>('https://api.search.brave.com/res/v1/web/search', {
    params: {
      q: query,
      count: 10,
      safesearch: 'off'
    },
    headers: {
      'Accept': 'application/json',
      'X-Subscription-Token': BRAVE_API_KEY
    },
    timeout: 10000
  });

  // Maintain the same return structure as the original code
  return { response: response.data };
}