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

# Start a run and wait

> Start a new run and return accumulated plain text when its stream completes. The current response is `{"role":"ai","content":"..."}`, not a Run record or a full graph state. This does not wait on an existing run_id. Use streaming for interruption and detailed progress handling.



## OpenAPI

````yaml /api/openapi.sdk.json post /api/ai/threads/{thread_id}/runs/wait
openapi: 3.0.3
info:
  title: XpertAI SDK HTTP API
  version: 1.0.0
  description: >-
    Current HTTP endpoints used by the SDK guide. Authenticate with a
    server-side API Key using Authorization: Bearer <API_KEY> or x-api-key.
    These endpoints do not require ChatKit. The reference covers the guide
    examples, not every method exported by the SDK. Check deployment support
    before using additional fields.
servers:
  - url: https://api.xpertai.cn
    description: XpertAI API. Replace with your own API origin for private deployments.
security:
  - ApiKeyBearer: []
  - ApiKeyHeader: []
tags:
  - name: Assistants
  - name: Threads
  - name: Runs
  - name: Contexts
  - name: Store
paths:
  /api/ai/threads/{thread_id}/runs/wait:
    post:
      tags:
        - Runs
      summary: Start a run and wait
      description: >-
        Start a new run and return accumulated plain text when its stream
        completes. The current response is `{"role":"ai","content":"..."}`, not
        a Run record or a full graph state. This does not wait on an existing
        run_id. Use streaming for interruption and detailed progress handling.
      operationId: wait_run
      parameters:
        - name: thread_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunRequest'
            example:
              assistant_id: 22222222-2222-4222-8222-222222222222
              input:
                action: send
                message:
                  input:
                    input: Hello, introduce yourself briefly.
      responses:
        '201':
          description: Successful response.
          content:
            application/json:
              schema:
                type: object
                properties:
                  role:
                    type: string
                    enum:
                      - ai
                  content:
                    type: string
                required:
                  - role
                  - content
              example:
                role: ai
                content: Hello
        '400':
          description: Invalid input, identifier mismatch or invalid operation state.
        '401':
          description: Missing or invalid API Key.
        '403':
          description: The caller cannot access the requested resource.
        '404':
          description: Resource not found or unavailable to the caller.
components:
  schemas:
    RunRequest:
      type: object
      properties:
        assistant_id:
          type: string
          description: >-
            Published agent ID. HTTP uses assistant_id; the SDK accepts
            assistantId as a method argument.
        input:
          oneOf:
            - $ref: '#/components/schemas/SendInput'
            - $ref: '#/components/schemas/ResumeInput'
            - $ref: '#/components/schemas/RetryInput'
            - $ref: '#/components/schemas/FollowUpInput'
          discriminator:
            propertyName: action
            mapping:
              send: '#/components/schemas/SendInput'
              retry: '#/components/schemas/RetryInput'
              resume: '#/components/schemas/ResumeInput'
              follow_up: '#/components/schemas/FollowUpInput'
          description: >-
            Chat action payload. Examples show send; retry, resume and follow_up
            require the appropriate execution state and access.
        context:
          type: object
          additionalProperties: true
          description: >-
            Optional runtime context. Use only fields supported by your deployed
            agent.
      required:
        - assistant_id
        - input
    SendInput:
      type: object
      properties:
        action:
          type: string
          enum:
            - send
        conversationId:
          type: string
          description: >-
            If supplied, must match the conversation owning the URL thread. Read
            metadata.conversation_id from the thread response.
        message:
          $ref: '#/components/schemas/Message'
        state:
          type: object
          additionalProperties: true
        projectId:
          type: string
        environmentId:
          type: string
        sandboxEnvironmentId:
          type: string
      required:
        - action
        - message
    ResumeInput:
      type: object
      properties:
        action:
          type: string
          enum:
            - resume
        conversationId:
          type: string
          description: >-
            If supplied, must match the conversation owning the URL thread. Read
            metadata.conversation_id from the thread response.
        target:
          $ref: '#/components/schemas/Target'
        decision:
          type: object
          properties:
            type:
              type: string
              enum:
                - confirm
                - reject
            payload: {}
          required:
            - type
        patch:
          type: object
          properties:
            agentKey:
              type: string
            toolCalls:
              type: array
              items: {}
            update: {}
        state:
          type: object
          additionalProperties: true
      required:
        - action
        - target
        - decision
    RetryInput:
      type: object
      properties:
        action:
          type: string
          enum:
            - retry
        conversationId:
          type: string
          description: >-
            If supplied, must match the conversation owning the URL thread. Read
            metadata.conversation_id from the thread response.
        source:
          $ref: '#/components/schemas/Target'
        environmentId:
          type: string
        sandboxEnvironmentId:
          type: string
      required:
        - action
        - source
    FollowUpInput:
      type: object
      properties:
        action:
          type: string
          enum:
            - follow_up
        conversationId:
          type: string
          description: >-
            If supplied, must match the conversation owning the URL thread. Read
            metadata.conversation_id from the thread response.
        mode:
          type: string
          enum:
            - queue
            - steer
        message:
          $ref: '#/components/schemas/Message'
        target:
          $ref: '#/components/schemas/Target'
        state:
          type: object
          additionalProperties: true
      required:
        - action
        - mode
        - message
    Message:
      type: object
      properties:
        clientMessageId:
          type: string
          description: >-
            Caller message identifier; it is not a server-side idempotency
            guarantee.
        input:
          type: object
          properties:
            input:
              type: string
              description: User text. Additional inputs depend on the agent definition.
            files:
              type: array
              items:
                $ref: '#/components/schemas/AgentFile'
          additionalProperties: true
      required:
        - input
    Target:
      type: object
      properties:
        aiMessageId:
          type: string
        executionId:
          type: string
      description: >-
        Use identifiers returned by the original execution or interruption; do
        not invent target IDs.
    AgentFile:
      type: object
      properties:
        id:
          type: string
          description: FileAsset ID. Pass the returned handle in message.input.files.
        fileId:
          type: string
        storageFileId:
          type: string
          description: >-
            StorageFile ID for knowledgebase document associations; do not
            substitute the FileAsset ID.
        url:
          type: string
        originalName:
          type: string
        size:
          type: integer
        mimeType:
          type: string
        status:
          type: string
        parseStatus:
          type: string
        parseMode:
          type: string
        purpose:
          type: string
      required:
        - id
  securitySchemes:
    ApiKeyBearer:
      type: http
      scheme: bearer
      description: Server-side API Key; do not expose it in browser code.
    ApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key

````

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