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

# 实时 WebSocket 连接

> 建立 WebSocket 连接用于实时对话。

**注意**: 这是一个 WebSocket 端点，需要使用 WebSocket 协议连接。

连接 URL 示例: `wss://api.example.com/v1/realtime?model=gpt-4o-realtime`




## OpenAPI

````yaml /api.json get /v1/realtime
openapi: 3.0.1
info:
  title: TKHub API
  description: TKHub 平台 API 接口文档
  version: 1.0.0
servers:
  - url: https://api.tkhub.ai
    description: 生产环境
  - url: https://api-test.tkhub.ai
    description: 测试环境
security:
  - bearerAuth: []
paths:
  /v1/realtime:
    get:
      tags:
        - Realtime
      summary: 实时 WebSocket 连接
      description: |
        建立 WebSocket 连接用于实时对话。

        **注意**: 这是一个 WebSocket 端点，需要使用 WebSocket 协议连接。

        连接 URL 示例: `wss://api.example.com/v1/realtime?model=gpt-4o-realtime`
      operationId: createRealtimeSession
      parameters:
        - name: model
          in: query
          description: 要使用的模型
          required: false
          schema:
            type: string
            example: gpt-4o-realtime-preview
      responses:
        '101':
          description: WebSocket 协议切换
          headers: {}
        '400':
          description: 请求错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          headers: {}
      deprecated: false
      security:
        - BearerAuth: []
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 错误信息
            type:
              type: string
              description: 错误类型
            param:
              type: string
              description: 相关参数
              nullable: true
            code:
              type: string
              description: 错误代码
              nullable: true
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        使用 Bearer Token 认证。
        格式: `Authorization: Bearer sk-xxxxxx`

````