## cURL

```bash
curl --location --request POST https://api.writer.com/v1/tools/web-search \
 --header "Authorization: Bearer <token>" \
 --header "Content-Type: application/json" \
--data-raw '{"query":"How do I get an API key for the Writer API?","include_domains":["dev.writer.com"]}'
```

## Python Code

```python
import requests

url = "https://api.writer.com/v1/tools/web-search"

payload = {
    "query": "How do I get an API key for the Writer API?",
    "include_domains": ["dev.writer.com"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## JavaScript Code

```javascript
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    query: 'How do I get an API key for the Writer API?',
    include_domains: ['dev.writer.com']
  })
};

fetch('https://api.writer.com/v1/tools/web-search', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

## Response

```json
{
  "query": "How do I get an API key for the Writer API?",
  "answer": "To get an API key for the Writer API, you need to create one in the AI Studio. Here's how to do it:\n\n1. Go to the AI Studio home page.\n2. Click on \"API Keys\" in the navigation menu.\n \nOnce you've created your API key, you can use it to make API calls. It's recommended to set the API key as an environment variable named `WRITER_API_KEY` for easier access. \n\nFor example, you can store it in a `.env` file and then initialize the Writer client, which will automatically look for the `WRITER_API_KEY` environment variable.",
  "sources": [
    {
      "url": "https://dev.writer.com/home/sdks",
      "raw_content": null
    },
    {
      "url": "https://dev.writer.com/api-guides/api-reference/application-api/applications",
      "raw_content": null
    },
    {
      "url": "https://dev.writer.com/api-reference/api-keys",
      "raw_content": null
    },
    {
      "url": "https://dev.writer.com/home/quickstart",
      "raw_content": null
    },
    {
      "url": "https://dev.writer.com/framework/chat-assistant",
      "raw_content": null
    }
  ]
}
```

### Deprecation Notice
The web search API endpoint at `/v1/tools/web-search` is deprecated and will be removed on **December 22, 2025**. Migration path: Use the web search tool in chat completions to perform web searches during conversations. The web search tool provides the same search capabilities within a chat completion workflow.

### Authorizations
Authorization\nstring\nheader\nrequired\nBearer authentication header of the form `Bearer <token>` where `<token>` is your Writer API key.

### Body
- **query**: string - The search query.
- **topic**: enum<string> - default: general. The search topic category. Use `news` for current events.
- **search_depth**: enum<string> - default: basic. Controls search comprehensiveness.
- **max_results**: integer<int32> - Limits the number of search results returned. Cannot exceed 20 sources.

### Response
200 - application/json
Successful response.
