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

# Create a metrics datasource



## OpenAPI

````yaml /api-reference/openapi.json post /terraform/metricsDatasources
openapi: 3.0.0
info:
  title: Costory
  version: '1.0'
  description: API Documentation
servers:
  - url: https://app-api.costory.io
security: []
paths:
  /terraform/metricsDatasources:
    post:
      tags:
        - Admin Metrics Datasources
      summary: Create a metrics datasource
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminMetricsDatasourceCreate'
      responses:
        '201':
          description: Metrics datasource created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminCreateMetricsDatasourceResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthorized'
      security:
        - bearerAuth: []
        - apiKeyAuth: []
components:
  schemas:
    AdminMetricsDatasourceCreate:
      oneOf:
        - type: object
          properties:
            name:
              type: string
            type:
              type: string
              enum:
                - AwsS3V2
            bucketName:
              type: string
            prefix:
              type: string
              default: ''
            roleArn:
              type: string
              pattern: '^arn:aws:iam::'
            metricsDefinition:
              type: array
              items:
                type: object
                properties:
                  metricName:
                    type: string
                    minLength: 1
                  gapFilling:
                    type: string
                    enum:
                      - ZERO
                      - FORWARD_FILL
                      - LINEAR_INTERPOLATION
                      - SPREAD
                  aggregation:
                    type: string
                    enum:
                      - SUM
                      - Average
                  dimensions:
                    type: array
                    items:
                      type: string
                  valueColumn:
                    type: string
                  unit:
                    type: string
                    nullable: true
                  dateColumn:
                    type: string
                required:
                  - metricName
                  - gapFilling
                  - aggregation
                  - valueColumn
                  - dateColumn
          required:
            - name
            - type
            - bucketName
            - roleArn
            - metricsDefinition
        - type: object
          properties:
            name:
              type: string
            type:
              type: string
              enum:
                - DatadogV2
            query:
              type: string
              minLength: 1
            datadogConfig:
              type: string
              minLength: 1
            metricsDefinition:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                  gapFillingMethod:
                    type: string
                    enum:
                      - ZERO
                      - FORWARD_FILL
                      - LINEAR_INTERPOLATION
                      - SPREAD
                  aggregationFormula:
                    type: string
                    enum:
                      - SUM
                      - Average
                required:
                  - name
                  - gapFillingMethod
                  - aggregationFormula
          required:
            - name
            - type
            - query
            - datadogConfig
      discriminator:
        propertyName: type
    AdminCreateMetricsDatasourceResponse:
      allOf:
        - oneOf:
            - type: object
              properties:
                bucketName:
                  type: string
                prefix:
                  type: string
                roleArn:
                  type: string
                name:
                  type: string
                type:
                  type: string
                  enum:
                    - AwsS3V2
                status:
                  type: string
                metricsDefinition:
                  type: array
                  items:
                    type: object
                    properties:
                      metricName:
                        type: string
                        minLength: 1
                      gapFilling:
                        type: string
                        enum:
                          - ZERO
                          - FORWARD_FILL
                          - LINEAR_INTERPOLATION
                          - SPREAD
                      aggregation:
                        type: string
                        enum:
                          - SUM
                          - Average
                      dimensions:
                        type: array
                        items:
                          type: string
                      valueColumn:
                        type: string
                      unit:
                        type: string
                        nullable: true
                        default: null
                      dateColumn:
                        type: string
                    required:
                      - metricName
                      - gapFilling
                      - aggregation
                      - valueColumn
                      - dateColumn
              required:
                - bucketName
                - prefix
                - roleArn
                - name
                - type
                - metricsDefinition
            - type: object
              properties:
                query:
                  type: string
                datadogConfig:
                  type: string
                  default: ''
                name:
                  type: string
                type:
                  type: string
                  enum:
                    - DatadogV2
                status:
                  type: string
                metricsDefinition:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                      gapFillingMethod:
                        type: string
                        enum:
                          - ZERO
                          - FORWARD_FILL
                          - LINEAR_INTERPOLATION
                          - SPREAD
                      aggregationFormula:
                        type: string
                        enum:
                          - SUM
                          - Average
                      dimensions:
                        type: array
                        items:
                          type: string
                        default: []
                      unit:
                        type: string
                        nullable: true
                        default: null
                    required:
                      - name
                      - gapFillingMethod
                      - aggregationFormula
              required:
                - query
                - name
                - type
                - metricsDefinition
          discriminator:
            propertyName: type
        - type: object
          properties:
            id:
              type: string
          required:
            - id
    BadRequest:
      type: object
      properties:
        error:
          type: string
          description: Error code
        reason:
          type: string
          description: Human-readable reason
        details:
          description: Additional details
        summary:
          type: string
          description: Optional short summary
      required:
        - error
    Unauthorized:
      type: object
      properties:
        error:
          type: string
          description: Unauthorized error message
      required:
        - error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT or Clerk ak_* API key
      description: >-
        Send `Authorization: Bearer <credential>` using either a Clerk session
        JWT or a Clerk API key (`ak_*`). API keys may identify a user (`user_*`)
        or organization (`org_*`) principal and are generated in the Clerk
        Dashboard under API keys.
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-token
      description: >-
        API token for authentication (or Admin API key). The token is scoped per
        organization and can be retrieved in the Organization Switcher.

````