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

# Create Block

> Create a new block in a workflow.

Add a new block to a workflow's draft graph.

The create route is flat: send `workflow_id` in the request body.

You provide the block ID — it must be unique within the workflow. Pick something descriptive (e.g. `extract-invoice`, `classifier-language`) so edges and assertions stay readable.

The `config` shape depends on `type`. See [Workflow Blocks](/workflows/Blocks) for the per-type config reference.

A few invariants the API enforces:

* Input blocks (`start_document`, `start_json`) cannot be placed inside containers — `parent_id` must be `null` for them.
* `parent_id` is reserved for placing blocks inside container blocks (`while_loop`, `for_each`).

<RequestExample>
  ```python Python theme={null}
  from retab import Retab

  client = Retab()

  # A typical extract block with a JSON schema config
  block = client.workflows.blocks.create(
      workflow_id="wf_abc123xyz",
      id="extract-1",
      type="extract",
      label="Extract Invoice Fields",
      position_x=320,
      position_y=0,
      config={
          "model": "gpt-5",
          "json_schema": {
              "type": "object",
              "properties": {
                  "invoice_number": {"type": "string"},
                  "total": {"type": "number"},
              },
          },
      },
  )

  print(block.id)
  ```

  ```typescript TypeScript theme={null}
  import { Retab } from "@retab/node";

  const client = new Retab({ apiKey: process.env.RETAB_API_KEY });

  const block = await client.workflows.blocks.create("wf_abc123xyz", "extract", "extract-1", "Extract Invoice Fields", 320, 0, undefined, undefined, {
      model: "retab-small",
      json_schema: {
        type: "object",
        properties: {
          invoice_number: { type: "string" },
          total: { type: "number" },
        },
      },
    });

  console.log(block.id);
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	retab "github.com/retab-dev/retab/clients/go"
  )

  func ptr[T any](v T) *T { return &v }

  func main() {
  	ctx := context.Background()

  	client, err := retab.NewClient("")
  	if err != nil {
  		log.Fatal(err)
  	}

  	block, err := client.Workflows.Blocks.Create(ctx, &retab.WorkflowBlocksCreateParams{
  		WorkflowID: "wf_abc123xyz",
  		ID:         ptr("extract-1"),
  		Type:      "extract",
  		Label:     ptr("Extract Invoice Fields"),
  		PositionX: ptr(320.0),
  		PositionY: ptr(0.0),
  		Config: &map[string]any{
  			"model": "gpt-5",
  			"json_schema": map[string]any{
  				"type": "object",
  				"properties": map[string]any{
  					"invoice_number": map[string]any{"type": "string"},
  					"total":          map[string]any{"type": "number"},
  				},
  			},
  		},
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

  	fmt.Println(block.ID)
  }
  ```

  ```ruby Ruby theme={null}
  require 'retab'

  client = Retab::Client.new(api_key: ENV['RETAB_API_KEY'])

  block = client.workflows.blocks.create(
    workflow_id: 'wf_abc123xyz',
    id: 'extract-1',
    type: 'extract',
    label: 'Extract Invoice Fields',
    position_x: 320,
    position_y: 0,
    config: {
      model: 'gpt-5',
      json_schema: {
        type: 'object',
        properties: {
          invoice_number: { type: 'string' },
          total: { type: 'number' },
        },
      },
    },
  )

  puts block.id
  ```

  ```rust Rust theme={null}
  use retab::enums::WorkflowBlockCreateRequestType;
  use retab::models::WorkflowBlockCreateRequest;
  use retab::resources::workflow_blocks::CreateParams;
  use retab::Retab;
  use serde_json::json;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);

      let config = serde_json::from_value(json!({
          "model": "gpt-5",
          "json_schema": {
              "type": "object",
              "properties": {
                  "invoice_number": {"type": "string"},
                  "total": {"type": "number"},
              },
          },
      }))?;

      let block = client
          .workflows().blocks()
          .create(CreateParams::new(WorkflowBlockCreateRequest {
              workflow_id: "wf_abc123xyz".into(),
              id: Some("extract-1".into()),
              type_: WorkflowBlockCreateRequestType::Extract,
              label: Some("Extract Invoice Fields".into()),
              position_x: Some(320.0),
              position_y: Some(0.0),
              width: None,
              height: None,
              config: Some(config),
              parent_id: None,
          }))
          .await?;

      println!("{}", block.id);
      Ok(())
  }
  ```

  ```php PHP theme={null}
  <?php
  require 'vendor/autoload.php';

  use Retab\Client;
  use Retab\Resource\WorkflowBlockCreateRequestType;

  $client = new Client(apiKey: getenv('RETAB_API_KEY'));

  $result = $client->workflows()->blocks()->create(
      workflowId: 'wf_abc123',
      type: WorkflowBlockCreateRequestType::Extract,
      id: 'extract-1',
      label: 'Extract Invoice Fields',
  );
  print_r($result);
  ```

  ```csharp C# theme={null}
  using Retab;
  using RetabClient = Retab.Retab;

  var apiKey = Environment.GetEnvironmentVariable("RETAB_API_KEY")!;
  var client = new RetabClient(apiKey);

  var result = await client.Workflows.Blocks.CreateAsync(new WorkflowBlocksCreateOptions());
  Console.WriteLine(result);
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;

  public final class Example {
    public static void main(String[] args) throws Exception {
      RetabClient client = new RetabClient(System.getenv("RETAB_API_KEY"));

      var result = client.workflows().blocks().create("wf_abc123", null, null, null, null, null, null, null, null, null);
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  curl -X 'POST' \
    'https://api.retab.com/v1/workflows/blocks' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <your-api-key>' \
    -d '{
      "workflow_id": "wf_abc123xyz",
      "id": "extract-1",
      "type": "extract",
      "label": "Extract Invoice Fields",
      "position_x": 320,
      "position_y": 0,
      "config": {
        "model": "gpt-5",
        "json_schema": {
          "type": "object",
          "properties": {
            "invoice_number": {"type": "string"},
            "total": {"type": "number"}
          }
        }
      }
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": "extract-1",
    "workflow_id": "wf_abc123xyz",
    "type": "extract",
    "label": "Extract Invoice Fields",
    "position_x": 320,
    "position_y": 0,
    "width": null,
    "height": null,
    "config": {
      "model": "gpt-5",
      "json_schema": {
        "type": "object",
        "properties": {
          "invoice_number": { "type": "string" },
          "total": { "type": "number" }
        }
      }
    },
    "parent_id": null,
    "updated_at": "2026-05-01T14:30:00Z"
  }
  ```

  ```json 400 theme={null}
  {
    "detail": "Input blocks (start_document, start_json) cannot be placed inside containers"
  }
  ```

  ```json 404 theme={null}
  {
    "detail": "Workflow not found"
  }
  ```

  ```json 409 theme={null}
  {
    "detail": "Block ID 'extract-1' already exists"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/workflows/blocks
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/workflows/blocks:
    post:
      tags:
        - Workflows
        - Workflow Blocks
      summary: Create Block
      description: Create a new block in a workflow.
      operationId: create_block
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWorkflowBlockRequest'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowBlock'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    CreateWorkflowBlockRequest:
      properties:
        workflow_id:
          type: string
          title: Workflow Id
          description: Workflow to create the block in.
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
          description: >-
            Block ID. Omit to let the server generate one (recommended). Block
            IDs must be unique across your organization, not just within a
            workflow — reusing a custom id like 'block_extract' in more than one
            workflow fails with 409.
        type:
          type: string
          enum:
            - start_document
            - start_json
            - note
            - parse
            - edit
            - extract
            - split
            - classifier
            - conditional
            - api_call
            - function
            - while_loop
            - for_each
            - merge_dicts
          title: Type
          description: Block type
        label:
          type: string
          maxLength: 200
          title: Label
          description: Display label
          default: ''
        position_x:
          type: number
          title: Position X
          description: X position
          default: 0
        position_y:
          type: number
          title: Position Y
          description: Y position
          default: 0
        width:
          anyOf:
            - type: number
            - type: 'null'
          title: Width
          description: Block width
        height:
          anyOf:
            - type: number
            - type: 'null'
          title: Height
          description: Block height
        config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Config
          description: Block configuration
        parent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Parent Id
          description: ID of parent container block (while_loop, for_each)
      type: object
      required:
        - type
        - workflow_id
      title: CreateWorkflowBlockRequest
      description: Create a new block in a workflow.
    WorkflowBlock:
      properties:
        id:
          type: string
          title: Id
        workflow_id:
          type: string
          title: Workflow Id
          description: Foreign key to workflow
        type:
          type: string
          enum:
            - start_document
            - start_json
            - note
            - parse
            - edit
            - extract
            - split
            - classifier
            - conditional
            - api_call
            - function
            - while_loop
            - for_each
            - merge_dicts
            - while_loop_sentinel_start
            - while_loop_sentinel_end
            - for_each_sentinel_start
            - for_each_sentinel_end
          title: Type
          description: Block type (extract, parse, classifier, etc.)
        label:
          type: string
          title: Label
          description: Display label for the block
          default: ''
        position_x:
          type: number
          title: Position X
          description: X position on canvas
          default: 0
        position_y:
          type: number
          title: Position Y
          description: Y position on canvas
          default: 0
        width:
          anyOf:
            - type: number
            - type: 'null'
          title: Width
          description: Block width for resizable blocks
        height:
          anyOf:
            - type: number
            - type: 'null'
          title: Height
          description: Block height for resizable blocks
        config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Config
          description: Block-specific configuration
        parent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Parent Id
          description: ID of parent container (while_loop, for_each)
        declarative_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Declarative Path
          description: Canonical declarative block path used to reconcile imported specs.
        declarative_source_block_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Declarative Source Block Id
          description: Authored declarative block id before import-time id regeneration.
        updated_at:
          type: string
          format: date-time
          title: Updated At
        resolved_schemas:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Resolved Schemas
          description: Schemas resolved for this block from the workflow graph.
      type: object
      required:
        - id
        - type
        - updated_at
        - workflow_id
      title: WorkflowBlock
      description: Public live workflow block object.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
          default: null
        ctx:
          type: object
          title: Context
          default: {}
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````