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

# Create Datasource

> Create a new datasource connection to your data infrastructure. Supports multiple database types and cloud services.

Create a new datasource connection to integrate your database or data warehouse with DataBrain. The API validates credentials, tests the connection, and automatically caches the schema for immediate use.

<Note>
  Before creating a datasource, ensure you have valid credentials for your database or data warehouse. The API will test the connection before creating the datasource. Supported datasource types include Snowflake, PostgreSQL, MySQL, BigQuery, Databricks, and many more.
</Note>

## Endpoint

```
POST https://api.usedatabrain.com/api/v2/datasource
```

## Self-hosted Databrain Endpoint

```
POST <SELF_HOSTED_URL>/api/v2/datasource
```

## Authentication

This endpoint requires a service token in the Authorization header. Service tokens differ from data app API keys and provide organization-level permissions.

To access your service token:

1. In **Settings** page, navigate to the **Service Tokens** section.
2. Click the **"Generate Token"** button to create a new service token if you don't have one already.

<Panel>
  <RequestExample>
    ```bash Authentication theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_...' \
      --header 'Content-Type: application/json'
    ```
  </RequestExample>
</Panel>

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for API authentication. Use your service token.

  ```
  Authorization: Bearer dbn_live_abc123...
  ```
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be set to `application/json` for all requests.

  ```
  Content-Type: application/json
  ```
</ParamField>

## Request Body

<ParamField body="datasourceType" type="string" required>
  The type of datasource to create. Must be one of the supported datasource types.

  **Supported types:**

  * `snowflake` - Snowflake data warehouse
  * `postgres` - PostgreSQL database
  * `redshift` - Amazon Redshift
  * `cockroachdb` - CockroachDB
  * `mysql` - MySQL database
  * `mongodb` - MongoDB database
  * `clickhouse` - ClickHouse database
  * `singlestore` - SingleStore database
  * `bigquery` - Google BigQuery
  * `databricks` - Databricks
  * `elasticsearch` - Elasticsearch
  * `opensearch` - OpenSearch
  * `mssql` - Microsoft SQL Server
  * `awss3` - Amazon S3
  * `csv` - CSV files
  * `firebolt` - Firebolt
  * `athena` - Amazon Athena
  * `trino` - Trino

  <Expandable title="Datasource type details">
    The datasource type determines which credential fields are required. Each datasource type has specific connection requirements documented in the credentials section.
  </Expandable>
</ParamField>

<ParamField body="credentials" type="object" required>
  Connection credentials for the datasource. The structure varies by datasource type, but all types require a `name` field.

  <Expandable title="Common credential fields">
    All datasource types require:

    * `name` (string, required) - Unique name for the datasource within your organization
  </Expandable>
</ParamField>

<ParamField body="credentials.name" type="string" required>
  Unique name for the datasource. This name will be used to reference the datasource in other APIs and configurations.

  <Expandable title="Naming guidelines">
    * Use descriptive names (e.g., "production-postgres", "analytics-snowflake")
    * Must be unique within your organization
    * Alphanumeric characters, hyphens, and underscores recommended
    * Case-sensitive
  </Expandable>
</ParamField>

<ParamField body="tenancySettings" type="object">
  Multi-tenant configuration for the datasource. Defines how data is isolated between different tenants/clients. Optional - if not provided, the datasource will be created without explicit tenancy settings.

  <Expandable title="Tenancy configuration details">
    * **TABLE level**: Uses a dedicated table to map client identifiers
    * **DATABASE level**: Each client has a separate database
    * Optional - can be omitted if tenancy is handled at the application level
  </Expandable>
</ParamField>

<ParamField body="tenancySettings.tenancyLevel" type="string">
  The level at which tenant isolation occurs. Must be one of: `TABLE` or `DATABASE`.

  * `TABLE`: Client mapping is stored in a specific table (most common)
  * `DATABASE`: Each client has a separate database instance

  **Required when** `tenancySettings` is provided. If `tenancySettings` is omitted, this field is not needed.
</ParamField>

<ParamField body="tenancySettings.clientColumnType" type="string">
  Data type of the client identifier column. Must be either `NUMBER` or `STRING`.

  **Required when** `tenancyLevel` is `TABLE`.
</ParamField>

<ParamField body="tenancySettings.schemaName" type="string">
  Schema name where the client mapping table is located.

  **Required when** `tenancyLevel` is `TABLE`.
</ParamField>

<ParamField body="tenancySettings.tableName" type="string">
  Name of the table that contains client mapping information.

  **Required when** `tenancyLevel` is `TABLE`.
</ParamField>

<ParamField body="tenancySettings.tableClientNameColumn" type="string">
  Column name in the mapping table that stores the client identifier.

  **Required when** `tenancyLevel` is `TABLE`.
</ParamField>

<ParamField body="tenancySettings.tablePrimaryKeyColumn" type="string">
  Primary key column of the client mapping table.

  **Required when** `tenancyLevel` is `TABLE`.
</ParamField>

### Datasource-Specific Credentials

The credentials object structure depends on the `datasourceType`. Below are examples for common datasource types:

<ParamField body="credentials" type="object">
  Datasource-specific credential fields. The required fields depend on the `datasourceType`.

  <AccordionGroup>
    <Accordion title="Snowflake">
      <ParamField body="credentials.host" type="string" required>
        Snowflake account hostname (e.g., `your-account.snowflakecomputing.com`)
      </ParamField>

      <ParamField body="credentials.username" type="string" required>
        Snowflake username
      </ParamField>

      <ParamField body="credentials.role" type="string" required>
        Snowflake role to use
      </ParamField>

      <ParamField body="credentials.warehouse" type="string" required>
        Snowflake warehouse name
      </ParamField>

      <ParamField body="credentials.database" type="string" required>
        Snowflake database name
      </ParamField>

      <ParamField body="credentials.schema" type="string" required>
        Snowflake schema name
      </ParamField>

      <ParamField body="credentials.credentials" type="string" required>
        Authentication method: `"username/password"` or `"Key-pair authentication"`
      </ParamField>

      <ParamField body="credentials.password" type="string">
        Password (required if credentials is `"username/password"`)
      </ParamField>

      <ParamField body="credentials.privateKey" type="string">
        Private key (required if credentials is `"Key-pair authentication"`)
      </ParamField>

      <ParamField body="credentials.privateKeyPass" type="string">
        Passphrase for the private key (optional)
      </ParamField>
    </Accordion>

    <Accordion title="Postgres / Redshift">
      <ParamField body="credentials.host" type="string" required>
        Database hostname or IP address
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.username" type="string" required>
        Database username
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Database password
      </ParamField>

      <ParamField body="credentials.database" type="string" required>
        Database name
      </ParamField>

      <ParamField body="credentials.schema" type="string" required>
        Schema name
      </ParamField>

      <ParamField body="credentials.sslMode" type="boolean">
        Enable SSL mode (optional)
      </ParamField>

      <ParamField body="credentials.sshTunnel" type="string">
        SSH tunnel setting: `"enable"` or `"disable"` (optional)
      </ParamField>

      <ParamField body="credentials.sshHost" type="string">
        SSH server hostname (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPort" type="number">
        SSH server port (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshUsername" type="string">
        SSH username (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPrivateKey" type="string">
        SSH private key (required if sshTunnel is `"enable"`)
      </ParamField>
    </Accordion>

    <Accordion title="CockroachDB">
      <ParamField body="credentials.host" type="string" required>
        CockroachDB hostname or IP address
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.username" type="string" required>
        Database username
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Database password
      </ParamField>

      <ParamField body="credentials.database" type="string" required>
        Database name
      </ParamField>

      <ParamField body="credentials.schema" type="string" required>
        Schema name
      </ParamField>

      <ParamField body="credentials.sslMode" type="boolean">
        Enable SSL mode (optional)
      </ParamField>

      <ParamField body="credentials.sshTunnel" type="string">
        SSH tunnel setting: `"enable"` or `"disable"` (optional)
      </ParamField>

      <ParamField body="credentials.sshHost" type="string">
        SSH server hostname (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPort" type="number">
        SSH server port (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshUsername" type="string">
        SSH username (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPrivateKey" type="string">
        SSH private key (required if sshTunnel is `"enable"`)
      </ParamField>
    </Accordion>

    <Accordion title="BigQuery">
      <ParamField body="credentials.credentials_json" type="string" required>
        JSON string containing Google Cloud service account credentials
      </ParamField>

      <ParamField body="credentials.project_id" type="string" required>
        Google Cloud project ID
      </ParamField>

      <ParamField body="credentials.dataset_location" type="string" required>
        BigQuery dataset location (e.g., `"US"`, `"EU"`)
      </ParamField>

      <ParamField body="credentials.dataset_id" type="string">
        BigQuery dataset ID (optional)
      </ParamField>
    </Accordion>

    <Accordion title="MySQL / MongoDB / ClickHouse">
      <ParamField body="credentials.host" type="string" required>
        Database hostname or IP address
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.user" type="string" required>
        Database username. Note: Uses `user` not `username` for these datasource types.
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Database password
      </ParamField>
    </Accordion>

    <Accordion title="MSSQL">
      <ParamField body="credentials.server" type="string" required>
        SQL Server hostname or IP address. Note: Uses `server` not `host` for MSSQL.
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.user" type="string" required>
        Database username. Note: Uses `user` not `username` for MSSQL.
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Database password
      </ParamField>

      <ParamField body="credentials.database" type="string">
        Database name (optional)
      </ParamField>

      <ParamField body="credentials.isDisableDatabase" type="boolean">
        Disable database selection (optional)
      </ParamField>

      <ParamField body="credentials.readOnlyIntent" type="boolean">
        Optional MSSQL read-only routing hint. When `true`, Databrain connects with read-only intent for MSSQL workloads.
      </ParamField>
    </Accordion>

    <Accordion title="SingleStore">
      <ParamField body="credentials.host" type="string" required>
        Database hostname or IP address
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.user" type="string" required>
        Database username
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Database password
      </ParamField>

      <ParamField body="credentials.database" type="string" required>
        Database name
      </ParamField>
    </Accordion>

    <Accordion title="Databricks">
      <ParamField body="credentials.serverHostname" type="string" required>
        Databricks server hostname
      </ParamField>

      <ParamField body="credentials.httpPath" type="string" required>
        Databricks HTTP path
      </ParamField>

      <ParamField body="credentials.token" type="string" required>
        Databricks access token
      </ParamField>
    </Accordion>

    <Accordion title="Elasticsearch">
      <ParamField body="credentials.server_type" type="string" required>
        Server type: `"elastic-cloud"`, `"open-cloud"`, or `"self-managed"`
      </ParamField>

      <ParamField body="credentials.cloud_id" type="string">
        Cloud ID (required if server\_type is `"elastic-cloud"` or `"open-cloud"`)
      </ParamField>

      <ParamField body="credentials.server_url" type="string">
        Server URL (required if server\_type is `"self-managed"`)
      </ParamField>

      <ParamField body="credentials.username" type="string">
        Username (required unless `disableAuth` is `true`)
      </ParamField>

      <ParamField body="credentials.password" type="string">
        Password (required unless `disableAuth` is `true`)
      </ParamField>

      <ParamField body="credentials.disableAuth" type="boolean">
        Disable authentication (optional, default `false`). Only valid when server\_type is `"self-managed"`.
      </ParamField>

      <ParamField body="credentials.isIgnoreVerifyCert" type="boolean">
        Ignore certificate verification (optional)
      </ParamField>

      <ParamField body="credentials.isIgnoreSsl" type="boolean">
        Ignore SSL (optional)
      </ParamField>
    </Accordion>

    <Accordion title="OpenSearch">
      <ParamField body="credentials.server_type" type="string" required>
        Server type: `"elastic-cloud"`, `"open-cloud"`, or `"self-managed"`
      </ParamField>

      <ParamField body="credentials.cloud_id" type="string">
        Cloud ID (required if server\_type is `"elastic-cloud"` or `"open-cloud"`)
      </ParamField>

      <ParamField body="credentials.server_url" type="string">
        Server URL (required if server\_type is `"self-managed"`)
      </ParamField>

      <ParamField body="credentials.username" type="string">
        Username (required unless `disableAuth` is `true`)
      </ParamField>

      <ParamField body="credentials.password" type="string">
        Password (required unless `disableAuth` is `true`)
      </ParamField>

      <ParamField body="credentials.disableAuth" type="boolean">
        Disable authentication (optional, default `false`). Only valid when server\_type is `"self-managed"`.
      </ParamField>

      <ParamField body="credentials.isIgnoreVerifyCert" type="boolean">
        Ignore certificate verification (optional)
      </ParamField>

      <ParamField body="credentials.isIgnoreSsl" type="boolean">
        Ignore SSL (optional)
      </ParamField>
    </Accordion>

    <Accordion title="Firebolt">
      <ParamField body="credentials.client_id" type="string" required>
        Firebolt client ID
      </ParamField>

      <ParamField body="credentials.client_secret" type="string" required>
        Firebolt client secret
      </ParamField>

      <ParamField body="credentials.account" type="string" required>
        Firebolt account name
      </ParamField>

      <ParamField body="credentials.database" type="string" required>
        Database name
      </ParamField>

      <ParamField body="credentials.engineName" type="string" required>
        Engine name
      </ParamField>

      <ParamField body="credentials.schema" type="string">
        Schema name (optional)
      </ParamField>
    </Accordion>

    <Accordion title="Athena">
      <ParamField body="credentials.database" type="string" required>
        Athena database name
      </ParamField>

      <ParamField body="credentials.outputBucket" type="string" required>
        S3 output bucket for query results
      </ParamField>

      <ParamField body="credentials.s3AccessKeyId" type="string" required>
        AWS access key ID
      </ParamField>

      <ParamField body="credentials.s3Region" type="string" required>
        AWS region
      </ParamField>

      <ParamField body="credentials.s3SecretAccessKey" type="string" required>
        AWS secret access key
      </ParamField>

      <ParamField body="credentials.datasourceId" type="string">
        Datasource ID (optional)
      </ParamField>
    </Accordion>

    <Accordion title="Trino">
      <ParamField body="credentials.host" type="string" required>
        Trino hostname or IP address
      </ParamField>

      <ParamField body="credentials.port" type="number" required>
        Database port number (1-65535)
      </ParamField>

      <ParamField body="credentials.catalog" type="string" required>
        Trino catalog name
      </ParamField>

      <ParamField body="credentials.schema" type="string" required>
        Schema name
      </ParamField>

      <ParamField body="credentials.username" type="string" required>
        Username
      </ParamField>

      <ParamField body="credentials.password" type="string" required>
        Password
      </ParamField>

      <ParamField body="credentials.sshTunnel" type="string">
        SSH tunnel setting: `"enable"` or `"disable"` (optional)
      </ParamField>

      <ParamField body="credentials.sshHost" type="string">
        SSH host (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPort" type="number">
        SSH port (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshUsername" type="string">
        SSH username (required if sshTunnel is `"enable"`)
      </ParamField>

      <ParamField body="credentials.sshPrivateKey" type="string">
        SSH private key (required if sshTunnel is `"enable"`)
      </ParamField>
    </Accordion>

    <Accordion title="CSV">
      <ParamField body="credentials.name" type="string" required>
        Name for the CSV datasource
      </ParamField>
    </Accordion>

    <Accordion title="AWS S3">
      <ParamField body="credentials.bucketName" type="string" required>
        S3 bucket name
      </ParamField>

      <ParamField body="credentials.datasetPath" type="string">
        Path within the bucket (optional, can be empty string)
      </ParamField>

      <ParamField body="credentials.s3Region" type="string" required>
        AWS region (e.g., `"us-east-1"`)
      </ParamField>

      <ParamField body="credentials.tableLevel" type="string">
        Table level: `"File"` or `"Folder"` (optional)
      </ParamField>

      <ParamField body="credentials.s3AccessKeyId" type="string" required>
        AWS access key ID
      </ParamField>

      <ParamField body="credentials.s3SecretAccessKey" type="string" required>
        AWS secret access key
      </ParamField>
    </Accordion>
  </AccordionGroup>
</ParamField>

## Response

<ResponseField name="name" type="string">
  The name of the created datasource (same as credentials.name).
</ResponseField>

<ResponseField name="error" type="null">
  Error field, null when successful. Not included in successful responses.
</ResponseField>

## Examples

<Panel>
  <RequestExample>
    ```bash cURL - PostgreSQL Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "postgres",
        "credentials": {
          "name": "production-postgres",
          "host": "db.example.com",
          "port": 5432,
          "username": "dbuser",
          "password": "securepassword",
          "database": "analytics",
          "schema": "public"
        }
      }'
    ```

    ```bash cURL - Snowflake Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "snowflake",
        "credentials": {
          "name": "analytics-snowflake",
          "host": "account.snowflakecomputing.com",
          "username": "user@example.com",
          "role": "ANALYST",
          "warehouse": "COMPUTE_WH",
          "database": "ANALYTICS",
          "schema": "PUBLIC",
          "credentials": "username/password",
          "password": "securepassword"
        }
      }'
    ```

    ```bash cURL - MSSQL Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "mssql",
        "credentials": {
          "name": "production-mssql",
          "server": "sqlserver.example.com",
          "port": 1433,
          "user": "sqluser",
          "password": "securepassword",
          "database": "analytics",
          "readOnlyIntent": true
        }
      }'
    ```

    ```bash cURL - CockroachDB Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "cockroachdb",
        "credentials": {
          "name": "production-cockroachdb",
          "host": "cockroach.example.com",
          "port": 26257,
          "username": "dbuser",
          "password": "securepassword",
          "database": "analytics",
          "schema": "public"
        }
      }'
    ```

    ```bash cURL - OpenSearch Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "opensearch",
        "credentials": {
          "name": "production-opensearch",
          "server_type": "self-managed",
          "server_url": "https://opensearch.example.com:9200",
          "username": "admin",
          "password": "securepassword"
        }
      }'
    ```

    ```bash cURL - Elasticsearch Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "elasticsearch",
        "credentials": {
          "name": "production-elasticsearch",
          "server_type": "elastic-cloud",
          "cloud_id": "my-deployment:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ...",
          "username": "elastic",
          "password": "securepassword"
        }
      }'
    ```

    ```bash cURL - Trino Example theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "trino",
        "credentials": {
          "name": "production-trino",
          "host": "trino.example.com",
          "port": 8080,
          "catalog": "hive",
          "schema": "analytics",
          "username": "trinouser",
          "password": "securepassword"
        }
      }'
    ```

    ```bash cURL - With Tenancy Settings theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/datasource \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datasourceType": "postgres",
        "credentials": {
          "name": "multi-tenant-postgres",
          "host": "db.example.com",
          "port": 5432,
          "username": "dbuser",
          "password": "securepassword",
          "database": "analytics",
          "schema": "public"
        },
        "tenancySettings": {
          "tenancyLevel": "TABLE",
          "clientColumnType": "STRING",
          "schemaName": "public",
          "tableName": "clients",
          "tableClientNameColumn": "client_name",
          "tablePrimaryKeyColumn": "client_id"
        }
      }'
    ```

    ```javascript Node.js theme={"dark"}
    const response = await fetch('https://api.usedatabrain.com/api/v2/datasource', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer dbn_live_abc123...',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        datasourceType: 'postgres',
        credentials: {
          name: 'production-postgres',
          host: 'db.example.com',
          port: 5432,
          username: 'dbuser',
          password: 'securepassword',
          database: 'analytics',
          schema: 'public'
        }
      })
    });

    const data = await response.json();
    if (data.error) {
      console.error('Error:', data.error);
    } else {
      console.log('Datasource created:', data.name);
    }
    ```

    ```python Python theme={"dark"}
    import requests

    response = requests.post(
        'https://api.usedatabrain.com/api/v2/datasource',
        headers={
            'Authorization': 'Bearer dbn_live_abc123...',
            'Content-Type': 'application/json'
        },
        json={
            'datasourceType': 'postgres',
            'credentials': {
                'name': 'production-postgres',
                'host': 'db.example.com',
                'port': 5432,
                'username': 'dbuser',
                'password': 'securepassword',
                'database': 'analytics',
                'schema': 'public'
            }
        }
    )

    data = response.json()
    if data.get('error'):
        print('Error:', data['error'])
    else:
        print('Datasource created:', data['name'])
    ```
  </RequestExample>

  <ResponseExample>
    ```json 200 - Success theme={"dark"}
    {
      "name": "production-postgres"
    }
    ```

    ```json 400 - Bad Request theme={"dark"}
    {
      "error": {
        "code": "INVALID_REQUEST_BODY",
        "message": "Invalid credentials for postgres: \"host\" is required",
        "status": 400
      }
    }
    ```

    ```json 400 - Duplicate Name theme={"dark"}
    {
      "error": {
        "code": "DATASOURCE_NAME_ERROR",
        "message": "Datasource name already exists, please use unique name",
        "status": 400
      }
    }
    ```

    ```json 400 - Connection Test Failed theme={"dark"}
    {
      "error": {
        "code": "CREDENTIAL_TEST_FAILED",
        "message": "Failed to connect to datasource",
        "status": 400
      }
    }
    ```

    ```json 401 - Unauthorized theme={"dark"}
    {
      "error": {
        "code": "AUTHENTICATION_ERROR",
        "message": "AUTHENTICATION_ERROR",
        "status": 401
      }
    }
    ```
  </ResponseExample>
</Panel>

## Error Codes

| Error Code                 | HTTP Status | Description                                             |
| -------------------------- | ----------- | ------------------------------------------------------- |
| `INVALID_REQUEST_BODY`     | 400         | Missing required fields or invalid credential structure |
| `DATASOURCE_NAME_ERROR`    | 400         | Datasource name already exists                          |
| `CREDENTIAL_TEST_FAILED`   | 400         | Connection test failed                                  |
| `AUTHENTICATION_ERROR`     | 401         | Invalid or missing service token                        |
| `SCHEMA_CACHE_FAILED`      | 500         | Schema caching failed                                   |
| `CREATE_DATASOURCE_FAILED` | 500         | Internal error during datasource creation               |
| `INTERNAL_SERVER_ERROR`    | 500         | Server error occurred                                   |

## Next Steps

<CardGroup cols={2}>
  <Card title="List Datasources" icon="list" href="/developer-docs/helpers/api-reference/list-datasources">
    View all datasources in your organization
  </Card>

  <Card title="Update Datasource" icon="edit" href="/developer-docs/helpers/api-reference/update-datasource">
    Update datasource credentials or configuration
  </Card>

  <Card title="Sync Datasource" icon="sync" href="/developer-docs/helpers/api-reference/sync-datasource">
    Sync datasource schema after creation
  </Card>

  <Card title="Create Datamart" icon="database" href="/developer-docs/helpers/api-reference/create-datamart">
    Create a datamart using your new datasource
  </Card>
</CardGroup>
