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

# Handle Chat

> Handles a user chat message.
- If `use_same_agent` is true, it retrieves the user's existing agent.
- If no agent exists, or `use_same_agent` is false, it creates a new agent.
- When creating an agent, it uses any provided optional parameters, falling back to defaults.



## OpenAPI

````yaml https://services.staging.app.dados.rio/eai-agent/openapi.json post /api/v1/eai-gateway/chat
openapi: 3.1.0
info:
  title: Agentic Search API
  description: >-
    API que gerencia os fluxos e ferramentas dos agentes de IA da Prefeitura do
    Rio de Janeiro
  version: 0.1.0
servers:
  - url: https://services.staging.app.dados.rio/eai-agent
    description: Staging
security: []
paths:
  /api/v1/eai-gateway/chat:
    post:
      tags:
        - EAI Gateway
      summary: Handle Chat
      description: >-
        Handles a user chat message.

        - If `use_same_agent` is true, it retrieves the user's existing agent.

        - If no agent exists, or `use_same_agent` is false, it creates a new
        agent.

        - When creating an agent, it uses any provided optional parameters,
        falling back to defaults.
      operationId: handle_chat_api_v1_eai_gateway_chat_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    ChatRequest:
      properties:
        user_number:
          type: string
          title: User Number
        message:
          type: string
          title: Message
        timeout:
          type: integer
          title: Timeout
          default: 300
        polling_interval:
          type: integer
          title: Polling Interval
          default: 2
        provider:
          type: string
          title: Provider
          default: google_agent_engine
        reasoning_engine_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Reasoning Engine Id
      type: object
      required:
        - user_number
        - message
      title: ChatRequest
    ChatResponse:
      properties:
        response:
          additionalProperties: true
          type: object
          title: Response
      type: object
      required:
        - response
      title: ChatResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````