> ## 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.

# Web Search

> Search the web and optionally scrape each result to Markdown in one round-trip.

<Badge color="blue">1 Credit Per Result</Badge>


## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/context.dev/openapi.documented.yml 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: []
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: Natural-language search query.
                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.
                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: 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

````