> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langsearch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LangSearch Web Search API

> Search the web, retrieve useful context, and build with source-backed information.

<div className="ls-hero">
  <div className="ls-kicker">FREE WEB SEARCH API</div>
  <h2>The World Engine<br /><span className="ls-hero-accent">for AGI.</span></h2>
  <p>Bring the world's information into your AI workflows. Search the web, retrieve useful context, and keep the sources.</p>
  <div className="ls-actions"><a className="ls-button" href="#make-your-first-search">Make your first search →</a><a href="/reference/search-api-guide-for-coding-agents">Building with an agent ↗</a></div>

  <div className="ls-arch" aria-hidden="true" />
</div>

LangSearch connects AI applications to information on the web. Send a query and receive structured results with source URLs and search snippets, or full webpage text when requested.

Building with a coding agent? Share the [self-contained integration guide](/reference/search-api-guide-for-coding-agents).

## What you can build

<CardGroup cols={3}>
  <Card title="Grounded answers" icon="messages-square">Give your model search context and source URLs to support its answers.</Card>
  <Card title="Research workflows" icon="search">Gather evidence across sources and refine the next search as you learn.</Card>
  <Card title="Coding agents" icon="terminal">Find relevant documentation and technical explanations for a development task.</Card>
</CardGroup>

## Make your first search

### 1. Get an API key

Open the [Dashboard](https://langsearch.com/dashboard), choose **API keys**, and create a key. Replace `YOUR_LANGSEARCH_API_KEY` below with your key. Run the request from a server or trusted local environment.

### 2. Send a request

Choose cURL, Python, or JavaScript. These examples use standard HTTP clients; no LangSearch-specific SDK is required.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.langsearch.com/v1/web-search \
    -H "Authorization: Bearer YOUR_LANGSEARCH_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "query": "How does a search API help an AI agent?",
      "count": 5,
      "contents": {"text": true},
      "freshness": "noLimit"
    }'
  ```

  ```python Python theme={null}
  import json
  from urllib.request import Request, urlopen

  request = Request(
      "https://api.langsearch.com/v1/web-search",
      data=json.dumps({
          "query": "How does a search API help an AI agent?",
          "count": 5, "contents": {"text": True}, "freshness": "noLimit"
      }).encode(),
      headers={
          "Authorization": "Bearer YOUR_LANGSEARCH_API_KEY",
          "Content-Type": "application/json"
      }
  )
  with urlopen(request, timeout=30) as response:
      result = json.load(response)
  for source in result["data"]["webPages"]["value"]:
      print(source["name"], source["url"])
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.langsearch.com/v1/web-search", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_LANGSEARCH_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: "How does a search API help an AI agent?",
      count: 5, contents: { text: true }, freshness: "noLimit",
    }),
    signal: AbortSignal.timeout(30000),
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const result = await response.json();
  for (const source of result.data.webPages.value) {
    console.log(source.name, source.url);
  }
  ```
</CodeGroup>

### 3. Read the sources

Results are in `data.webPages.value`. Each item represents a source:

| Field           | What it gives you                                  |
| --------------- | -------------------------------------------------- |
| `name`          | Source title                                       |
| `url`           | Source URL to retain for citations                 |
| `snippet`       | Search text when full webpage text is not enabled  |
| `text`          | Full webpage text when enabled; replaces `snippet` |
| `datePublished` | Publication metadata, when available               |

The examples above enable `contents.text`, so read `text` for each source. Omit this option or set it to `false` to use `snippet` instead. Your model can use source text to compose an answer with citations. Text and date fields may be missing; an empty result array is also a valid response.

### Result metadata and missing fields

Preserve result order unless your application has a reason to reorder it.

For context, use `text` in text mode or `snippet` in snippet mode, and keep the source URL even if text is missing. Broaden the query or freshness window when the evidence is insufficient.

## Authentication and API keys

Every request uses the same authentication header:

```http theme={null}
Authorization: Bearer YOUR_LANGSEARCH_API_KEY
```

Create a key in **Dashboard → API keys**, copy it when the full key is shown, and store it securely. Run requests from a server or trusted local tool; do not expose the key in a browser bundle, public repository, or shared configuration file.

To rotate a key, create a replacement, update your application, verify a request, and then delete the old key. All keys on your account share the same allowance.

If you receive `401`, check the `Bearer ` prefix, accidental whitespace, an unchanged placeholder, or a deleted key. MCP uses the same Bearer authentication with its [client-specific configuration](/integrations/mcp).

## Choose what to retrieve

| Your task                  | Starting point                                       |
| -------------------------- | ---------------------------------------------------- |
| A focused factual question | `count: 5`, `contents: { "text": true }`             |
| A source list              | `count: 10`; omit `contents`                         |
| Recent developments        | `contents: { "text": true }`, `freshness: "oneWeek"` |
| A bounded model context    | `contents: { "text": { "max_characters": 3000 } }`   |

`count` defaults to 10 and has a maximum of 50. `contents.text: true` requests full webpage text with a **5000-character limit per result**. An object also enables text: `contents: { "text": { "max_characters": 3000 } }`. The limit must be a positive integer, and you do not need a separate `true` flag. The limit is an upper bound; available text may be shorter.

## Filter by date and domain

`freshness` accepts `noLimit` (default), `oneDay`, `oneWeek`, `oneMonth`, and `oneYear`, plus:

* A specific UTC date: `2026-09-12`.
* An inclusive UTC date range: `2026-09-01..2026-09-13`.

Use valid calendar dates with the start on or before the end. Use `includeDomains` to restrict sources and `excludeDomains` to leave sources out. Domain entries are strings such as `langsearch.com` or `openai.com`; omit the arrays or leave them empty to apply no domain filter.

```json theme={null}
{
  "query": "AI search APIs",
  "count": 10,
  "freshness": "2026-09-01..2026-09-13",
  "includeDomains": ["langsearch.com", "openai.com"],
  "excludeDomains": ["reddit.com"],
  "contents": { "text": { "max_characters": 3000 } }
}
```

Date filtering uses source metadata, not a guarantee that a page was crawled during that window.

For query refinement and choosing the right amount of context, read [Best Practices](/reference/search-best-practices).

## Connect your tools

<CardGroup cols={2}>
  <Card title="MCP" icon="plug" href="/integrations/mcp">Connect Codex, Claude Code, Cursor, VS Code, and other clients to the official hosted server.</Card>
  <Card title="Agent Skill" icon="sparkles" href="/integrations/skill">Give your agent the official installation instructions.</Card>
</CardGroup>

## Next steps

* [Web Search API reference](/api/web-search-api): request fields and interactive playground.
* [Plan & usage](/limits/api-limits): account allowance and automatic resets.
* [Errors & troubleshooting](/api/errors): diagnose failures and decide when to retry.
