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

# 兼容调用

> 以 SSE 返回结果。优先将 JSON 对象中的 prompt 作为消息；其他 JSON 值转换成文本，非 JSON 请求按原始文本处理。用户与会话由请求头指定，缺省 user_id 为 agentkit_user，缺省 session_id 为空字符串；建议始终明确提供二者

自动检查并创建会话；应用名称来自服务加载的智能体，无需在请求体提供。支持 `harness.mcp_servers` 作为本次 MCP 覆盖，不应用其他 Harness 覆盖。流开始后的失败通过 error 事件返回

用于只发送文本的兼容客户端。请求体通常为 `{"prompt":"Hello"}`，用户和会话通过 `user_id`、`session_id` 请求头提供；它们不是请求体字段

建议每次明确提供两个请求头，避免缺省值使不同调用落到同一用户或会话命名空间。服务会检查并创建会话，应用名称取自已加载的智能体

<Warning>
  调用会保存会话并执行模型和工具，可能产生费用或外部操作。重新发送相同消息可能再次执行这些操作
</Warning>

响应为 SSE，使用 `curl -N` 持续读取并处理流内 `error`。如需结构化 ADK 消息，使用[流式运行 Harness](/productions/api-reference/preview/zh/harness-runtime/run-sse)


## OpenAPI

````yaml productions/api-reference/openapi/zh/harness-runtime.json POST /invoke
openapi: 3.1.0
info:
  title: Harness Runtime
  version: agentkit-cli 0.54.0 / SDK 0.8.0 / ADK 2.2.0
  description: >-
    AgentKit CLI 0.54.0 部署的 Harness Runtime，基于 VeADK 1.0.8、AgentKit SDK 0.8.0 与
    Google ADK 2.2.0 核验；定时任务另需启用配置
servers:
  - url: http://localhost:8000
    description: 本地服务
security:
  - {}
  - RuntimeBearer: []
tags:
  - name: 服务与应用
  - name: 会话
  - name: 智能体运行
  - name: 制品
  - name: 记忆
  - name: 评测 · 开发服务
  - name: 调试 · 开发服务
  - name: 兼容接口
  - name: Harness 定时任务
paths:
  /invoke:
    post:
      tags:
        - Harness 调用
      summary: 兼容调用
      description: >-
        以 SSE 返回结果。优先将 JSON 对象中的 prompt 作为消息；其他 JSON 值转换成文本，非 JSON
        请求按原始文本处理。用户与会话由请求头指定，缺省 user_id 为 agentkit_user，缺省 session_id
        为空字符串；建议始终明确提供二者


        自动检查并创建会话；应用名称来自服务加载的智能体，无需在请求体提供。支持 `harness.mcp_servers` 作为本次 MCP
        覆盖，不应用其他 Harness 覆盖。流开始后的失败通过 error 事件返回
      operationId: harnessRuntimeInvokeCompatible
      parameters:
        - name: user_id
          in: header
          required: false
          schema:
            type: string
            default: agentkit_user
          example: user-001
        - name: session_id
          in: header
          required: false
          schema:
            type: string
            default: ''
          example: session-001
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - type: object
                  properties:
                    prompt:
                      type: string
                      description: 本次调用的用户消息
                    harness:
                      $ref: '#/components/schemas/HarnessMcpOverrides'
                  additionalProperties: true
                - type: array
                  items: {}
                - type: string
                - type: number
                - type: boolean
                - type: 'null'
            examples:
              prompt:
                value:
                  prompt: Hello
              mcp:
                value:
                  prompt: Hello
                  harness:
                    mcp_servers:
                      - endpoint: https://mcp.example.com/mcp
          text/plain:
            schema:
              type: string
            example: Hello
      responses:
        '200':
          description: SSE 事件流
          content:
            text/event-stream:
              schema:
                type: string
              example: >+
                data:
                {"content":{"parts":[{"text":"Hello"}]},"author":"harness_agent"}

        '400':
          description: 共享 OAuth 请求同时提供 MCP 和其他 Harness 覆盖，或请求不符合接口要求
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    properties:
                      error:
                        type: string
                  - $ref: '#/components/schemas/ApiError'
        '411':
          description: 仅共享 OAuth：必须提供有效 Content-Length
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: CONTENT_LENGTH_REQUIRED
        '413':
          description: 仅共享 OAuth：请求体不得超过 128 KiB
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: REQUEST_TOO_LARGE
components:
  schemas:
    HarnessMcpOverrides:
      type: object
      properties:
        mcp_servers:
          items:
            $ref: '#/components/schemas/McpServerConfig'
          type: array
          title: Mcp Servers
          description: 远程 MCP 服务列表；省略时继承部署配置，提供时整体替换，空数组禁用本次调用的远程 MCP
    ApiError:
      type: object
      required:
        - detail
      properties:
        detail:
          type: string
          description: 错误详情
    McpServerConfig:
      properties:
        protocol:
          type: string
          enum:
            - streamable-http
            - sse
          title: Protocol
          default: streamable-http
          description: MCP 传输协议，默认 streamable-http，也支持 sse
        endpoint:
          type: string
          title: Endpoint
          description: HTTP(S) 服务地址，不允许用户名密码、片段标识或控制字符
        api_key:
          anyOf:
            - type: string
              format: password
              writeOnly: true
            - type: 'null'
          title: Api Key
          description: 发送给 MCP 服务的 Bearer 凭证，可省略；不允许换行，不是 Runtime 访问凭证
      additionalProperties: false
      type: object
      required:
        - endpoint
      title: McpServerConfig
  securitySchemes:
    RuntimeBearer:
      type: http
      scheme: bearer
      description: 本地未配置网关时可不提供；云部署使用 Runtime API Key 或部署要求的用户池 JWT，不能使用模型 API Key

````