> ## 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.

# Create a background run

> Start a new run and return its record while execution continues. Use run_id to query status or subscribe to its stream. This is an alternative to stream or wait; do not call all three for the same message.



## OpenAPI

````yaml /api/openapi.sdk.json post /api/ai/threads/{thread_id}/runs
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:
    post:
      tags:
        - Runs
      summary: Create a background run
      description: >-
        Start a new run and return its record while execution continues. Use
        run_id to query status or subscribe to its stream. This is an
        alternative to stream or wait; do not call all three for the same
        message.
      operationId: create_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:
                $ref: '#/components/schemas/Run'
              example:
                run_id: 33333333-3333-4333-8333-333333333333
                thread_id: 11111111-1111-4111-8111-111111111111
                assistant_id: 22222222-2222-4222-8222-222222222222
                status: running
                created_at: '2026-10-12T00:00:00Z'
                updated_at: '2026-10-12T00:00:00Z'
                metadata: {}
        '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
    Run:
      type: object
      properties:
        run_id:
          type: string
        thread_id:
          type: string
        assistant_id:
          type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        status:
          type: string
          description: >-
            Execution status. Check the status and metadata.agentRun.error; HTTP
            success is not task success.
        metadata:
          type: object
          properties:
            agentRun:
              type: object
              additionalProperties: true
          additionalProperties: true
      required:
        - run_id
        - thread_id
        - status
    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.