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

# Create Schema



## OpenAPI

````yaml POST /public/v1/projects/{projectId}/schemas
openapi: 3.1.0
info:
  title: Synthbrew API
  description: Runtime CRUD and public v1 management endpoints for Synthbrew resources.
  version: 1.0.0
servers:
  - url: https://api.synthbrew.com/api
    description: Production
security:
  - sourceApiKey: []
tags:
  - name: Runtime
    description: Public runtime CRUD operations authenticated with source API keys
  - name: Public v1 Projects
    description: Team-scoped project management endpoints authenticated with team API keys
  - name: Public v1 Schemas
    description: Schema management endpoints scoped to projects accessible by the API key
  - name: Public v1 Sources
    description: >-
      Source management and generation endpoints scoped to projects accessible
      by the API key
paths:
  /public/v1/projects/{projectId}/schemas:
    post:
      tags:
        - Public v1 Schemas
      summary: Create a schema
      operationId: publicV1CreateSchema
      parameters:
        - $ref: '#/components/parameters/ProjectId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSchemaRequest'
      responses:
        '201':
          description: Schema created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schema'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/PublicUnauthorized'
        '403':
          $ref: '#/components/responses/PublicForbidden'
        '404':
          $ref: '#/components/responses/PublicNotFound'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - teamApiKey: []
components:
  parameters:
    ProjectId:
      name: projectId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Project UUID in the team associated with the API key.
      example: 11111111-1111-1111-1111-111111111111
  schemas:
    CreateSchemaRequest:
      type: object
      required:
        - name
      description: >-
        Create a schema. Optionally include initialVersion.schema to create the
        first version in the same request.
      properties:
        name:
          type: string
        initialVersion:
          type: object
          description: Optional initial schema version payload.
          properties:
            schema:
              $ref: '#/components/schemas/SchemaVersionConfig'
      example:
        name: Hospital operations
        initialVersion:
          schema:
            formatVersion: 1
            metadata:
              name: Hospital operations
              description: Synthetic hospital departments and visits.
            generationDefaults:
              rowCount: 100
              locale: en
              timezone: UTC
            entities:
              - id: departments
                generation:
                  rowCount: 25
                fields:
                  - id: id
                    type: uuid
                  - id: name
                    type: enum
                    values:
                      - Cardiology
                      - Obstetrics
                      - Oncology
                    generation:
                      uniqueValues: true
                primaryKey:
                  - id
    Schema:
      type: object
      additionalProperties: true
      properties:
        id:
          type: string
          format: uuid
        slug:
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        projectId:
          type: string
          format: uuid
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
          nullable: true
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error summary.
    SchemaVersionConfig:
      type: object
      required:
        - formatVersion
        - entities
      description: >-
        Declarative schema config used by schema versions. This is the v1 public
        contract when paired with schemaConfigVersion="v1" and formatVersion=1.
      properties:
        formatVersion:
          type: integer
          enum:
            - 1
          description: Schema config format version.
        metadata:
          type: object
          additionalProperties: true
          properties:
            name:
              type: string
            description:
              type: string
            tags:
              type: array
              items:
                type: string
        generationDefaults:
          $ref: '#/components/schemas/EntityGenerationConfig'
        entities:
          type: array
          items:
            $ref: '#/components/schemas/SchemaEntityConfig'
      additionalProperties: false
    EntityGenerationConfig:
      type: object
      description: Generation defaults or per-entity generation settings.
      properties:
        rowCount:
          oneOf:
            - type: integer
              minimum: 0
            - $ref: '#/components/schemas/RowCountRange'
        locale:
          type: string
        timezone:
          type: string
        seed:
          oneOf:
            - type: string
            - type: integer
      additionalProperties: false
    SchemaEntityConfig:
      type: object
      required:
        - id
        - fields
      description: Entity/table definition in a Synthbrew schema config.
      properties:
        id:
          type: string
          description: >-
            Stable entity identifier. Must start with a letter and use letters,
            numbers, or underscores.
        label:
          type: string
        description:
          type: string
        fields:
          type: array
          items:
            $ref: '#/components/schemas/SchemaFieldConfig'
        primaryKey:
          type: array
          items:
            type: string
          description: Field IDs that form the primary key.
        uniqueKeys:
          type: array
          items:
            type: array
            items:
              type: string
          description: Field ID groups that should be unique at row level.
        indexes:
          type: array
          items:
            $ref: '#/components/schemas/SchemaEntityIndexConfig'
        generation:
          $ref: '#/components/schemas/EntityGenerationConfig'
      additionalProperties: false
    RowCountRange:
      type: object
      required:
        - min
        - max
      properties:
        min:
          type: integer
          minimum: 0
        max:
          type: integer
          minimum: 0
      additionalProperties: false
    SchemaFieldConfig:
      type: object
      required:
        - id
        - type
      description: >-
        Field definition in a Synthbrew schema config. Type-specific properties
        are accepted based on the selected type.
      properties:
        id:
          type: string
          description: >-
            Stable field identifier. Must start with a letter and use letters,
            numbers, or underscores.
        label:
          type: string
        description:
          type: string
        type:
          type: string
          enum:
            - string
            - text
            - integer
            - number
            - boolean
            - date
            - datetime
            - time
            - uuid
            - json
            - enum
        nullable:
          type: boolean
          default: false
        references:
          $ref: '#/components/schemas/SchemaFieldReferenceConfig'
        generation:
          $ref: '#/components/schemas/FieldGenerationConfig'
        format:
          type: string
          enum:
            - plain
            - email
            - url
            - slug
            - phone
          description: String field format.
        minLength:
          type: integer
          minimum: 0
        maxLength:
          type: integer
          minimum: 1
        min:
          type: number
        max:
          type: number
        precision:
          type: integer
          minimum: 1
        prefix:
          type: string
        suffix:
          type: string
        trueRate:
          type: number
          minimum: 0
          maximum: 1
        outputFormat:
          type: string
          enum:
            - iso
            - slash
            - sql
        weekdaysOnly:
          type: boolean
          default: false
        values:
          type: array
          items:
            type: string
          description: Allowed values for enum fields.
        weights:
          type: array
          items:
            type: number
            exclusiveMinimum: 0
          description: Optional enum weights. Count must match values count.
      additionalProperties: false
    SchemaEntityIndexConfig:
      type: object
      required:
        - fields
      properties:
        id:
          type: string
        fields:
          type: array
          items:
            type: string
        unique:
          type: boolean
          default: false
      additionalProperties: false
    SchemaFieldReferenceConfig:
      type: object
      required:
        - entity
        - field
      properties:
        entity:
          type: string
        field:
          type: string
        relation:
          type: string
          enum:
            - many-to-one
            - one-to-one
          default: many-to-one
        pick:
          type: string
          enum:
            - random
            - sequential
          default: random
        onDelete:
          type: string
          enum:
            - restrict
            - cascade
            - set-null
          default: restrict
        onUpdate:
          type: string
          enum:
            - restrict
            - cascade
            - set-null
          default: restrict
      additionalProperties: false
    FieldGenerationConfig:
      type: object
      description: Field-level generation settings.
      properties:
        emptyRate:
          type: number
          minimum: 0
          maximum: 1
          default: 0
          description: >-
            Chance to emit an empty value. Nullable fields emit null; required
            fields fall back to a generated value.
        uniqueValues:
          type: boolean
          description: >-
            Avoid duplicate generated values for this field when the value
            source has a finite pool, such as enum values, weightedChoice
            choices, or reference values. If the pool is exhausted, the entity
            inserts fewer rows and generation continues.
        strategy:
          $ref: '#/components/schemas/FieldGenerationStrategyConfig'
      additionalProperties: false
    FieldGenerationStrategyConfig:
      type: object
      required:
        - kind
      description: >-
        Generation strategy. Supported kinds are literal, sequence, randomInt,
        randomFloat, randomBoolean, weightedChoice, faker, template, dateRange,
        and reference.
      properties:
        kind:
          type: string
          enum:
            - literal
            - sequence
            - randomInt
            - randomFloat
            - randomBoolean
            - weightedChoice
            - faker
            - template
            - dateRange
            - reference
      additionalProperties: true
  responses:
    BadRequest:
      description: Validation or query error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PublicUnauthorized:
      description: Missing, invalid, or revoked team API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingKey:
              value:
                error: API key required
            invalidKey:
              value:
                error: Invalid API key
    PublicForbidden:
      description: Authenticated but forbidden for the current API key scope
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PublicNotFound:
      description: Resource not found (or not accessible for this team/scope)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    sourceApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Source API key created under /api/sources/:sourceId/api-keys
    teamApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: 'Team API key created under /api/api-keys. Prefix: sb_api_.'

````