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

# Create a flow

> Creates a flow in a workspace and returns it in full. Only `typebot.name` is required; omit `groups`, `edges` and `events` for an empty flow with a start event.

The new flow is a **draft**: agents do not see it until you call **Publish a flow**.

A flow is a conversational flow unless `typebot.settings.general.type` is `TOOL` or `CONTEXT_ENRICHMENT`. A `TOOL` needs a `tenant` your token grants (otherwise `403`) and a `toolDescription`, and its name must contain a letter or a number and be unique inside the tenant (otherwise `400`). Its inputs are declared in a `Declare variables` block of `groups`; copying the shape from an existing tool read with **Get a flow** is the safest way to build one.

The flow is checked before it is saved, and a refusal saves nothing and says what to fix:

- Groups, edges and events must be consistent: an edge pointing at a missing group or block, or a missing start event, is a `400`.
- A tool's `Code` blocks and the custom code of its `Set variable` blocks are linted. A `Set variable` that runs on the client is refused, because tools run without a browser.
- `settings.tool.outputSchema` must compile.



## OpenAPI

````yaml /api-reference/specs/controlled-flows/v1.json post /v1/typebots
openapi: 3.0.3
info:
  title: Controlled Flows API
  version: 1.0.0
  description: >-
    Read, build, validate and publish controlled flows and the tools agents
    call.
servers:
  - url: https://api.cloudhumans.com/typebot
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: The workspaces that hold your flows.
  - name: Flows
    description: >-
      Read, create, change, validate and publish flows. Writes land in the
      draft; only a publish makes them live.
  - name: Versions
    description: The saved versions of a flow, and restoring one.
  - name: Credentials
    description: >-
      REST API credentials that HTTP Request blocks send without exposing the
      secret in the flow.
paths:
  /v1/typebots:
    post:
      tags:
        - Flows
      summary: Create a flow
      description: >-
        Creates a flow in a workspace and returns it in full. Only
        `typebot.name` is required; omit `groups`, `edges` and `events` for an
        empty flow with a start event.


        The new flow is a **draft**: agents do not see it until you call
        **Publish a flow**.


        A flow is a conversational flow unless `typebot.settings.general.type`
        is `TOOL` or `CONTEXT_ENRICHMENT`. A `TOOL` needs a `tenant` your token
        grants (otherwise `403`) and a `toolDescription`, and its name must
        contain a letter or a number and be unique inside the tenant (otherwise
        `400`). Its inputs are declared in a `Declare variables` block of
        `groups`; copying the shape from an existing tool read with **Get a
        flow** is the safest way to build one.


        The flow is checked before it is saved, and a refusal saves nothing and
        says what to fix:


        - Groups, edges and events must be consistent: an edge pointing at a
        missing group or block, or a missing start event, is a `400`.

        - A tool's `Code` blocks and the custom code of its `Set variable`
        blocks are linted. A `Set variable` that runs on the client is refused,
        because tools run without a browser.

        - `settings.tool.outputSchema` must compile.
      operationId: createFlow
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - workspaceId
                - typebot
              description: Where to create the flow and what it contains.
              properties:
                workspaceId:
                  type: string
                  description: >-
                    The workspace to create the flow in, e.g.
                    `clx1a2b3c4d5e6f7g8h9`. Get it from **List workspaces**. A
                    workspace your token cannot write to answers 404,
                    indistinguishable from one that does not exist.
                typebot:
                  type: object
                  required:
                    - name
                  description: >-
                    The flow to create. Only `name` is mandatory; everything
                    omitted gets its default.
                  properties:
                    name:
                      type: string
                      description: >-
                        The flow's name. Required. For a TOOL it is the identity
                        agents call: it must contain at least one letter or
                        number and be unique inside the tenant (a collision
                        answers 400).
                    icon:
                      type: string
                      description: An emoji or image URL shown next to the flow name.
                    folderId:
                      type: string
                      nullable: true
                      description: >-
                        The folder to put the flow in. An id that does not exist
                        puts it outside any folder on create; send `null` on
                        update to take it out of its folder.
                    groups:
                      type: array
                      items:
                        type: object
                        additionalProperties: true
                      description: >-
                        The flow's groups, each with its `id`, `title`,
                        `graphCoordinates` and ordered `blocks`. Same shape
                        **Get a flow** returns. Omit for an empty flow. A tool's
                        inputs are the variables of a block of type `Declare
                        variables`.
                    edges:
                      type: array
                      items:
                        type: object
                        additionalProperties: true
                      description: >-
                        The connections between groups and blocks: each has an
                        `id`, a `from` and a `to` pointing at group and block
                        ids that exist in `groups`. Same shape **Get a flow**
                        returns. An edge pointing at a missing group or block
                        answers 400.
                    events:
                      type: array
                      items:
                        type: object
                        additionalProperties: true
                      description: >-
                        The flow's start event, exactly one entry. Same shape
                        **Get a flow** returns. Omit it and a start event is
                        created for you.
                    variables:
                      type: array
                      items:
                        type: object
                        additionalProperties: true
                      description: >-
                        The variables the flow declares, each with an `id` and
                        `name`, and `isInputVariable` true for a tool input
                        declared in a `Declare variables` block. Same shape
                        **Get a flow** returns.
                    settings:
                      type: object
                      additionalProperties: true
                      description: >-
                        The flow's settings. `general.type` is `default`, `TOOL`
                        or `CONTEXT_ENRICHMENT`; for a TOOL, `tool.outputSchema`
                        is a JSON Schema (root `type` `object`) that every
                        answer of the tool must satisfy, allowed only on a TOOL
                        and refused with 400 when it does not compile. Send
                        `{"general": {"type": "TOOL"}}` to create a tool.
                    theme:
                      type: object
                      additionalProperties: true
                      description: The flow's visual theme. Omit for the default theme.
                    selectedThemeTemplateId:
                      type: string
                      nullable: true
                      description: >-
                        The id of the theme template applied to the flow. Null
                        for none.
                    resultsTablePreferences:
                      type: object
                      additionalProperties: true
                      nullable: true
                      description: >-
                        Which columns of the results table are shown. Rarely
                        needed.
                    publicId:
                      type: string
                      nullable: true
                      description: >-
                        The slug of the flow's public URL, lowercase letters,
                        digits and hyphens. Already taken answers 400. Omit it
                        and **Publish a flow** generates one.
                    customDomain:
                      type: string
                      nullable: true
                      description: >-
                        A custom domain for the flow's public URL. One that is
                        already in use answers 400. Rarely needed.
                    tenant:
                      type: string
                      nullable: true
                      description: >-
                        The Claudia tenant that owns a TOOL. Mandatory when the
                        flow is created as a TOOL. For a TOOL it must be a
                        tenant your token grants, otherwise 403; flows that are
                        not tools are not checked. It is the tenant of one of
                        your Claudia projects.
                    toolDescription:
                      type: string
                      nullable: true
                      description: >-
                        What an agent is told the tool does and when to use it.
                        Mandatory when the flow is created as a TOOL. Write it
                        for the agent that will read it: what the tool does,
                        when to call it, what it returns.
      responses:
        '200':
          description: The flow as stored.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlowSaved'
        '400':
          description: >-
            The flow was refused and nothing was created. `message` says why:
            missing name, tenant or tool description on a TOOL, a tool name
            already used in the tenant, a public id or domain already taken, an
            invalid output schema, an inconsistent graph or a script or Set
            variable code that failed the lint.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing, expired or invalid credentials.
        '403':
          description: >-
            The created TOOL's tenant is not one your token grants. Nothing was
            created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            No such workspace, or none your token can write to — the two are
            deliberately indistinguishable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit applied by the API gateway. Back off and retry.
components:
  schemas:
    FlowSaved:
      type: object
      required:
        - typebot
      properties:
        typebot:
          $ref: '#/components/schemas/Flow'
      description: >-
        A flow as stored after a write. Its `updatedAt` is the value to send as
        `typebot.updatedAt` on the next **Update a flow** and as
        `expectedUpdatedAt` on **Publish a flow**.
    Error:
      type: object
      properties:
        message:
          type: string
          description: What went wrong.
        code:
          type: string
          description: Error code, e.g. `NOT_FOUND` or `BAD_REQUEST`.
        issues:
          type: array
          description: Per-field validation problems, present on a 400 for invalid input.
          items:
            type: object
            additionalProperties: true
      required:
        - message
        - code
      description: Something the caller needs to fix.
    Flow:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: string
          description: The flow's internal id.
        name:
          type: string
          description: The flow's name.
        version:
          type: string
          description: 'The flow schema version: `3`, `4`, `5` or `6`.'
        icon:
          nullable: true
          type: string
          description: An emoji or image URL shown next to the flow name.
        folderId:
          nullable: true
          type: string
          description: The folder the flow sits in. Null when it is outside any folder.
        workspaceId:
          type: string
          description: The workspace the flow belongs to.
        publicId:
          nullable: true
          type: string
          description: >-
            The slug in the flow's public URL. Null until one is set. It is NOT
            the internal `id`.
        tenant:
          nullable: true
          type: string
          description: >-
            For a TOOL flow, the Claudia tenant that owns the tool. Null or
            absent for flows that are not tools.
        toolDescription:
          nullable: true
          type: string
          description: >-
            For a TOOL flow, what an agent is told the tool does and when to use
            it. Null or absent for flows that are not tools.
        createdAt:
          type: string
          format: date-time
          description: When the flow was created.
        updatedAt:
          type: string
          format: date-time
          description: When the flow was last changed.
        isArchived:
          type: boolean
          description: True when the flow was archived.
        isClosed:
          type: boolean
          description: True when the flow stopped accepting new conversations.
        groups:
          type: array
          items:
            type: object
            additionalProperties: true
          description: >-
            The flow's groups, each with its `id`, `title` and ordered `blocks`.
            A TOOL's inputs live in a block of type `Declare variables`.
        edges:
          type: array
          items:
            type: object
            additionalProperties: true
          description: >-
            The connections between groups and blocks: each has an `id`, a
            `from` and a `to` pointing at group and block ids.
        events:
          nullable: true
          type: array
          items:
            type: object
            additionalProperties: true
          description: >-
            The flow's start event(s). Null on flows saved with an older schema
            version.
        variables:
          type: array
          items:
            type: object
            additionalProperties: true
          description: >-
            The variables the flow declares, each with an `id` and `name`, and
            `isInputVariable` true when it is a tool input declared in a
            `Declare variables` block.
        settings:
          type: object
          additionalProperties: true
          description: >-
            The flow's settings. `general.type` is `default`, `TOOL` or
            `CONTEXT_ENRICHMENT`. For a TOOL, `tool.outputSchema` is a JSON
            Schema (root `type` `object`) that every answer of the tool must
            satisfy; it is absent when the tool answers with untyped text.
      description: A flow with its full definition.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.