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

# Save Realtime Session

> Batch save realtime voice session from live-stream WebSocket.

Authentication: MD5 hash of "master:" + botId

This endpoint accepts a batch of messages from a realtime voice conversation
and saves them to the database with proper session and message tracking.



## OpenAPI

````yaml https://api.gbase.ai/openapi-redoc.json post /v1/robots/{ai_id}/realtime-session/save
openapi: 3.1.0
info:
  title: GBase
  description: >
    # Introduce

    This API document can help you understand GBase more deeply. 

    You can train your own AI directly through the interface of this document.



    ##  Authentication


    Home page: [https://gbase.ai](https://gbase.ai)


    Huggingface:
    [https://huggingface.co/gptbase](https://huggingface.co/gptbase)


    The GBase API uses API keys for authentication. Visit your API Keys page to
    retrieve the API key you'll use in your requests.


    Remember that your API key is a secret! Do not share it with others or
    expose it in any client-side code (browsers, apps). 

    Production requests must be routed through your own backend server where
    your API key can be securely loaded from an environment variable or key
    management service.


    All API requests should include your API key in an Authorization HTTP header
    as follows:


    Parameter name: Authorization


    Value: Bearer [YOUR_API_KEY](https://admin.gbase.ai/keys)


    ```

    Authorization: Bearer YOUR_API_KEY

    ```


    ## Use steps

    1.Fill in your API keys.


    2.You can create an AI by using either the API interface or the
    administrative backend. Once created, the AI will generate an ID which will
    be required for the subsequent steps.


    3.Use the generated ID to call the file upload interface.


    4.After uploading the file, you can use the question interface to inquire
    about it.
  version: 0.0.1
servers:
  - url: https://api.gbase.ai
security: []
paths:
  /v1/robots/{ai_id}/realtime-session/save:
    post:
      tags:
        - Question
      summary: Save Realtime Session
      description: >-
        Batch save realtime voice session from live-stream WebSocket.


        Authentication: MD5 hash of "master:" + botId


        This endpoint accepts a batch of messages from a realtime voice
        conversation

        and saves them to the database with proper session and message tracking.
      operationId: save_realtime_session_v1_robots__ai_id__realtime_session_save_post
      parameters:
        - required: true
          schema:
            type: string
            title: Ai Id
          name: ai_id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RealtimeSessionSaveIn'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RealtimeSessionSaveOut'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    RealtimeSessionSaveIn:
      properties:
        session_id:
          type: string
          maxLength: 100
          title: Session Id
        messages:
          items:
            $ref: '#/components/schemas/RealtimeMessageIn'
          type: array
          title: Messages
        metadata:
          type: object
          title: Metadata
          default: {}
        usage:
          $ref: '#/components/schemas/RealtimeUsageIn'
        tool_usage:
          $ref: '#/components/schemas/RealtimeToolUsageIn'
        logs:
          items:
            $ref: '#/components/schemas/RealtimeLogEntryIn'
          type: array
          title: Logs
      type: object
      required:
        - session_id
        - messages
      title: RealtimeSessionSaveIn
    RealtimeSessionSaveOut:
      properties:
        success:
          type: boolean
          title: Success
        session_id:
          type: string
          title: Session Id
        messages_saved:
          type: integer
          title: Messages Saved
        backend_session_id:
          type: string
          title: Backend Session Id
      type: object
      required:
        - success
        - session_id
        - messages_saved
        - backend_session_id
      title: RealtimeSessionSaveOut
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    RealtimeMessageIn:
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          title: Role
        content:
          type: string
          title: Content
        timestamp:
          type: string
          title: Timestamp
        message_type:
          type: string
          enum:
            - audio_transcription
            - text
          title: Message Type
        tool_calls:
          items:
            type: object
          type: array
          title: Tool Calls
      type: object
      required:
        - role
        - content
        - timestamp
        - message_type
      title: RealtimeMessageIn
    RealtimeUsageIn:
      properties:
        turn_count:
          type: integer
          title: Turn Count
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        input_tokens:
          type: integer
          title: Input Tokens
          default: 0
        output_tokens:
          type: integer
          title: Output Tokens
          default: 0
        input_token_details:
          $ref: '#/components/schemas/RealtimeTokenDetailsIn'
        cached_tokens_details:
          $ref: '#/components/schemas/RealtimeTokenDetailsIn'
        output_token_details:
          $ref: '#/components/schemas/RealtimeTokenDetailsIn'
        turns:
          items:
            $ref: '#/components/schemas/RealtimeTurnUsageIn'
          type: array
          title: Turns
          default: []
      type: object
      title: RealtimeUsageIn
    RealtimeToolUsageIn:
      properties:
        call_count:
          type: integer
          title: Call Count
          default: 0
        total_prompt_tokens:
          type: integer
          title: Total Prompt Tokens
          default: 0
        total_completion_tokens:
          type: integer
          title: Total Completion Tokens
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        calls:
          items:
            $ref: '#/components/schemas/RealtimeToolCallUsageIn'
          type: array
          title: Calls
          default: []
      type: object
      title: RealtimeToolUsageIn
      description: Realtime 会话级 tool LLM 用量聚合
    RealtimeLogEntryIn:
      properties:
        timestamp:
          type: string
          title: Timestamp
          default: ''
        level:
          type: string
          title: Level
          default: log
        category:
          type: string
          title: Category
          default: ''
        message:
          type: string
          title: Message
          default: ''
        data:
          title: Data
      type: object
      title: RealtimeLogEntryIn
      description: 前端上报的 Realtime 日志条目
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    RealtimeTokenDetailsIn:
      properties:
        text_tokens:
          type: integer
          title: Text Tokens
          default: 0
        audio_tokens:
          type: integer
          title: Audio Tokens
          default: 0
        cached_tokens:
          type: integer
          title: Cached Tokens
          default: 0
      type: object
      title: RealtimeTokenDetailsIn
    RealtimeTurnUsageIn:
      properties:
        turn_index:
          type: integer
          title: Turn Index
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        input_tokens:
          type: integer
          title: Input Tokens
          default: 0
        output_tokens:
          type: integer
          title: Output Tokens
          default: 0
        input_text_tokens:
          type: integer
          title: Input Text Tokens
          default: 0
        input_audio_tokens:
          type: integer
          title: Input Audio Tokens
          default: 0
        cached_tokens:
          type: integer
          title: Cached Tokens
          default: 0
        cached_text_tokens:
          type: integer
          title: Cached Text Tokens
          default: 0
        cached_audio_tokens:
          type: integer
          title: Cached Audio Tokens
          default: 0
        output_text_tokens:
          type: integer
          title: Output Text Tokens
          default: 0
        output_audio_tokens:
          type: integer
          title: Output Audio Tokens
          default: 0
        duration_ms:
          type: integer
          title: Duration Ms
          default: 0
        timestamp:
          type: integer
          title: Timestamp
          default: 0
        latency_ms:
          type: integer
          title: Latency Ms
        latency_tool_call_count:
          type: integer
          title: Latency Tool Call Count
          default: 0
      type: object
      required:
        - turn_index
      title: RealtimeTurnUsageIn
    RealtimeToolCallUsageIn:
      properties:
        turn_index:
          type: integer
          title: Turn Index
          default: 0
        tool_name:
          type: string
          title: Tool Name
          default: ''
        model:
          type: string
          title: Model
        prompt_tokens:
          type: integer
          title: Prompt Tokens
          default: 0
        completion_tokens:
          type: integer
          title: Completion Tokens
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        timestamp:
          type: integer
          title: Timestamp
          default: 0
      type: object
      title: RealtimeToolCallUsageIn
      description: Realtime 会话中单次工具调用产生的文本 LLM 用量（reasoning agent 等）
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````