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

# Run Synchronously

> Run a runnable synchronously

Run a runnable synchronously and wait for its completion. The request will block until the runnable finishes execution or reaches a timeout.


## OpenAPI

````yaml POST /v1/runnable/{id}/runs?mode=sync
openapi: 3.1.0
info:
  title: re-factor API Reference
  version: 1.0.0
  description: API specification for re-factor system based on schema definitions
servers: []
security:
  - BearerAuth: []
paths:
  /v1/runnable/{id}/runs?mode=sync:
    post:
      summary: Run a runnable synchronously
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                resources:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        description: Name of the resource
                      resource:
                        oneOf:
                          - type: object
                            required:
                              - id
                            properties:
                              id:
                                type: string
                                format: uuid
                                description: >-
                                  The pre-existing ID of the resource, if you've
                                  already created it.
                          - $ref: '#/components/schemas/ResourceCreate'
                        description: >-
                          Resource to use under the `name` key for the run. Can
                          be a string ID or a full resource object.
                  description: Resources to embed within the runtime
                timeout_seconds:
                  type: integer
                  description: >-
                    Timeout in seconds. If null or less than 1, no timeout is
                    set.
                telemetry_strategy:
                  type: string
                  enum:
                    - disable
                    - default
                    - force
                  default: default
                  description: >-
                    Telemetry strategy to use for the run. `disable` will
                    disable telemetry, `force` will force telemetry, and
                    `default` will use the runnable's default telemetry
                    strategy.
      responses:
        '200':
          description: Synchronous invocation result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunState'
components:
  schemas:
    ResourceCreate:
      type: object
      required:
        - name
        - directory_path
      properties:
        content:
          type: string
          description: >-
            The file to upload. This can be provided instead of `uri`. It should
            be a base64-encoded string of the format
            `data:<MIME_TYPE>;base64,<BASE64_ENCODED_CONTENT>`.
        uri:
          type: string
          format: uri
          description: >-
            The URI of the file to upload. This can be provided instead of
            `content`.
        name:
          type: string
          description: Name of the resource
        tags:
          type: array
          items:
            type: string
          description: Tags for the resource
        directory_path:
          type: string
          description: Path to the directory where the resource should be stored
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata for the resource
    RunState:
      type: object
      required:
        - id
        - account_id
        - status
        - created_at
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier for the run
        account_id:
          type: string
          description: ID of the account that owns this run
        parent_run_id:
          type: string
          format: uuid
          nullable: true
          description: ID of the parent run if this is a child run
        runnable_id:
          type: string
          format: uuid
          nullable: true
          description: ID of the runnable that was executed
        telemetry_span_id:
          type: string
          nullable: true
          description: Telemetry span ID for tracing
        experiment_id:
          type: string
          format: uuid
          nullable: true
          description: ID of the experiment this run belongs to
        experiment_candidate_id:
          type: string
          nullable: true
          description: ID of the experiment candidate this run represents
        status:
          type: string
          enum:
            - running
            - completed
            - failed
            - cancelled
            - timeout
            - waiting
          description: Current status of the run
        state:
          type: object
          nullable: true
          additionalProperties: true
          description: Current state of the run
        created_by:
          type: string
          nullable: true
          description: ID of the user who created the run
        created_at:
          type: string
          format: date-time
          description: When the run was created
        completed_at:
          type: string
          format: date-time
          nullable: true
          description: >-
            When the run completed (for completed, failed, cancelled, or timeout
            status)
        total_input_tokens:
          type: integer
          nullable: true
          description: Total number of input tokens used
        total_cached_tokens:
          type: integer
          nullable: true
          description: Total number of cached tokens used
        total_output_tokens:
          type: integer
          nullable: true
          description: Total number of output tokens generated
        total_token_cost_usd:
          type: number
          nullable: true
          description: Total cost of the run in USD
        failed_at:
          type: string
          format: date-time
          nullable: true
          description: When the run failed (for failed status)
        result:
          $ref: '#/components/schemas/RunResult'
          nullable: true
          description: >-
            Result of the run. If the run has not yet completed, this will be
            partially populated and is subject to change over time. This may be
            null if the run has yet to generate any output.
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          description: Additional metadata about the run
    RunResult:
      type: object
      properties:
        id:
          type: string
          description: >-
            The id of the run. This can be used to query the status of the run
            or fetch its output.
        outputs:
          type: object
          additionalProperties: true
          description: >-
            The outputs of the run. This is a map of output names, defined
            within the runnable configuration, to output values.
        metadata:
          type: object
          additionalProperties: true
          description: The metadata of the run. This is a map of arbitrary keys to values.
        usage:
          type: array
          items:
            $ref: '#/components/schemas/ModelUsage'
        error:
          type: object
          description: The error that occurred during the run, if any.
          properties:
            message:
              type: string
              description: The error message
            code:
              type: string
              description: The error code
          required:
            - message
      required:
        - id
    ModelUsage:
      type: object
      properties:
        provider:
          type: string
          description: The provider of the model
        model:
          type: string
          description: The name of the model
        cached_tokens:
          type: integer
          description: The number of cached tokens used
        prompt_tokens:
          type: integer
          description: The number of prompt tokens used
        completion_tokens:
          type: integer
          description: The number of completion tokens used
      required:
        - provider
        - model
        - cached_tokens
        - prompt_tokens
        - completion_tokens
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````