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

# Cancel a search

> Cancels a search. A search that hasn't started is removed straight away and its held credits are returned.

A running search can't be stopped instantly. It stops at its next checkpoint and then reports `status: "failed"` with `error: "Search cancelled"`, and the response's `message` says so. If it had already finished searching, it completes normally and is charged. Check [Get a search](/api-reference/search/search-status) for the final state.

Most searches finish in seconds, so this matters mostly for searches with `scrapeOptions`.




## OpenAPI

````yaml DELETE /search/{jobId}
openapi: 3.1.0
info:
  title: Spidra API
  version: 1.0.0
  description: >-
    Public API endpoints for web scraping via Spidra. Authenticate with
    `Authorization: Bearer YOUR_API_KEY`.
servers:
  - url: https://api.spidra.io/api
security:
  - BearerAuth: []
  - ApiKeyAuth: []
paths:
  /search/{jobId}:
    delete:
      tags:
        - Search
      summary: Cancel a search
      description: >
        Cancels a search. A search that hasn't started is removed straight away
        and its held credits are returned.


        A running search can't be stopped instantly. It stops at its next
        checkpoint and then reports `status: "failed"` with `error: "Search
        cancelled"`, and the response's `message` says so. If it had already
        finished searching, it completes normally and is charged. Check [Get a
        search](/api-reference/search/search-status) for the final state.


        Most searches finish in seconds, so this matters mostly for searches
        with `scrapeOptions`.
      parameters:
        - name: jobId
          in: path
          required: true
          description: The `jobId` returned by `POST /search`.
          schema:
            type: string
            format: uuid
          example: 08135670-12ca-442d-a48c-e83f0da437d7
      responses:
        '200':
          description: >-
            The search was cancelled, or, if it was running, cancelling was
            requested.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - cancelled
                  jobId:
                    type: string
                    format: uuid
                    description: The search's ID.
                  message:
                    type: string
                    description: >-
                      Only when the search was already running. Says that it
                      stops at its next checkpoint.
              examples:
                queued:
                  summary: Cancelled before it started
                  value:
                    status: cancelled
                    jobId: 08135670-12ca-442d-a48c-e83f0da437d7
                running:
                  summary: Cancelling requested while running
                  value:
                    status: cancelled
                    jobId: 09130a7c-c861-46b0-b3bd-86e74addff9c
                    message: >-
                      This search was already running, so cancellation was
                      requested. It stops at its next checkpoint and then
                      reports status "failed" with "Search cancelled". If it had
                      already finished searching it completes normally. Check
                      GET /api/search/{jobId} for the final state.
        '400':
          description: The search has already finished, so there's nothing to cancel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                completed:
                  summary: Already completed
                  value:
                    status: error
                    message: Cannot cancel a job that has already completed.
                failed:
                  summary: Already failed
                  value:
                    status: error
                    message: Cannot cancel a job that has already failed.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: >-
            The search belongs to another account, or search isn't turned on for
            your account.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Another account's search
                  value:
                    status: error
                    message: You do not have permission to access this job.
                    code: FORBIDDEN
                not_available:
                  summary: Search not turned on for this account
                  value:
                    status: error
                    message: This feature isn't available on your account yet.
        '404':
          description: >-
            There's no search with this ID, or it finished more than an hour
            ago.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                status: error
                message: Search job not found
                code: JOB_NOT_FOUND
        '500':
          description: The search couldn't be cancelled. Try again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                status: error
                message: Failed to cancel search job
components:
  schemas:
    ErrorResponse:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          description: What went wrong, as a sentence you can show to a person.
        code:
          type: string
          description: >-
            A stable code for the error, when there is one, such as
            `JOB_NOT_FOUND` or `SERVICE_BUSY`. Branch on this rather than on
            `message`.
        errors:
          description: >-
            On validation errors (`422`), every problem with the request.
            Scrape, batch, crawl, map and search return a list of sentences.
            Templates, presets and monitors return `{ field, message }` objects.
          oneOf:
            - type: array
              items:
                type: string
            - type: array
              items:
                type: object
                properties:
                  field:
                    type: string
                  message:
                    type: string
        retry_after:
          type: integer
          description: >-
            On `503 SERVICE_BUSY`, how many seconds to wait before sending the
            request again.
  responses:
    Unauthorized:
      description: The API key is missing, wrong, or turned off.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missing:
              summary: No key sent
              value:
                status: error
                message: Missing authentication
            invalid:
              summary: Wrong or turned-off key
              value:
                status: error
                message: Invalid token or API key
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.