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

# Chat with the service

> Endpoint to chat with the service using a prompt and chat ID.



## OpenAPI

````yaml post /v1/spark-api/generic
openapi: 3.0.0
info:
  title: SPARK API
  description: Spark REST API.
  version: 1.0.0
servers:
  - url: https://api.globalwebindex.com
security: []
paths:
  /v1/spark-api/generic:
    post:
      tags:
        - Chat
      summary: Chat with the service
      description: Endpoint to chat with the service using a prompt and chat ID.
      operationId: chat
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
        description: Chat request payload.
        required: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatSuccess'
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
        '401':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthorized'
        '404':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
        '422':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnprocessableEntity'
        '500':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ChatRequest:
      type: object
      description: Request payload for chat.
      required:
        - prompt
      properties:
        prompt:
          type: string
          description: The chat prompt.
        chat_id:
          type: string
          description: The chat session ID (assigned at 1st prompt).
          example: ''
        dataset_code:
          type: string
          description: >-
            Optional dataset code to scope the chat. It will default to Core
            (ds-core) if not provided.
          example: ds-core
          default: ds-core
        docked_audiences:
          type: array
          description: >
            The audiences ids (UUIDs) to dock and produce insights for.

            These audiences are created via GWI platform and need to be shared
            within the organization.

            The list can be found using
            [/v2/saved/audiences](/docs/platform-api/reference/audiences/v2-list-audiences).
          items:
            type: string
          example:
            - 00000000-0000-0000-0000-000000000000
            - 00000000-0000-0000-0000-000000000001
      example:
        prompt: >-
          What is the average age of social media users in Greece who access
          these platforms daily?
    ChatSuccess:
      type: object
      description: Response payload for chat.
      required:
        - message
        - insights
        - chat_id
        - sources
      properties:
        message:
          type: string
          description: The chat response message.
        insights:
          type: array
          description: Insights related to the chat.
          items:
            $ref: '#/components/schemas/InsightResponse'
        chat_id:
          type: string
          description: The chat session ID.
        sources:
          $ref: '#/components/schemas/ChatInsightSources'
      example:
        message: 'Based on your input, here are some interesting Insights:'
        insights:
          - id: 75f1f21a-9157-412e-bdcf-d6af93a4f4dc
            text: >-
              30% of social media users in Greece who spend 3 or more hours
              daily on these platforms are part of Gen Z.
          - id: 02e9c8a5-d42f-4a6d-b7d8-c238f2208d44
            text: >-
              24% of this audience falls within the age range of 16 to 24 years
              old.
        chat_id: 9b1507d7-16d5-4f26-8d64-69d34e23e9f0
        sources:
          topics:
            - Facebook usage
          audiences:
            - id: c95451a1-b936-42a3-9a1c-13b5b43c20a6
              name: Heavy social networkers
              description: >-
                Individuals who spend between 3 and more than 10 hours on social
                media on an average day.
          datasets:
            - code: ds-core
              name: GWI Core
          locations:
            - code: s2_30
              name: Greece
          waves:
            - code: q3_2024
              name: Q3 2024
            - code: q4_2024
              name: Q4 2024
    BadRequest:
      type: object
      description: Response payload for bad request.
      properties:
        code:
          type: integer
          description: The HTTP status code.
        message:
          type: string
          description: The reason for the error.
      example:
        code: 400
        message: Bad request reason
    Unauthorized:
      type: object
      description: Response payload for unauthorized.
      properties:
        message:
          type: string
      example:
        message: Unauthorized
    NotFound:
      type: object
      description: Response payload for not found.
      properties:
        code:
          type: integer
          description: The HTTP status code.
        message:
          type: string
          description: The reason for the error.
      example:
        code: 404
        message: Not found reason
    UnprocessableEntity:
      type: object
      description: Response payload unprocessable entity.
      properties:
        code:
          type: integer
          description: The HTTP status code.
        message:
          type: string
          description: The reason for the error.
      example:
        code: 422
        message: Unprocessable entity reason
    InternalServerError:
      type: object
      description: Response payload for internal server error.
      properties:
        code:
          type: integer
          description: The HTTP status code.
        message:
          type: string
          description: Generic error reason.
      example:
        code: 500
        message: There was an error processing your request. Please try again later.
    InsightResponse:
      type: object
      description: Single insight record.
      required:
        - id
        - text
      properties:
        id:
          type: string
          description: Unique identifier of the insight.
        text:
          type: string
          description: Insight text.
    ChatInsightSources:
      type: object
      description: Metadata about the sources used for insights.
      properties:
        topics:
          type: array
          items:
            type: string
        audiences:
          type: array
          items:
            $ref: '#/components/schemas/SourcesAudience'
        datasets:
          type: array
          items:
            $ref: '#/components/schemas/SourcesDataset'
        locations:
          type: array
          items:
            $ref: '#/components/schemas/SourcesLocation'
        waves:
          type: array
          items:
            $ref: '#/components/schemas/SourcesWave'
    SourcesAudience:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
    SourcesDataset:
      type: object
      properties:
        code:
          type: string
        name:
          type: string
    SourcesLocation:
      type: object
      properties:
        code:
          type: string
        name:
          type: string
    SourcesWave:
      type: object
      properties:
        code:
          type: string
        name:
          type: string
  securitySchemes:
    ApiKeyAuth:
      in: header
      name: Authorization
      type: apiKey

````