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

# Create a new debug chat session



## OpenAPI

````yaml api-reference/data/openapi.json POST /v1/agents/{agentId}/debug-chat
openapi: 3.1.0
info:
  title: Data API
  version: 1.0.9
  description: Query conversations, recordings, annotations, notes, and debug chat.
servers:
  - url: https://api.us.poly.ai
  - url: https://api.eu.poly.ai
  - url: https://api.uk.poly.ai
  - url: https://api.studio.poly.ai
security:
  - polyApiKey: []
paths:
  /v1/agents/{agentId}/debug-chat:
    parameters:
      - name: agentId
        in: path
        required: true
        schema:
          type: string
    post:
      tags:
        - Debug Chat
      summary: Create a new debug chat session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDebugChatBody'
      responses:
        '201':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DebugChatResponse'
        '400':
          description: Validation error
        '401':
          description: Unauthorized – missing or invalid API key
        '403':
          description: Forbidden – insufficient permissions
components:
  schemas:
    CreateDebugChatBody:
      description: |-
        Starting parameters for a debug chat session: which agent variant,
        which language codes, and which environment to run in.
      type: object
      properties:
        clientEnv:
          description: Client environment (sandbox, pre-release, live)
          type: string
        asrLangCode:
          description: ASR language code (e.g. en-US). Defaults to server config.
          type: string
        ttsLangCode:
          description: TTS language code (e.g. en-US). Defaults to server config.
          type: string
        conversationId:
          description: Custom conversation ID. Auto-generated if omitted.
          type: string
        variantId:
          description: Variant ID to use
          type: string
        channel:
          description: Channel type (e.g. chat.polyai)
          type: string
        integrationAttributes:
          description: >-
            Custom attributes accessible via conv.integration_attributes in
            project functions
          type: object
      required:
        - clientEnv
    DebugChatResponse:
      description: |-
        A chat turn's result: the agent's reply text, the conversation's
        updated state, and whether the conversation has ended.
      type: object
      properties:
        conversationId:
          type: string
        userInput:
          type: string
        response:
          type: string
        metadata:
          $ref: '#/components/schemas/ChatMetadataResponse'
        conversationEnded:
          type: boolean
        delayedResponse:
          type: boolean
      required:
        - conversationId
        - userInput
        - response
        - metadata
        - conversationEnded
        - delayedResponse
    ChatMetadataResponse:
      description: Metadata returned with each chat response.
      type: object
      properties:
        state:
          type: object
        currentNode:
          type: string
        nodeTrace:
          type: array
          items:
            type: string
        metrics:
          type: object
        functionEvents:
          type: array
          items: {}
        handoffDestination:
          type: string
        retrievedTopics:
          type: array
          items:
            type: string
        retrievedSources:
          type: array
          items:
            type: string
        citedTopic:
          type: string
        inFlow:
          type: string
        inStep:
          type: string
        llmRequests:
          type: array
          items:
            type: object
        asrLangCode:
          type: string
        ttsLangCode:
          type: string
      required:
        - state
        - currentNode
        - nodeTrace
        - metrics
        - functionEvents
  securitySchemes:
    polyApiKey:
      type: apiKey
      in: header
      name: X-API-KEY

````