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

# Post querylogs

> Search for logs matching the provided query.



## OpenAPI

````yaml /api-reference/openapi.yaml post /query/logs
openapi: 3.0.0
info:
  description: API for managing Metoro environments, alerts, and dashboards.
  license:
    name: Proprietary
    url: https://metoro.io/terms
  title: Metoro API
  version: 1.0.0
servers:
  - description: Production API server
    url: https://us-east.metoro.io/api/v1
  - description: Demo API server
    url: https://demo.us-east.metoro.io/api/v1
security: []
paths:
  /query/logs:
    post:
      tags:
        - Logs
      description: Search for logs matching the provided query.
      operationId: queryLogs
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryLogsRequest'
        description: Query to execute to retrieve logs
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryLogsResponse'
          description: Logs retrieved successfully
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Bad request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Unauthorized
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal server error
components:
  schemas:
    QueryLogsRequest:
      description: Request to query logs
      example:
        query: >-
          count(logs{log_level="error",
          service.name="/k8s/default/redis-test-app"})
        startTime: 1750147200000
        endTime: 1750150800000
        limit: 1000
      properties:
        query:
          description: MetoroQL query to execute to retrieve logs.
          type: string
        startTime:
          description: >-
            Unix timestamp in milliseconds to start querying logs from,
            inclusive. Shorter time ranges will lead to faster responses.
          format: int64
          type: integer
        endTime:
          description: >-
            Unix timestamp in milliseconds to stop querying logs at, inclusive.
            Shorter time ranges will lead to faster responses.
          format: int64
          type: integer
        limit:
          description: >-
            Maximum number of logs to return. Defaults to 100 if not provided.
            Must be between 1 and 1000.
          type: integer
      required:
        - endTime
        - query
        - startTime
      type: object
    QueryLogsResponse:
      description: >-
        Response containing logs matching the query, ordered by timestamp
        ascending
      example:
        count: 2
        logs:
          - timestamp: 1750147200000
            log_level: error
            message: Error connecting to Redis
            attributes:
              service.name: /k8s/default/redis
              container.id: /k8s/default/redis-test-app-7f76f54f-2k8vx/redis-test-app
              environment: production
              custom.attribute: value
          - timestamp: 1750147260000
            log_level: error
            message: Terminating Redis connection
            attributes:
              service.name: /k8s/default/redis
              container.id: /k8s/default/redis-test-app-7f76f54f-2k8vx/redis-test-app
              environment: production
              custom.attribute: value
      properties:
        count:
          description: Total number of logs matching the query
          type: integer
        logs:
          description: List of logs matching the query, ordered
          items:
            $ref: '#/components/schemas/LogEntry'
          type: array
    Error:
      example:
        error: 'Invalid alert configuration: missing required field'
      properties:
        error:
          description: Error message describing what went wrong
          type: string
      required:
        - error
      type: object
    LogEntry:
      description: Log entry object
      example:
        timestamp: 1750147200000
        log_level: error
        message: Error connecting to Redis
        attributes:
          service.name: /k8s/default/redis
          container.id: /k8s/default/redis-test-app-7f76f54f-2k8vx/redis-test-app
          environment: production
          custom.attribute: value
      properties:
        timestamp:
          description: Timestamp of the log entry in milliseconds since epoch
          format: int64
          type: integer
        log_level:
          description: Log level of the entry (e.g., error, info, debug)
          type: string
        message:
          description: Log message content
          type: string
        attributes:
          description: >-
            Attributes associated with the log entry in key-value format. This
            will include metoro generated attributes like service.name,
            container.id, and environment as well as any custom attributes from
            strucutured json logs.
          type: object
      required:
        - attributes
        - log_level
        - message
        - timestamp

````