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

# Create Table

> Creates an empty uploaded table that can be inserted into with the /insert endpoint.
Each successful table creation consumes 10 credits.

<Info>
  Minimum required API key scope: `Read/Write`
</Info>

The resulting table will be empty, and can be inserted into with the [/insert endpoint](./uploads-insert).

<Note>
  * If a table already exists with the same name, the request will fail.
  * Column names in the table can't start with a special character or a digit.
  * Each successful table creation **consumes credits based on the table size created**. Minimum charge is 1 credit.
  * To delete a table, you can go to `user settings (dune.com) -> data -> delete` or use the [/delete endpoint](./uploads-delete).
</Note>

<Tip>
  **Migrating from the old API?** See the [Migration Guide](./migration) for help updating your code.
</Tip>

## Schema

You need to define the schema of your data by providing `schema` array of columns in the request. Each column has three parameters:

**name**: the name of the field

**type**: the data type of the field
<Note> Dune supports [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) timestamp format </Note>

**nullable**: if the column is nullable (true/false, true by default)

<RequestExample>
  ```bash curl theme={null}
  curl --request POST \
    --url https://api.dune.com/api/v1/uploads \
    --header 'X-DUNE-API-KEY: <x-dune-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
    "namespace":"my_user",
    "table_name":"interest_rates",
    "description": "10 year daily interest rates, sourced from https://fred.stlouisfed.org/series/DGS10",
    "is_private": false,
    "schema": [{"name": "date", "type": "timestamp"}, {"name": "dgs10", "type": "double",  "nullable": true}]
  }'
  ```

  ```python Python SDK theme={null}
  from dune_client.client import DuneClient

  dune = DuneClient()

  table = dune.create_table(
          namespace="my_user",
          table_name="interest_rates",
          description="10 year daily interest rates, sourced from https://fred.stlouisfed.org/series/DGS10",
          schema= [
              {"name": "date", "type": "timestamp"},
              {"name": "dgs10", "type": "double", "nullable": True}
          ],
          is_private=False
  )
  ```

  ```typescript TS SDK theme={null}
  import { DuneClient, ColumnType } from "@duneanalytics/client-sdk";

  client = new DuneClient(process.env.DUNE_API_KEY!);
  const result = await client.table.create({
    namespace: "my_user",
    table_name: "interest_rates",
    schema: [
      {"name": "date", "type": ColumnType.Timestamp},
      {"name": "dgs10", "type": ColumnType.Double}
    ]
  });
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.dune.com/api/v1/uploads"

  payload = {
      "namespace": "my_user",
      "table_name": "interest_rates",
      "description": "10 year daily interest rates, sourced from https://fred.stlouisfed.org/series/DGS10",
      "schema": [{"name": "date", "type": "timestamp"}, {"name": "dgs10", "type": "double", "nullable": True}],
      "is_private": False
  }

  headers = {
      "X-DUNE-API-KEY": "<x-dune-api-key>",
      "Content-Type": "application/json"
  }


  response = requests.request("POST", url, json=payload, headers=headers)
  ```

  ```javascript Javascript theme={null}
  const url = "https://api.dune.com/api/v1/uploads";

  const payload = {
      "namespace": "my_user",
      "table_name": "interest_rates",
      "description": "10 year daily interest rates, sourced from https://fred.stlouisfed.org/series/DGS10",
      "schema": [{"name": "date", "type": "timestamp"}, {"name": "dgs10", "type": "double", "nullable": true}],
      "is_private": false
  };

  const headers = {
      "X-DUNE-API-KEY": "<x-dune-api-key>",
      "Content-Type": "application/json"
  };

  fetch(url, {
      method: 'POST',
      headers: headers,
      body: JSON.stringify(payload)
  })
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
  ```
</RequestExample>


## OpenAPI

````yaml POST /v1/uploads
openapi: 3.0.1
info:
  contact: {}
  description: Dune API
  title: DuneAPI
  version: '1.0'
servers:
  - url: https://api.dune.com/api
security: []
paths:
  /v1/uploads:
    post:
      summary: Create an empty uploaded table with a defined schema
      description: >-
        Creates an empty uploaded table that can be inserted into with the
        /insert endpoint.

        Each successful table creation consumes 10 credits.
      parameters:
        - description: API Key for the service
          in: header
          name: X-Dune-Api-Key
          required: true
          schema:
            type: string
        - description: Alternative to using the X-Dune-Api-Key header
          in: query
          name: api_key
          schema:
            type: string
      requestBody:
        content:
          '*/*':
            schema:
              $ref: '#/components/schemas/models.TableCreateRequest'
        description: payload
        x-originalParamName: payload
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.TableCreateResponse'
          description: OK
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.TableCreateResponse'
          description: Created
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error400'
          description: Bad Request
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error404'
          description: Not Found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error500'
          description: Internal Server Error
components:
  schemas:
    models.TableCreateRequest:
      properties:
        description:
          type: string
        is_private:
          type: boolean
        namespace:
          type: string
        schema:
          items:
            $ref: '#/components/schemas/models.TableColumn'
          type: array
        table_name:
          type: string
      type: object
    models.TableCreateResponse:
      properties:
        already_existed:
          type: boolean
        example_query:
          type: string
        full_name:
          type: string
        message:
          type: string
        namespace:
          type: string
        table_name:
          type: string
      type: object
    models.Error400:
      properties:
        error:
          example: Bad Request
          type: string
      type: object
    models.Error404:
      properties:
        error:
          example: Object not found
          type: string
      type: object
    models.Error500:
      properties:
        error:
          example: Internal error
          type: string
      type: object
    models.TableColumn:
      properties:
        name:
          type: string
        nullable:
          type: boolean
        type:
          description: >-
            ColumnType is a json.RawMessage so that we can support objects like
            Array and Struct.
          items:
            type: integer
          type: array
      type: object

````