> ## 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 Edge

> Create a new edge connecting two blocks.

Validates that:
- Both source and target blocks exist in the workflow
- The connection is semantically valid (type compatibility, container rules, etc.)

Connect two blocks by creating an edge.

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

You provide the edge ID — it must be unique within the workflow. Use a readable convention (e.g. `edge-start-to-extract`) so the graph stays inspectable.

`source_handle` and `target_handle` reference handles declared by each block. The handle naming convention is direction + slot:

* `output-file-0`, `output-json-0`, `output-file-booking-confirmation`, `output-json-needs-review`, …
* `input-file-0`, `input-json-0`, …

Dynamic split/classifier/conditional outputs use the route `handle_key`, not
the display label. Inspect the source block before wiring those edges.

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

  client = Retab()

  edge = client.workflows.edges.create(
      workflow_id="wf_abc123xyz",
      id="edge-start-to-extract",
      source_block="start-1",
      target_block="extract-1",
      source_handle="output-file-0",
      target_handle="input-file-0",
  )

  print(edge.id)
  ```

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

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

  const edge = await client.workflows.edges.create("wf_abc123xyz", "start-1", "extract-1", "edge-start-to-extract", "output-file-0", "input-file-0");

  console.log(edge.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)
  	}

  	edge, err := client.Workflows.Edges.Create(ctx, &retab.WorkflowEdgesCreateParams{
  		WorkflowID:    "wf_abc123xyz",
  		ID:            ptr("edge-start-to-extract"),
  		SourceBlock:  "start-1",
  		TargetBlock:  "extract-1",
  		SourceHandle: ptr("output-file-0"),
  		TargetHandle: ptr("input-file-0"),
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

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

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

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

  edge = client.workflows.edges.create(
    workflow_id: 'wf_abc123xyz',
    id: 'edge-start-to-extract',
    source_block: 'start-1',
    target_block: 'extract-1',
    source_handle: 'output-file-0',
    target_handle: 'input-file-0',
  )

  puts edge.id
  ```

  ```rust Rust theme={null}
  use retab::models::WorkflowEdgeCreateRequest;
  use retab::resources::workflow_edges::CreateParams;
  use retab::Retab;

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

      let edge = client
          .workflows().edges()
          .create(CreateParams::new(WorkflowEdgeCreateRequest {
              workflow_id: "wf_abc123xyz".into(),
              id: Some("edge-start-to-extract".into()),
              source_block: "start-1".into(),
              target_block: "extract-1".into(),
              source_handle: Some("output-file-0".into()),
              target_handle: Some("input-file-0".into()),
          }))
          .await?;

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

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

  use Retab\Client;

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

  $result = $client->workflows()->edges()->create(
      workflowId: 'wf_abc123',
      sourceBlock: 'value',
      targetBlock: 'value',
  );
  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.Edges.CreateAsync(new WorkflowEdgesCreateOptions());
  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().edges().create("wf_abc123", null, null, null, null, null);
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  curl -X 'POST' \
    'https://api.retab.com/v1/workflows/edges' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <your-api-key>' \
    -d '{
      "workflow_id": "wf_abc123xyz",
      "id": "edge-start-to-extract",
      "source_block": "start-1",
      "target_block": "extract-1",
      "source_handle": "output-file-0",
      "target_handle": "input-file-0"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": "edge-start-to-extract",
    "workflow_id": "wf_abc123xyz",
    "source_block": "start-1",
    "target_block": "extract-1",
    "source_handle": "output-file-0",
    "target_handle": "input-file-0",
    "updated_at": "2026-05-01T14:30:00Z"
  }
  ```

  ```json 400 theme={null}
  {
    "detail": "Source or target block does not exist in this workflow"
  }
  ```

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

  ```json 409 theme={null}
  {
    "detail": "Edge ID already exists in this workflow"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/workflows/edges
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/workflows/edges:
    post:
      tags:
        - Workflows
        - Workflow Edges
      summary: Create Edge
      description: >-
        Create a new edge connecting two blocks.


        Validates that:

        - Both source and target blocks exist in the workflow

        - The connection is semantically valid (type compatibility, container
        rules, etc.)
      operationId: create_edge
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWorkflowEdgeRequest'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowEdge'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    CreateWorkflowEdgeRequest:
      properties:
        workflow_id:
          type: string
          title: Workflow Id
          description: Workflow to create the edge in.
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
          description: Edge ID. Omit to let the server generate one (recommended).
        source_block:
          type: string
          title: Source Block
          description: Source block ID
        target_block:
          type: string
          title: Target Block
          description: Target block ID
        source_handle:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Handle
          description: Output handle
        target_handle:
          anyOf:
            - type: string
            - type: 'null'
          title: Target Handle
          description: Input handle
      type: object
      required:
        - source_block
        - target_block
        - workflow_id
      title: CreateWorkflowEdgeRequest
      description: Create a new edge connecting two blocks in a workflow.
    WorkflowEdge:
      properties:
        id:
          type: string
          title: Id
        workflow_id:
          type: string
          title: Workflow Id
          description: Foreign key to workflow
        source_block:
          type: string
          title: Source Block
          description: ID of the source block
        target_block:
          type: string
          title: Target Block
          description: ID of the target block
        source_handle:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Handle
          description: Output handle on source block
        target_handle:
          anyOf:
            - type: string
            - type: 'null'
          title: Target Handle
          description: Input handle on target block
        updated_at:
          type: string
          format: date-time
          title: Updated At
      type: object
      required:
        - id
        - source_block
        - target_block
        - updated_at
        - workflow_id
      title: WorkflowEdge
      description: Public live workflow edge 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

````