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

# Stop an agent

> Stop an agent while it works on a conversation.



## OpenAPI

````yaml api-reference/openapi.yaml POST /v1/responses/{response_id}/cancel
openapi: 3.0.3
info:
  title: QX API
  version: '1.0'
  description: >-
    Run what you build in QX from your own code. Message agents, execute flows
    and grids, and read their results.
servers:
  - url: https://api.qxlabs.com
security:
  - bearerAuth: []
tags:
  - name: Agents
    description: >-
      Message agents through OpenAI's Responses API, so OpenAI's SDKs work with
      a QX API key.
  - name: Flows
    description: Execute flows and follow their executions.
  - name: Grids
    description: Execute grids, follow their executions and read their rows.
paths:
  /v1/responses/{response_id}/cancel:
    post:
      tags:
        - Agents
      summary: Stop an agent
      description: >
        Stops the agent working on a response's conversation. What it already
        did stays.

        The call that started the turn ends with status `cancelled`.
      operationId: stopAgent
      parameters:
        - name: response_id
          in: path
          required: true
          schema:
            type: string
          description: The ID of a response of the conversation
          example: resp_8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f_4f1a2b3c4d5e
      responses:
        '200':
          description: The turn was stopped
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  object:
                    type: string
                  status:
                    type: string
                  model:
                    type: string
                    description: The agent the stopped turn ran
                  conversation:
                    type: object
                    properties:
                      id:
                        type: string
                  output:
                    type: array
                    description: >-
                      What the agent did before it stopped, as in a finished
                      response
                    items:
                      $ref: '#/components/schemas/Item'
              example:
                id: resp_8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f_4f1a2b3c4d5e
                object: response
                status: cancelled
                model: builtin:qx_agent
                conversation:
                  id: 8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f
                output: []
        '404':
          description: There's no such response for you
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentsError'
        '409':
          description: No turn is running on the conversation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentsError'
              example:
                error:
                  message: No turn is running on this conversation.
                  type: invalid_request_error
                  param: null
                  code: null
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentsError'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >
            curl -X POST
            https://api.qxlabs.com/v1/responses/resp_8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f_4f1a2b3c4d5e/cancel
            \
              -H "Authorization: Bearer <YOUR_QX_API_KEY>"
        - lang: python
          label: Python
          source: >
            from openai import OpenAI


            client = OpenAI(base_url="https://api.qxlabs.com/v1",
            api_key="<YOUR_QX_API_KEY>")


            stopped =
            client.responses.cancel("resp_8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f_4f1a2b3c4d5e")

            print(stopped.status)
        - lang: typescript
          label: TypeScript
          source: >
            import OpenAI from "openai";


            const client = new OpenAI({ baseURL: "https://api.qxlabs.com/v1",
            apiKey: "<YOUR_QX_API_KEY>" });


            const stopped = await
            client.responses.cancel("resp_8d2c4e6f8a0b1c3d5e7f9a1b3c5d7e9f_4f1a2b3c4d5e");

            console.log(stopped.status);
components:
  schemas:
    Item:
      type: object
      title: Item
      description: >-
        One thing in a turn. `type` says which kind it is, and the other fields
        go with it
      properties:
        type:
          type: string
          enum:
            - reasoning
            - message
            - mcp_call
            - mcp_approval_request
          description: >-
            `reasoning` for the agent's thinking, `message` for a message,
            `mcp_call` for a tool call, `mcp_approval_request` for a call
            waiting for your approval
        id:
          type: string
          description: >-
            An approval request's ID goes back as `approval_request_id` in your
            answer
          example: msg_77c0a1b2c3d4
        status:
          type: string
          enum:
            - in_progress
            - completed
            - failed
            - incomplete
          description: >-
            For reasoning, messages and tool calls. A tool call that failed is
            `failed`, and one that was stopped is `incomplete`
        role:
          type: string
          enum:
            - assistant
            - user
          description: >-
            For messages. `assistant` for the agent's, `user` for yours, which
            only a conversation's items hold
        content:
          type: array
          description: >-
            For messages. The agent's message is an `output_text` part with its
            text and the sources it cites. Your message is an `input_text` part,
            then an `input_file` part per file
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - output_text
                  - input_text
                  - input_file
              text:
                type: string
                description: For `output_text` and `input_text`
              filename:
                type: string
                description: For `input_file`
              annotations:
                type: array
                description: >-
                  For `output_text`. A `url_citation` for each source with a
                  link
                items:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - url_citation
                    url:
                      type: string
                    title:
                      type: string
                    start_index:
                      type: integer
                      description: >-
                        Where the citation's `[n]` marker starts in the text. 0
                        when the text doesn't cite it
                    end_index:
                      type: integer
                      description: Where the marker ends. 0 when the text doesn't cite it
        summary:
          type: array
          description: For reasoning. The thinking as `summary_text` parts
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - summary_text
              text:
                type: string
        server_label:
          type: string
          description: >-
            For tool calls and approval requests. `qx` for one of QX's own
            tools, or the app, like `gmail`
        name:
          type: string
          description: >-
            For tool calls and approval requests. The tool, like `web_search` or
            `GMAIL_SEND_EMAIL`
        arguments:
          type: string
          description: >-
            For tool calls and approval requests, as a JSON object in a string.
            A call to one of QX's own tools shows only the `command`, `query`,
            `url` or `path` it was given, with a command cut to 40 characters,
            and a call to an app's tool shows `{}`. An approval request has the
            call's arguments in full, with the agent's `reason` for it among
            them
          example: '{}'
        output:
          type: string
          nullable: true
          description: For tool calls. Always null, since a tool's result stays in the app
        error:
          type: string
          nullable: true
          description: >-
            For tool calls. The result when the call failed or was stopped, null
            otherwise
        approval_request_id:
          type: string
          nullable: true
          description: >-
            For tool calls. The approval request the call ran after, if it
            needed one
    AgentsError:
      type: object
      description: OpenAI's error shape
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
              nullable: true
            code:
              type: string
              nullable: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Your QX API key. The `X-API-Key` header works too

````

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