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

# TTSQL

> Converts natural language query to SQL, executes it, and returns results in markdown format

<Note>
  **Earnings-call schedule fields.** These fields are returned **only for
  organizations entitled to earnings-call schedule retrieval** and are omitted
  entirely for all others. For an entitled organization, every successful
  response includes both `earnings_schedule` (array) and
  `earnings_schedule_truncated` (bool) — they are `[]` and `false` when the query
  isn't about earnings-call dates. For a schedule query (e.g. "When does Apple
  next report?"), `rdb_result` carries the same schedule as markdown text and
  `earnings_schedule` is its structured form (the two are always returned together,
  not one instead of the other). Upcoming dates that are still vendor projections
  (not yet confirmed) are flagged `is_estimated: true`.
</Note>


## OpenAPI

````yaml POST /v1/ttsql
openapi: 3.0.1
info:
  title: LinqAlpha API
  description: >-
    Linq helps finance professionals make informed decisions using
    Retrieval-Augmented Generation (RAG)-enhanced answers. By leveraging
    cutting-edge Large Language Models (LLM) and supplementary technology, Linq
    provides the most optimized responses based on your queries.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://api.linqalpha.com
security:
  - ApiKeyAuth: []
tags:
  - name: Search
    description: Search and generate responses
  - name: Data
    description: Data retrieval and mapping
  - name: Feedback
    description: Conversation feedback
  - name: RMS
    description: Research Management System
  - name: Source Management
    description: Source batch and file management
  - name: MCP
    description: >-
      LinqAlpha MCP — Financial data tools for AI assistants via Model Context
      Protocol
  - name: Connectors
    description: Customer Connectors — customer-owned MCP connector management
  - name: Briefing
    description: Briefing Agent — automated market briefings with scheduling and delivery
  - name: Status
    description: Sync status — check organization, document, and container sync progress
paths:
  /v1/ttsql:
    post:
      tags:
        - Data
      summary: TTSQL
      description: >-
        Converts natural language query to SQL, executes it, and returns results
        in markdown format
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TtsRequest'
            example:
              query: Show me NVIDIA's quarterly revenue and net income for 2024
      responses:
        '200':
          description: Query executed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TtsResponse'
              example:
                code: 0
                success: true
                message: success
                response:
                  execution_id: 2548d578-0446-4abc-b6f6-f50c966d341c
                  stock_name_mapping:
                    BBG001S5TZJ6: NVIDIA Corporation
                  currency_info:
                    - currency: USD
                      exchange_rate: 1
                  field_currency_info:
                    BBG001S6Q004:
                      SALES: TWD
                      EPS: TWD
                      ff_sales: TWD
                  execution_duration: 171
                  date_range:
                    - '2024-01-01'
                    - '2024-12-31'
                  rdb_result: |-
                    ### Company Annual Financials

                    | name | Fiscal Period End Date | Dividends Per Share |
                    | --- | --- | --- |
                    | NVIDIA Corporation | 2024-01-31 | 0.016 |
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
        '401':
          description: Unauthorized - Invalid API key or authentication credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
              example:
                error:
                  code: API_KEY_MISSING
                  msg: header does not contain api key
                  message: header does not contain api key
                payload: null
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
components:
  schemas:
    TtsRequest:
      type: object
      required:
        - query
      properties:
        query:
          type: string
          description: Natural language query to be converted to SQL
          example: Show me NVIDIA's quarterly revenue and net income for 2024
    TtsResponse:
      type: object
      required:
        - code
        - success
        - message
        - response
      properties:
        code:
          type: integer
          description: Response code (0 for success)
          example: 0
        success:
          type: boolean
          description: Indicates whether the request was successful
          example: true
        message:
          type: string
          description: Response message
          example: success
        response:
          $ref: '#/components/schemas/TtsQueryResult'
    ApiErrorResponse:
      type: object
      description: Standard error response wrapper
      properties:
        error:
          $ref: '#/components/schemas/ApiError'
        payload:
          description: Always null for error responses
          nullable: true
      required:
        - error
        - payload
    TtsQueryResult:
      type: object
      required:
        - execution_id
        - rdb_result
      properties:
        execution_id:
          type: string
          format: uuid
          description: Unique identifier for the query execution
          example: 2548d578-0446-4abc-b6f6-f50c966d341c
        stock_name_mapping:
          type: object
          additionalProperties:
            type: string
          description: Mapping of stock IDs to company names
          example:
            BBG001S5TZJ6: NVIDIA Corporation
        currency_info:
          type: array
          items:
            $ref: '#/components/schemas/CurrencyInfo'
          description: Currency information for each stock
        field_currency_info:
          type: object
          additionalProperties:
            type: string
          description: Currency information for each field
          example:
            BBG001S6Q004:
              SALES: TWD
              EPS: TWD
              ff_sales: TWD
        execution_duration:
          type: number
          description: Execution duration in milliseconds
        date_range:
          type: array
          items:
            type: string
            format: date
          minItems: 2
          maxItems: 2
          description: Date range for the query [start_date, end_date]
          example:
            - '2024-01-01'
            - '2024-12-31'
        rdb_result:
          type: string
          description: Query results formatted as markdown tables
          example: |-
            ### Company Annual Financials

            | name | Fiscal Period End Date | Dividends Per Share |
            | --- | --- | --- |
            | NVIDIA Corporation | 2024-01-31 | 0.016 |
        earnings_schedule:
          type: array
          items:
            $ref: '#/components/schemas/EarningsScheduleEvent'
          description: >-
            Prior/upcoming earnings-call schedule events for the resolved
            companies, returned when the query asks for earnings-call dates
            (e.g. "When does Apple next report?"). Returned only for
            organizations entitled to earnings-call schedule retrieval; omitted
            entirely for all other organizations.
        earnings_schedule_truncated:
          type: boolean
          description: >-
            True when an unbounded universe scan ("which companies report this
            week?") was capped by a load/window limit, so the returned list is
            partial. Always false for company-specific queries. Present only
            alongside earnings_schedule.
    ApiError:
      type: object
      properties:
        code:
          type: string
          description: >-
            Error code indicating the type of error. Common codes:

            - Authentication: `API_KEY_MISSING`, `INVALID_API_KEY`

            - Validation: `INVALID_REQUEST_BODY`, `ORGANIZATION_ID_MISSING`,
            `TICKERS_MISSING`, `CHAT_MESSAGE_ID_MISSING`, `DOCUMENT_ID_MISSING`

            - Service: `SEARCH_FAIL`, `TTS_FAIL`, `CREATE_CONV_FAIL`,
            `GET_STOCK_FAIL`, `CREATE_MSG_FAIL`, `ALPHA_COMP_FAIL`,
            `GET_REF_FAIL`

            - Connectors: `CONNECTOR_LIST_FAIL`, `CONNECTOR_NOT_FOUND`,
            `CONNECTOR_CREATE_FAIL`, `CONNECTOR_UPDATE_FAIL`,
            `CONNECTOR_DELETE_FAIL`, `CONNECTOR_TEST_FAIL`

            - Not Found: `NOT_FOUND`
          example: INVALID_REQUEST_BODY
        msg:
          type: string
          description: Error message (deprecated, use `message` instead)
          example: query is required and must be a string
        message:
          type: string
          description: Error message providing more details about the error
          example: query is required and must be a string
      required:
        - code
    CurrencyInfo:
      type: object
      required:
        - currency
        - exchange_rate
      properties:
        currency:
          type: string
          description: Currency code (ISO 4217)
          example: USD
        exchange_rate:
          type: number
          description: Exchange rate to base currency
          example: 1
    EarningsScheduleEvent:
      type: object
      required:
        - stock_id
        - stock_name
        - event_datetime
        - direction
        - is_estimated
      properties:
        stock_id:
          type: string
          description: Bloomberg Global ID of the company
          example: BBG001S5N8V8
        stock_name:
          type: string
          description: Company name
          example: Apple Inc.
        event_datetime:
          type: string
          description: Earnings-call / release datetime (ISO 8601)
          example: '2026-07-30T00:00:00'
        direction:
          type: string
          enum:
            - prior
            - upcoming
          description: >-
            Whether the event is in the past (prior) or future (upcoming)
            relative to now
        is_estimated:
          type: boolean
          description: >-
            True when the date is a vendor projection rather than a
            confirmed/announced date. Always false for prior events; only ever
            true for upcoming events.
          example: true
        fiscal_date:
          type: string
          format: date
          nullable: true
          description: Fiscal period the event reports on
          example: '2026-09-30'
        link:
          type: string
          nullable: true
          description: Webcast link, if available
        event_description:
          type: string
          nullable: true
          description: Human-readable event description
          example: Q3 2026 Earnings Release (Projected)
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````