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

# Run a task

> <p>Execute a task that has already been created. By default the call blocks until the run finishes. Pass <code>async: true</code> to return immediately, in which case you should poll <code>GET /runs</code> to retrieve the result once it's ready.</p>



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/indices/openapi.documented.yml post /v1beta/runs
openapi: 3.1.0
info:
  title: Indices API
  description: 'The Indices REST API. See docs for details: https://docs.indices.io'
  version: 0.0.1
servers:
  - url: https://api.indices.io
security:
  - ApiKeyAuth: []
tags:
  - name: Tasks
    description: Create a task to repeatedly perform an action on an external website.
  - name: Runs
    description: Execute a task.
  - name: Secrets
    description: Manage secrets like login credentials and API keys.
paths:
  /v1beta/runs:
    post:
      tags:
        - Runs
      summary: Run a task
      description: >-
        <p>Execute a task that has already been created. By default the call
        blocks until the run finishes. Pass <code>async: true</code> to return
        immediately, in which case you should poll <code>GET /runs</code> to
        retrieve the result once it's ready.</p>
      operationId: createRun
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRunRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Run'
        '202':
          description: >-
            Async run accepted; poll `get /runs` until it reaches a terminal
            status.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Run'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Indices from 'indicesio';

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

            const run = await client.runs.run({ task_id: 'task_id' });

            console.log(run.id);
        - lang: Python
          source: |-
            import os
            from indices import Indices

            client = Indices(
                api_key=os.environ.get("INDICES_API_KEY"),  # This is the default and can be omitted
            )
            run = client.runs.run(
                task_id="task_id",
            )
            print(run.id)
components:
  schemas:
    CreateRunRequest:
      properties:
        task_id:
          type: string
          description: ID of the task to execute.
        arguments:
          additionalProperties: true
          type: object
          description: >-
            Arguments to pass to the task. Optional if the task does not require
            any arguments.
        secret_bindings:
          additionalProperties:
            type: string
          type: object
          description: >-
            Mapping of secret slot names to secret IDs. Each slot defined in the
            task's required_secrets must be mapped to a user-owned secret.
        async:
          type: boolean
          description: >-
            When true, return immediately with a pending run; poll retrieveRun
            for the result.
          default: false
        max_timeout_s:
          type: integer
          maximum: 3600
          minimum: 1
          description: Maximum execution time in seconds before the run is timed out.
          default: 300
      type: object
      required:
        - task_id
      title: CreateRunRequest
    Run:
      properties:
        id:
          type: string
          description: Unique identifier for the object.
        task_id:
          type: string
          description: ID of the task executed in this run.
        arguments:
          additionalProperties: true
          type: object
          description: Arguments in this run for the task's input parameters.
        secret_bindings:
          additionalProperties:
            type: string
          type: object
          description: >-
            Secrets to use for this run. This dict must be a mapping of secret
            slot names to secret IDs.
        status:
          $ref: '#/components/schemas/RunStatus'
          description: >-
            Lifecycle status of the run: `pending`, `running`, `success`,
            `failed`, `timed_out`, `result_too_large`, or `internal_error`.
        result_json:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Execution result of the run. In JSON, matching the task's output
            schema.
        has_logs:
          type: boolean
          description: Whether the run has associated logs
        created_at:
          type: string
          format: date-time
          description: Timestamp when the object was created.
        finished_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: Timestamp when the object was last updated.
      type: object
      required:
        - id
        - task_id
        - arguments
        - status
        - result_json
        - has_logs
        - created_at
        - finished_at
      title: Run
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    RunStatus:
      type: string
      enum:
        - pending
        - running
        - success
        - failed
        - timed_out
        - result_too_large
        - internal_error
      title: RunStatus
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Enter your API key as the bearer token. Set header: `Authorization` to
        `Bearer <api_key>`

````