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

# Search the Web

> Search the web and optionally scrape results in one call so your product gets answers faster.

<Badge color="blue">1 Credit Per 10 Results</Badge>


## OpenAPI

````yaml POST /web/search
openapi: 3.0.0
info:
  title: Context API
  description: API for retrieving context data from any website
  version: 1.0.0
servers:
  - url: https://api.context.dev/v1
security: []
tags:
  - name: Monitors
    description: >-
      Monitor pages, sitemaps, and extracted website data for exact or semantic
      changes. The change.detected webhook payload is documented by the
      MonitorsChangeDetectedWebhookPayload schema.
paths:
  /web/search:
    post:
      tags:
        - Web Scraping
      summary: Web Search
      description: >-
        Search the web and optionally scrape each result to Markdown in one
        round-trip.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  minLength: 1
                  maxLength: 500
                  description: >-
                    Search query. Accepts natural language as well as
                    Google-style search operators such as `site:`, `-site:`,
                    `inurl:`, `intitle:`, quoted phrases, and `OR`.
                numResults:
                  type: integer
                  minimum: 10
                  maximum: 100
                  default: 10
                  description: >-
                    Number of results to request and return (10–100). Defaults
                    to 10.
                includeDomains:
                  type: array
                  items:
                    type: string
                  description: >-
                    Allowlist — only return results from these domains. Example:
                    ["arxiv.org", "github.com"].
                excludeDomains:
                  type: array
                  items:
                    type: string
                  description: >-
                    Blocklist — drop results from these domains. Example:
                    ["pinterest.com", "reddit.com"].
                freshness:
                  type: string
                  enum:
                    - last_24_hours
                    - last_week
                    - last_month
                    - last_year
                  description: Restrict results to content published within this window.
                country:
                  type: string
                  enum:
                    - af
                    - al
                    - dz
                    - as
                    - ad
                    - ao
                    - ai
                    - aq
                    - ag
                    - ar
                    - am
                    - aw
                    - au
                    - at
                    - az
                    - bs
                    - bh
                    - bd
                    - bb
                    - by
                    - be
                    - bz
                    - bj
                    - bm
                    - bt
                    - bo
                    - ba
                    - bw
                    - bv
                    - br
                    - io
                    - bn
                    - bg
                    - bf
                    - bi
                    - kh
                    - cm
                    - ca
                    - cv
                    - ky
                    - cf
                    - td
                    - cl
                    - cn
                    - cx
                    - cc
                    - co
                    - km
                    - cg
                    - cd
                    - ck
                    - cr
                    - ci
                    - hr
                    - cu
                    - cy
                    - cz
                    - dk
                    - dj
                    - dm
                    - do
                    - ec
                    - eg
                    - sv
                    - gq
                    - er
                    - ee
                    - et
                    - fk
                    - fo
                    - fj
                    - fi
                    - fr
                    - gf
                    - pf
                    - tf
                    - ga
                    - gm
                    - ge
                    - de
                    - gh
                    - gi
                    - gr
                    - gl
                    - gd
                    - gp
                    - gu
                    - gt
                    - gn
                    - gw
                    - gy
                    - ht
                    - hm
                    - va
                    - hn
                    - hk
                    - hu
                    - is
                    - in
                    - id
                    - ir
                    - iq
                    - ie
                    - il
                    - it
                    - jm
                    - jp
                    - jo
                    - kz
                    - ke
                    - ki
                    - kp
                    - kr
                    - kw
                    - kg
                    - la
                    - lv
                    - lb
                    - ls
                    - lr
                    - ly
                    - li
                    - lt
                    - lu
                    - mo
                    - mk
                    - mg
                    - mw
                    - my
                    - mv
                    - ml
                    - mt
                    - mh
                    - mq
                    - mr
                    - mu
                    - yt
                    - mx
                    - fm
                    - md
                    - mc
                    - mn
                    - ms
                    - ma
                    - mz
                    - mm
                    - na
                    - nr
                    - np
                    - nl
                    - an
                    - nc
                    - nz
                    - ni
                    - ne
                    - ng
                    - nu
                    - nf
                    - mp
                    - 'no'
                    - om
                    - pk
                    - pw
                    - ps
                    - pa
                    - pg
                    - py
                    - pe
                    - ph
                    - pn
                    - pl
                    - pt
                    - pr
                    - qa
                    - re
                    - ro
                    - ru
                    - rw
                    - sh
                    - kn
                    - lc
                    - pm
                    - vc
                    - ws
                    - sm
                    - st
                    - sa
                    - sn
                    - rs
                    - sc
                    - sl
                    - sg
                    - sk
                    - si
                    - sb
                    - so
                    - za
                    - gs
                    - es
                    - lk
                    - sd
                    - sr
                    - sj
                    - sz
                    - se
                    - ch
                    - sy
                    - tw
                    - tj
                    - tz
                    - th
                    - tl
                    - tg
                    - tk
                    - to
                    - tt
                    - tn
                    - tr
                    - tm
                    - tc
                    - tv
                    - ug
                    - ua
                    - ae
                    - gb
                    - us
                    - um
                    - uy
                    - uz
                    - vu
                    - ve
                    - vn
                    - vg
                    - vi
                    - wf
                    - eh
                    - ye
                    - zm
                    - zw
                  description: >-
                    Two-letter ISO 3166-1 alpha-2 country code to localize
                    results to a specific country (maps to Google's `gl`
                    parameter). Example: "us", "gb", "de".
                queryFanout:
                  type: boolean
                  description: >-
                    Expand the query into multiple parallel variants for broader
                    recall.
                markdownOptions:
                  type: object
                  additionalProperties: false
                  description: >-
                    Inline Markdown scraping for each result. Set `enabled:
                    true` to activate.
                  properties:
                    enabled:
                      type: boolean
                      default: false
                      description: >-
                        Scrape each result to Markdown. Off by default to keep
                        search cheap and fast.
                    includeLinks:
                      type: boolean
                      default: true
                      description: Keep hyperlinks in the Markdown.
                    includeImages:
                      type: boolean
                      default: false
                      description: Emit image references in the Markdown.
                    shortenBase64Images:
                      type: boolean
                      default: true
                      description: >-
                        Truncate inline base64 image payloads to keep responses
                        small.
                    useMainContentOnly:
                      type: boolean
                      default: false
                      description: >-
                        Strip nav, header, footer, and sidebar — keep only the
                        primary article content.
                    pdf:
                      type: object
                      properties:
                        shouldParse:
                          type: boolean
                          default: true
                          description: >-
                            Parse PDF URLs. When false, PDF results are skipped
                            with WEBSITE_ACCESS_ERROR.
                        start:
                          type: integer
                          minimum: 1
                          description: >-
                            First PDF page to parse (1-based, inclusive).
                            Defaults to page 1.
                        end:
                          type: integer
                          minimum: 1
                          description: >-
                            Last PDF page to parse (1-based, inclusive).
                            Defaults to the final page. Must be >= start.
                      additionalProperties: false
                      default:
                        shouldParse: true
                      description: >-
                        PDF handling. Use start/end to bound text extraction and
                        OCR to a page range.
                    includeFrames:
                      type: boolean
                      default: false
                      description: Render iframe contents into the Markdown.
                    maxAgeMs:
                      type: integer
                      minimum: 0
                      maximum: 2592000000
                      default: 86400000
                      description: >-
                        Cache TTL in ms for scraped Markdown keyed by URL +
                        options. Default 1 day, max 30 days. Set to 0 to force a
                        fresh scrape.
                    waitForMs:
                      type: integer
                      minimum: 0
                      maximum: 30000
                      description: >-
                        Extra wait after page load before rendering, in ms
                        (0–30000). Useful for JS-heavy pages.
                    timeoutMS:
                      $ref: '#/components/schemas/TimeoutMS'
                timeoutMS:
                  $ref: '#/components/schemas/TimeoutMS'
              required:
                - query
              additionalProperties: false
      responses:
        '200':
          description: Search succeeded. Results are ordered by relevance.
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        url:
                          type: string
                          description: Canonical result URL.
                        title:
                          type: string
                          description: Page title.
                        description:
                          type: string
                          description: Snippet excerpt from the page.
                        relevance:
                          type: string
                          enum:
                            - high
                            - medium
                            - low
                          description: Relevance to the original query.
                        markdown:
                          type: object
                          properties:
                            markdown:
                              type: string
                              nullable: true
                              description: >-
                                GFM Markdown of the page. Null unless
                                markdownOptions.enabled is true and scraping
                                succeeded.
                            code:
                              type: string
                              enum:
                                - SUCCESS
                                - NOT_REQUESTED
                                - TIMEOUT
                                - WEBSITE_ACCESS_ERROR
                                - ERROR
                              description: >-
                                Per-result scrape outcome. Inspect this before
                                reading `markdown`.
                          required:
                            - markdown
                            - code
                          additionalProperties: false
                          description: Markdown scrape status and content for this result.
                      required:
                        - url
                        - title
                        - description
                        - relevance
                        - markdown
                  query:
                    type: string
                    description: >-
                      Echo of the original query (useful when fanout was
                      enabled).
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
                required:
                  - results
                  - query
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message describing the issue
                  error_code:
                    type: string
                    enum:
                      - INPUT_VALIDATION_ERROR
                    description: Error code indicating the type of error
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
                required:
                  - message
                  - error_code
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  error_code:
                    type: string
                    enum:
                      - UNAUTHORIZED
                    description: Error code indicating unauthorized access
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
        '403':
          description: Forbidden - Insufficient permissions or usage limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  error_code:
                    type: string
                    enum:
                      - FORBIDDEN
                      - USAGE_EXCEEDED
                      - DISABLED
                      - INSUFFICIENT_PERMISSIONS
                    description: Error code indicating forbidden access
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
        '408':
          description: Request timeout
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Timeout error message
                  error_code:
                    type: string
                    enum:
                      - REQUEST_TIMEOUT
                    description: Error code indicating request timeout
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                    description: Error code indicating internal server error
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import ContextDev from 'context.dev';

            const client = new ContextDev({
              apiKey: process.env['CONTEXT_DEV_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.web.search({ query: 'x' });

            console.log(response.query);
        - lang: Python
          source: |-
            import os
            from context.dev import ContextDev

            client = ContextDev(
                api_key=os.environ.get("CONTEXT_DEV_API_KEY"),  # This is the default and can be omitted
            )
            response = client.web.search(
                query="x",
            )
            print(response.query)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/context-dot-dev/context-go-sdk\"\n\t\"github.com/context-dot-dev/context-go-sdk/option\"\n)\n\nfunc main() {\n\tclient := contextdev.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Web.Search(context.TODO(), contextdev.WebSearchParams{\n\t\tQuery: \"x\",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Query)\n}\n"
        - lang: Ruby
          source: |-
            require "context_dev"

            context_dev = ContextDev::Client.new(api_key: "My API Key")

            response = context_dev.web.search(query: "x")

            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use ContextDev\Client;

            use ContextDev\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('CONTEXT_DEV_API_KEY') ?: 'My
            API Key');


            try {
              $response = $client->web->search(
                query: 'x',
                country: 'af',
                excludeDomains: ['string'],
                freshness: 'last_24_hours',
                includeDomains: ['string'],
                markdownOptions: [
                  'enabled' => true,
                  'includeFrames' => true,
                  'includeImages' => true,
                  'includeLinks' => true,
                  'maxAgeMs' => 0,
                  'pdf' => ['end' => 1, 'shouldParse' => true, 'start' => 1],
                  'shortenBase64Images' => true,
                  'timeoutMs' => 1000,
                  'useMainContentOnly' => true,
                  'waitForMs' => 0,
                ],
                numResults: 10,
                queryFanout: true,
                timeoutMs: 1000,
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            context-dev web search \
              --api-key 'My API Key' \
              --query x
components:
  schemas:
    TimeoutMS:
      type: integer
      minimum: 1000
      maximum: 300000
      description: >-
        Optional timeout in milliseconds for the request. If the request takes
        longer than this value, it will be aborted with a 408 status code.
        Maximum allowed value is 300000ms (5 minutes).
    KeyMetadata:
      type: object
      description: >-
        Metadata about the API key used for the request. Included in every
        response whenever a valid API key is provided, even when the response
        status is not 200.
      properties:
        credits_consumed:
          type: integer
          description: The number of credits consumed by this request.
        credits_remaining:
          type: integer
          description: >-
            The number of credits remaining for your organization after this
            request.
      required:
        - credits_consumed
        - credits_remaining
  responses:
    RateLimited:
      description: Rate limit exceeded
      headers:
        Retry-After:
          description: Seconds until the per-minute rate limit window resets
          schema:
            type: integer
            minimum: 1
            maximum: 60
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error message
              error_code:
                type: string
                enum:
                  - RATE_LIMITED
                description: Error code indicating the rate limit was exceeded
              key_metadata:
                $ref: '#/components/schemas/KeyMetadata'
            required:
              - message
              - error_code
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````