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

# Send Event

> Send an event to a running task. This is used for:

- **Session actions**: `run_task`, `goto`, `extract`, `evaluate_js`, `close`
- **Custom tool responses**: Responding to tool calls from the agent

The SDK handles this automatically when using `session.run_task()`, `session.goto()`, etc.



## OpenAPI

````yaml /api-reference/openapi.json post /task/{task_id}/event
openapi: 3.1.0
info:
  title: Smooth
  version: 0.4.1
  description: >-
    # Introduction


    The Smooth API allows for programmatic browser automation and task
    execution. You can run simple one-shot tasks, or create interactive browser
    sessions for multi-step workflows.


    This documentation provides a guide to using the API directly, as well as
    through our Python SDK.


    # Authentication


    To use the API, you need an API key. The API key must be sent in the
    `apikey` header with every request.


    Example: `apikey: YOUR_API_KEY`


    If you are using the Python SDK, you can provide the API key in two ways:


    1.  **Directly in the client constructor**:

        ```python
        from smooth import SmoothClient
        client = SmoothClient(api_key="YOUR_API_KEY")
        ```

    2.  **As an environment variable**:
        Set the `CIRCLEMIND_API_KEY` environment variable, and the client will automatically use it.

        ```bash
        export CIRCLEMIND_API_KEY="YOUR_API_KEY"
        ```

    # Python SDK


    The Smooth Python SDK provides a convenient way to interact with the Smooth
    API.


    ## Installation


    You can install the Smooth Python SDK using pip:


    ```bash

    pip install smooth-py

    ```


    ## Features


    *   **Synchronous and Asynchronous Clients**: Choose between `SmoothClient`
    for traditional sequential programming and `SmoothAsyncClient` for
    high-performance asynchronous applications.

    *   **Simple Tasks**: Run one-shot browser automation tasks with
    `client.run()`.

    *   **Session Workflows**: Create browser sessions for multi-step workflows
    with `client.session()`.

    *   **Custom Tools**: Register Python functions that the agent can call
    during execution.


    ## Usage


    ### Simple Task


    Run a one-shot task and wait for the result:


    ```python

    from smooth import SmoothClient


    client = SmoothClient(api_key="YOUR_API_KEY")


    task_handle = client.run(
        task="Go to https://www.google.com and search for 'Smooth SDK'"
    )

    print(f"Task started with ID: {task_handle.id()}")

    print(f"Live view: {task_handle.live_url()}")


    result = task_handle.result()  # Blocks until task is done


    if result.status == 'done':
        print("Task Output:", result.output)
    else:
        print("Task Failed:", result.output)
    ```


    ### Session Workflow


    For multi-step workflows, create a session and run multiple actions:


    ```python

    from smooth import SmoothClient


    client = SmoothClient(api_key="YOUR_API_KEY")


    with client.session(url="https://example.com") as session:
        # Run a task within the session
        result = session.run_task("Search for flights from NYC to LA")
        print(f"Task output: {result.output}")
        
        # Extract structured data
        flights = session.extract(
            schema={"type": "array", "items": {"type": "object", "properties": {"price": {"type": "number"}}}},
            prompt="Extract the first 3 flight prices"
        )
        print(f"Flights: {flights.output}")
        
        # Navigate to a URL
        session.goto("https://example.com/checkout")
        
        # Execute JavaScript
        title = session.evaluate_js("document.title")
        print(f"Page title: {title.output}")
    ```


    ### Asynchronous Client


    For async applications:


    ```python

    import asyncio

    from smooth import SmoothAsyncClient


    async def main():
        async with SmoothAsyncClient(api_key="YOUR_API_KEY") as client:
            task_handle = await client.run(
                task="Go to Github and search for 'smooth-sdk'"
            )
            print(f"Task started with ID: {task_handle.id()}")
            
            result = await task_handle.result()
            print("Task Output:", result.output)

    asyncio.run(main())

    ```
servers:
  - url: https://api.smooth.sh/api/v1
security:
  - APIKeyHeader: []
tags:
  - name: Task
    description: Operations for running and managing browser automation tasks
  - name: Event
    description: >-
      Operations for sending events to running tasks (session actions, custom
      tool responses)
  - name: Profile
    description: >-
      Operations for managing browser profiles (persistent cookies and
      authentication)
  - name: File
    description: Operations for uploading and managing files
  - name: Extension
    description: Operations for managing browser extensions
paths:
  /task/{task_id}/event:
    post:
      tags:
        - Event
      summary: Send Event
      description: >-
        Send an event to a running task. This is used for:


        - **Session actions**: `run_task`, `goto`, `extract`, `evaluate_js`,
        `close`

        - **Custom tool responses**: Responding to tool calls from the agent


        The SDK handles this automatically when using `session.run_task()`,
        `session.goto()`, etc.
      operationId: send_task_event
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            title: Task Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TaskEvent'
            examples:
              run_task:
                summary: Run task in session
                value:
                  name: session_action
                  payload:
                    name: run_task
                    input:
                      task: Search for flights from NYC to LA
                      max_steps: 32
                  id: evt_abc123
              goto:
                summary: Navigate to URL
                value:
                  name: browser_action
                  payload:
                    name: goto
                    input:
                      url: https://example.com
                  id: evt_def456
              extract:
                summary: Extract data
                value:
                  name: browser_action
                  payload:
                    name: extract
                    input:
                      schema:
                        type: array
                        items:
                          type: object
                          properties:
                            title:
                              type: string
                            price:
                              type: number
                      prompt: Extract the first 5 products
                  id: evt_ghi789
              evaluate_js:
                summary: Execute JavaScript
                value:
                  name: browser_action
                  payload:
                    name: evaluate_js
                    input:
                      js: document.title
                  id: evt_jkl012
              close:
                summary: Close session
                value:
                  name: session_action
                  payload:
                    name: close
                  id: evt_mno345
              tool_response:
                summary: Custom tool response
                description: Response to a tool call from the agent
                value:
                  name: tool_call
                  payload:
                    code: 200
                    output:
                      result: Tool execution successful
                  id: evt_pqr678
      responses:
        '200':
          description: Event successfully sent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_TaskEventResponse'
        '400':
          description: Session closed or invalid event.
        '404':
          description: Task not found.
      x-codeSamples:
        - lang: curl
          label: cURL (run_task)
          source: >-
            curl -X POST "https://api.smooth.sh/api/v1/task/YOUR_TASK_ID/event"
            \
                 -H "Content-Type: application/json" \
                 -H "apikey: YOUR_API_KEY" \
                 -d '{
                   "name": "session_action",
                   "payload": {
                     "name": "run_task",
                     "input": {
                       "task": "Search for flights from NYC to LA",
                       "max_steps": 32
                     }
                   },
                   "id": "evt_abc123"
                 }'
        - lang: curl
          label: cURL (extract)
          source: >-
            curl -X POST "https://api.smooth.sh/api/v1/task/YOUR_TASK_ID/event"
            \
                 -H "Content-Type: application/json" \
                 -H "apikey: YOUR_API_KEY" \
                 -d '{
                   "name": "browser_action",
                   "payload": {
                     "name": "extract",
                     "input": {
                       "schema": {"type": "object", "properties": {"title": {"type": "string"}}},
                       "prompt": "Extract the page title"
                     }
                   },
                   "id": "evt_def456"
                 }'
        - lang: python
          label: Python
          source: |-
            # The SDK handles events automatically
            from smooth import SmoothClient

            client = SmoothClient(api_key="YOUR_API_KEY")

            with client.session(url="https://example.com") as session:
                # These methods send events internally
                result = session.run_task("Click the login button")
                data = session.extract(
                    schema={"type": "object", "properties": {"title": {"type": "string"}}},
                    prompt="Extract the page title"
                )
                session.goto("https://example.com/dashboard")
                js_result = session.evaluate_js("document.title")
components:
  schemas:
    TaskEvent:
      type: object
      properties:
        name:
          type: string
          description: 'Event type: `browser_action`, `session_action`, or `tool_call`.'
          title: Name
        payload:
          type: object
          description: >-
            Event payload. For actions: `{name, input}`. For tool responses:
            `{code, output}`.
          title: Payload
        id:
          anyOf:
            - type: string
            - type: 'null'
          description: Unique event ID. Used to match responses to requests.
          title: ID
        timestamp:
          anyOf:
            - type: integer
            - type: 'null'
          description: Unix timestamp of the event.
          title: Timestamp
      required:
        - name
        - payload
      title: TaskEvent
      description: Event model for sending actions to running tasks.
    ApiResponse_TaskEventResponse:
      type: object
      properties:
        r:
          $ref: '#/components/schemas/TaskEventResponse'
      required:
        - r
    TaskEventResponse:
      type: object
      properties:
        id:
          type: string
          description: The ID of the created event.
          title: ID
      required:
        - id
      title: TaskEventResponse
      description: Response model for send event operation.
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: apikey

````