> ## 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 streaming run

> Start a new run and stream its output. Save run_id from the Content-Location response header. For reconnection use `GET /api/ai/threads/{thread_id}/runs/{run_id}/stream`; repeating this POST can execute the task again. The body uses assistant_id and input, not the legacy request/options envelope.



## OpenAPI

````yaml /api/openapi.sdk.json post /api/ai/threads/{thread_id}/runs/stream
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/stream:
    post:
      tags:
        - Runs
      summary: Start a streaming run
      description: >-
        Start a new run and stream its output. Save run_id from the
        Content-Location response header. For reconnection use `GET
        /api/ai/threads/{thread_id}/runs/{run_id}/stream`; repeating this POST
        can execute the task again. The body uses assistant_id and input, not
        the legacy request/options envelope.
      operationId: stream_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: >-
            Schematic SSE frames; real events contain additional fields.
            Preserve each id cursor, ignore colon-prefixed heartbeat comments
            and inspect lifecycle, interruption and error events. HTTP success
            or connection close alone is not task success.
          content:
            text/event-stream:
              schema:
                type: string
              example: >+
                id: 1791763200000-0

                data: {"type":"message","data":"Hello"}


                id: 1791763200001-0

                data:
                {"type":"event","event":"on_conversation_end","data":{"status":"idle","error":null}}

          headers:
            Content-Location:
              description: Run resource path; the final path segment is run_id.
              schema:
                type: string
              example: >-
                /api/ai/threads/11111111-1111-4111-8111-111111111111/runs/33333333-3333-4333-8333-333333333333
        '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.