---
title: "Create a model"
method: POST
path: "/api/public/organizations/{orgId}/models"
tags: ["Models"]
---

# Create a model

`POST /api/public/organizations/{orgId}/models`

## Request

- Base URL: `https://charts.basedash.com`
- URL: `https://charts.basedash.com/api/public/organizations/{orgId}/models`
- Auth: HTTP bearer

Creates a new model within an organization. Requires admin access to the organization.

## Path parameters

- `orgId` string, required: Organization ID

## Request body

- CreateModelInput
  - `name` string, required: Human-readable model name
  - `referenceName` string: Stable SQL reference name for the model
  - `description` string: Model description
  - `databaseConnectionId` string, required: Data source ID
  - `sqlQuery` string, required: SQL query that defines the reusable dataset
  - `measures` object[]: Ordered reusable aggregate expressions
    - `name` string, required
    - `sql` string, required
    - `description` string
    - `synonyms` string[]
  - `segments` object[]: Ordered reusable predicate expressions
    - `name` string, required
    - `sql` string, required
    - `description` string
    - `synonyms` string[]
  - `defaultTimeColumn` string, nullable: Default date result column, or null for no default
  - `synonyms` string[]: Alternative names for the model
  - `grain` string: What one row in the model represents
  - `keyColumns` string[]: Columns that uniquely identify a row
  - `relationships` object[]: Relationships from this model to other models
    - `targetModelId` string, required
    - `sourceColumn` string, required
    - `targetColumn` string, required
    - `cardinality` 'many_to_one' | 'one_to_one' | 'one_to_many', required
  - `usageGuidance` string: Guidance about when and how to use the model
  - `columnSynonyms` object[]: Alternative names for model result columns
    - `name` string, required
    - `synonyms` string[], required

## Response `201`

Model created successfully

- object
  - `data` ModelResponse, required
    - `id` string, required: Model ID
    - `createdAt` string, date-time, required: Model creation timestamp
    - `updatedAt` string, date-time, required: Model last update timestamp
    - `name` string, required: Human-readable model name
    - `referenceName` string, required: Stable SQL reference name for the model
    - `description` string, required: Model description
    - `sqlQuery` string, required: SQL query for the latest model version
    - `organizationId` string, required: Organization ID
    - `databaseConnectionId` string, required: Data source ID
    - `verifiedAt` string, date-time, nullable, required: Verification timestamp for the current model SQL
    - `verifiedByMemberId` string, nullable, required: Member who verified the current model SQL
    - `columns` object[], required: Inferred result columns and their documentation
      - `name` string, required
      - `description` string
      - `synonyms` string[]
      - `type` 'array' | 'bigint' | 'boolean' | 'date' | 'mixed' | 'null' | 'number' | 'object' | 'string' | 'unknown', required: Best-effort type inferred from sampled result values.
      - `nullable` boolean, required: Whether null or undefined appeared in sampled result values.
      - `example` union, required: First non-null sampled value, normalized for JSON.
        - string
        - number
        - boolean
      - `sampleValues` union[]: Distinct non-null sampled values (capped), normalized for JSON.
        - union
          - string
          - number
          - boolean
    - `measures` object[], required: Ordered reusable aggregate expressions
      - `name` string, required
      - `sql` string, required
      - `description` string
      - `synonyms` string[]
    - `segments` object[], required: Ordered reusable predicate expressions
      - `name` string, required
      - `sql` string, required
      - `description` string
      - `synonyms` string[]
    - `defaultTimeColumn` string, nullable, required: Default date result column
    - `synonyms` string[], required: Alternative model names
    - `grain` string, required: What one model row represents
    - `keyColumns` string[], required: Columns that uniquely identify a model row
    - `relationships` object[], required: Relationships to other models
      - `targetModelId` string, required
      - `sourceColumn` string, required
      - `targetColumn` string, required
      - `cardinality` 'many_to_one' | 'one_to_one' | 'one_to_many', required
    - `usageGuidance` string, required: Guidance about when and how to use the model
    - `warnings` object[], required: Non-blocking semantic metadata warnings
      - `code` 'base_sql_contains_group_by' | 'default_time_column_cleared' | 'measure_may_not_aggregate' | 'semantic_expression_may_be_stale', required
      - `message` string, required
      - `field` 'sqlQuery' | 'measures' | 'segments' | 'defaultTimeColumn', required
      - `name` string

## Other responses

- `400`: Bad request - Invalid JSON body or validation error
- `401`: Unauthorized - Missing or invalid API key
- `404`: Not found - Organization, data source, or admin access not found
- `409`: Conflict - Another model in the organization already uses this reference name
- `429`: Rate limit exceeded - Too many requests
- `500`: Internal server error

---

[API](https://skmtc.dev/basedash/apis/basedash-public-api.md) - [All operations](https://skmtc.dev/basedash/apis/basedash-public-api/llms.txt) - [OpenAPI document](https://skmtc.dev/basedash/apis/basedash-public-api/revisions/efb9d40bc6f7?raw)
