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

# Create data view

> Creates a new data view for a knowledge source, providing controlled access through a service account. This endpoint requires credits and meters setup work based on the number of warehouse operations performed for the request.

<Note>
  For a complete guide on setting up Data Views including creating knowledge, service accounts, and obtaining BigQuery credentials, see the [Creating Data Views Introduction](/introduction/data-views).
</Note>


## OpenAPI

````yaml post /data-views
openapi: 3.0.3
info:
  version: 0.1.1
  title: Datagrid API
  description: Datagrid API
servers:
  - url: https://api.datagrid.com/v1
security:
  - BearerAuth: []
paths:
  /data-views:
    post:
      tags:
        - Data Views
      summary: Create data view
      description: >-
        Creates a new data view for a knowledge source, providing controlled
        access through a service account. This endpoint requires credits and
        meters setup work based on the number of warehouse operations performed
        for the request.
      operationId: DataViews.createDataView
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - bigquery_dataset_name
                - knowledge_id
                - service_account_id
              properties:
                bigquery_dataset_name:
                  type: string
                  description: >-
                    The name of the BigQuery dataset containing views to the
                    data. Your organization's domain will be automatically
                    prepended to the name.
                knowledge_id:
                  type: string
                  description: The id of the knowledge to create a data view for.
                service_account_id:
                  type: string
                  description: >-
                    The id of the service account that will access this data
                    view.
      responses:
        '201':
          description: Successfully created data view
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateDataViewResponse'
        '402':
          description: >-
            Credit limit exceeded. The organization does not have enough credits
            to perform this operation. Check your billing status and add credits
            to your account.
        '404':
          description: >-
            Not found. The referenced knowledge or service account does not
            exist, or the authenticated user does not have permission to access
            it.
        '429':
          description: >-
            Rate limit exceeded. The request has been throttled because the rate
            limit for this endpoint has been reached. Check the `Retry-After`
            response header and retry after the specified number of seconds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Datagrid from 'datagrid-ai';

            const client = new Datagrid({
              apiKey: process.env['DATAGRID_API_KEY'], // This is the default and can be omitted
            });

            const dataView = await client.dataViews.create({
              bigquery_dataset_name: 'bigquery_dataset_name',
              knowledge_id: 'knowledge_id',
              service_account_id: 'service_account_id',
            });

            console.log(dataView);
        - lang: Python
          source: |-
            import os
            from datagrid_ai import Datagrid

            client = Datagrid(
                api_key=os.environ.get("DATAGRID_API_KEY"),  # This is the default and can be omitted
            )
            data_view = client.data_views.create(
                bigquery_dataset_name="bigquery_dataset_name",
                knowledge_id="knowledge_id",
                service_account_id="service_account_id",
            )
            print(data_view)
components:
  schemas:
    CreateDataViewResponse:
      allOf:
        - $ref: '#/components/schemas/DataView'
        - type: object
          properties:
            credits:
              nullable: true
              description: >-
                Credit consumption for this data-view creation. `consumed`
                reflects the warehouse setup work billed for the request. `null`
                when the billing write fails after the data view is successfully
                created.
              allOf:
                - $ref: '#/components/schemas/OperationCredits'
    RateLimitError:
      type: object
      description: >-
        Returned when the rate limit is exceeded. Rate limits are enforced per
        teamspace, endpoint path, and HTTP method over a 60-second sliding
        window. Each endpoint may have its own limit — check the
        X-RateLimit-Limit response header for the effective value.
      required:
        - error
        - message
        - retryable
        - status_code
      properties:
        status_code:
          type: integer
          description: The HTTP status code (429).
        statusCode:
          type: integer
          deprecated: true
          description: Deprecated. Use status_code instead.
        error:
          type: string
          enum:
            - rate_limit_exceeded
          description: The error code identifying this as a rate limit error.
        message:
          type: string
          description: A human-readable error message.
        mitigation:
          type: string
          description: Suggested action to resolve the error.
        retryable:
          type: boolean
          description: Whether the request can be retried after a delay.
        details:
          type: object
          properties:
            reason:
              type: string
              description: A detailed explanation of why the rate limit was exceeded.
    DataView:
      type: object
      description: >-
        The `data_view` object represents a view into a knowledge source that
        can be accessed through a service account.
      required:
        - object
        - id
        - bigquery_dataset_name
        - created_at
        - knowledge_id
        - service_account_id
      properties:
        object:
          type: string
          enum:
            - data_view
          description: The object type, which is always `data_view`.
        id:
          type: string
          description: The data view identifier.
        bigquery_dataset_name:
          type: string
          description: The name of the BigQuery dataset containing views to the data.
        created_at:
          type: string
          format: date-time
          description: The ISO string for when the data view was created.
        knowledge_id:
          type: string
          description: The id of the knowledge this data view is for.
        service_account_id:
          type: string
          description: The id of the service account that can access this data view.
    OperationCredits:
      type: object
      required:
        - consumed
      properties:
        consumed:
          type: number
          description: The number of credits consumed by the operation.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````