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

# Start Chat

> Start or continue an Agent chat with `X-Api-Key`. This endpoint does not accept `Authorization: Bearer <API Key>`.

Omit `sessionId` to create a new session; `messages` must then include one `role=user` message. Pass `sessionId` to continue a session, submit a tool approval, or resume a waiting run. A session that is already running returns business code `18120`; use the resume endpoint instead.

A successful response is an AI SDK UI Message SSE stream and is not wrapped in `{ code, data }`. After a new session title is generated, the stream includes `data-title`. When human approval is required, the stream includes `data-approval-cost`.



## OpenAPI

````yaml /openapi/en/aitoearn.openapi.json post /api/agent/chat
openapi: 3.0.1
info:
  title: AiToEarn Open Platform API
  description: >-
    AiToEarn Open Platform API. You can switch between the China and
    international sites for testing. Business success is determined by whether
    the response body has code === 0.
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: China site
  - url: https://aitoearn.ai
    description: International site
security: []
tags:
  - name: AI Services
  - name: AI Services/Video Generation
  - name: AI Services/Image Generation
  - name: Channel Management
  - name: Channel Management/Accounts
  - name: Channel Management/Publishing
  - name: Channel Management/Platforms
  - name: Channel Management/Works
  - name: Channel Management/Account Groups
  - name: Channel Management/Authorization
  - name: Asset Management
  - name: AI Services/Large Language Models
  - name: AI Services/Real-person Assets
  - name: AI Services/Agent
paths:
  /api/agent/chat:
    post:
      tags:
        - AI Services/Agent
      summary: Start Chat
      description: >-
        Start or continue an Agent chat with `X-Api-Key`. This endpoint does not
        accept `Authorization: Bearer <API Key>`.


        Omit `sessionId` to create a new session; `messages` must then include
        one `role=user` message. Pass `sessionId` to continue a session, submit
        a tool approval, or resume a waiting run. A session that is already
        running returns business code `18120`; use the resume endpoint instead.


        A successful response is an AI SDK UI Message SSE stream and is not
        wrapped in `{ code, data }`. After a new session title is generated, the
        stream includes `data-title`. When human approval is required, the
        stream includes `data-approval-cost`.
      operationId: AgentController_chat
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  type: string
                  description: Session ID. Omit it to create a new session.
                messages:
                  type: array
                  description: >-
                    User messages or tool-approval responses submitted in this
                    request. Required for a new session.
                  default: []
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - tool
                        description: >-
                          Message role. user is a user message, and tool is a
                          tool-approval response.
                      content:
                        description: >-
                          A user message can be a string or an array of
                          text/file parts. A tool message must be an array of
                          tool-approval-response objects.
                    required:
                      - role
                      - content
                    additionalProperties: true
                model:
                  type: string
                  default: auto
                  description: >-
                    Model. Pass auto or a specific model ID. The default is
                    auto.
                effort:
                  type: string
                  enum:
                    - none
                    - low
                    - medium
                    - high
                    - xhigh
                    - max
                  description: >-
                    Reasoning effort. The request fails when the model does not
                    support the selected effort.
                timezone:
                  type: string
                  description: User IANA time zone, for example Asia/Shanghai.
              additionalProperties: false
            examples:
              default:
                summary: Request example
                value:
                  messages:
                    - role: user
                      content: Write a short weekend cafe post.
                  model: auto
      responses:
        '200':
          description: >-
            Native third-party protocol response or SSE data, not wrapped in the
            AiToEarn common response envelope.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                description: >-
                  Native third-party protocol response, not wrapped in the
                  AiToEarn common response envelope.
              examples:
                success:
                  summary: Native third-party success response
                  value:
                    id: AgentController_chat_example
                    object: response
            text/event-stream:
              schema:
                type: string
                description: SSE streaming response.
      security:
        - apikey-header-X-Api-Key: []
components:
  securitySchemes:
    apikey-header-X-Api-Key:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Need to get API Key from AiToEarn. Click to go to ["API Key Obtaining
        Tutorial"](/en/use/api-key).

````