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

# Replace workflow

> Replaces the workflow completely — there is no partial update. The body
may be the workflow object itself or wrapped as `{"workflow": {...}}`.
Send `{"workflow": null}` to remove the workflow; the agent then runs as a
single-prompt agent again.

The workflow is validated against the same rules the voice runtime
enforces. An invalid workflow is rejected with `400 VALIDATION_ERROR`
listing every problem found, and nothing is written.




## OpenAPI

````yaml put /v1/agents/{agentId}/workflow
openapi: 3.1.0
info:
  title: TalkPilot API
  version: 1.0.0
  description: >
    The TalkPilot API allows you to programmatically manage your call center
    agents,

    employees, forwarding slots, knowledge base, and more.


    ## Authentication


    All API requests require an API key passed via the `X-API-Key` header:


    ```

    X-API-Key: tp_live_abc123def456...

    ```


    An API key can reach every organization its creator is a member of (see

    `GET /v1/organization`) and can be restricted to specific agents and
    permissions.

    Create and manage keys in the TalkPilot Dashboard under **Settings > API**

    (Dev-Admin only).


    ## Rate Limiting


    Default limits per API key: **60 requests/minute** and **1,000
    requests/hour**

    (both enforced, both configurable per key).


    Rate limit headers are included in every response to a request authenticated

    with an API key (Dashboard JWT requests are not rate limited):

    - `X-RateLimit-Limit` — Max requests per minute

    - `X-RateLimit-Remaining` — Remaining requests in the current minute window

    - `X-RateLimit-Reset` — Unix timestamp roughly 60 seconds in the future


    When rate limited, the API returns `429 Too Many Requests` with
    `Retry-After: 60`

    (minute window) or `Retry-After: 3600` (hour window).


    ## Pagination


    List endpoints support pagination via query parameters:

    - `page` — Page number (default: 1)

    - `limit` — Items per page (default: 20, max: 100)


    Paginated responses include a `pagination` object with `page`, `limit`,
    `total`, and `pages`.


    ## Error Format


    All errors follow a consistent format:


    ```json

    {
      "error": {
        "code": "VALIDATION_ERROR",
        "message": "Human-readable description",
        "details": [{ "field": "name", "message": "Required" }],
        "request_id": "req_abc123"
      }
    }

    ```
  contact:
    name: TalkPilot Support
    email: support@talkpilot.io
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.talkpilot.io
    description: Production
security:
  - apiKey: []
tags:
  - name: Health
    description: API health and status
  - name: Agents
    description: Manage AI agent configurations
  - name: Workflow
    description: Multi-state conversation flow of an agent
  - name: Tools
    description: Manage agent tools (HTTP requests, call transfers, etc.)
  - name: Employees
    description: Manage employees linked to agents
  - name: Contacts
    description: >-
      Customer contacts (customer_database) per agent — the voice agent
      recognises callers and greets them by name or tag from here
  - name: Forwarding Slots
    description: Manage call forwarding slot assignments
  - name: Knowledge Base
    description: Manage agent knowledge base documents
  - name: Calls
    description: Read call records and transcripts
  - name: Organization
    description: Organization-level settings
  - name: API Keys
    description: Manage API keys (Dashboard JWT auth only; dev_admin)
paths:
  /v1/agents/{agentId}/workflow:
    put:
      tags:
        - Workflow
      summary: Replace workflow
      description: >
        Replaces the workflow completely — there is no partial update. The body

        may be the workflow object itself or wrapped as `{"workflow": {...}}`.

        Send `{"workflow": null}` to remove the workflow; the agent then runs as
        a

        single-prompt agent again.


        The workflow is validated against the same rules the voice runtime

        enforces. An invalid workflow is rejected with `400 VALIDATION_ERROR`

        listing every problem found, and nothing is written.
      operationId: replaceWorkflow
      parameters:
        - $ref: '#/components/parameters/AgentId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Workflow'
                - type: object
                  required:
                    - workflow
                  properties:
                    workflow:
                      oneOf:
                        - $ref: '#/components/schemas/Workflow'
                        - type: 'null'
            examples:
              replace:
                summary: Replace the flow
                value:
                  name: Inbound Call Flow
                  description: intent_analysis routes, callback_info is terminal.
                  steps:
                    - id: intent_analysis
                      name: Anruf-Analyse
                      description: Erkenne das Anliegen und route weiter.
                      completion: Anliegen erkannt und weitergeleitet.
                      step_type: prompt
                      next:
                        - id: callback_info
                    - id: callback_info
                      name: Rückruf-Daten aufnehmen
                      description: Nimm die fehlenden Pflichtangaben auf.
                      completion: Daten erfasst, Anruf beendet.
                      step_type: prompt
                      next: []
              clear:
                summary: Remove the workflow
                value:
                  workflow: null
      responses:
        '200':
          description: Stored workflow
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    AgentId:
      name: agentId
      in: path
      required: true
      description: Agent UUID
      schema:
        type: string
        format: uuid
  schemas:
    Workflow:
      type: object
      required:
        - name
        - steps
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        description:
          type:
            - string
            - 'null'
          maxLength: 500
        steps:
          type: array
          minItems: 1
          maxItems: 20
          items:
            $ref: '#/components/schemas/WorkflowStep'
    WorkflowResponse:
      type: object
      properties:
        agent_id:
          type: string
          format: uuid
        workflow:
          oneOf:
            - $ref: '#/components/schemas/Workflow'
            - type: 'null'
        updated_at:
          type: string
          format: date-time
    WorkflowStep:
      type: object
      required:
        - id
        - name
        - description
        - completion
      properties:
        id:
          type: string
          minLength: 1
          maxLength: 50
          description: Unique within the workflow
        name:
          type: string
          minLength: 1
          maxLength: 100
        description:
          type: string
          minLength: 1
          maxLength: 20000
          description: The instructions for this state
        completion:
          type: string
          minLength: 1
          maxLength: 500
          description: When this state counts as done
        step_type:
          type: string
          enum:
            - prompt
            - action
          default: prompt
        tools:
          type: array
          maxItems: 20
          items:
            type: string
          description: Tool names available in this state
        next:
          type: array
          maxItems: 10
          items:
            $ref: '#/components/schemas/WorkflowNextEdge'
          description: Allowed follow-up states
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              enum:
                - VALIDATION_ERROR
                - UNAUTHORIZED
                - FORBIDDEN
                - AGENT_NOT_ACCESSIBLE
                - NOT_FOUND
                - CONFLICT
                - RATE_LIMITED
                - INTERNAL_ERROR
            message:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  field:
                    type: string
                  message:
                    type: string
            request_id:
              type: string
    WorkflowNextEdge:
      type: object
      required:
        - id
      properties:
        id:
          type: string
          description: Must reference an existing step id
  responses:
    ValidationError:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: VALIDATION_ERROR
              message: Invalid request body
              details:
                - field: llm_temperature
                  message: Must be between 0 and 2
              request_id: req_abc123
    Unauthorized:
      description: Missing or invalid authentication
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: UNAUTHORIZED
              message: Invalid or missing API key
              request_id: req_abc123
    Forbidden:
      description: >
        Insufficient permissions (`FORBIDDEN`), or the agent is outside the
        key's

        `allowed_agent_ids` (`AGENT_NOT_ACCESSIBLE`)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            missingPermission:
              value:
                error:
                  code: FORBIDDEN
                  message: 'API key lacks required permission: agents:write'
                  request_id: req_abc123
            agentNotAccessible:
              value:
                error:
                  code: AGENT_NOT_ACCESSIBLE
                  message: API key does not have access to this agent
                  request_id: req_abc123
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: NOT_FOUND
              message: Agent not found
              request_id: req_abc123
    RateLimited:
      description: Too many requests for this API key (60/minute or 1,000/hour by default)
      headers:
        Retry-After:
          description: >-
            Seconds to wait before retrying — 60 for the minute window, 3600 for
            the hour window
          schema:
            type: integer
        X-RateLimit-Limit:
          schema:
            type: integer
        X-RateLimit-Remaining:
          schema:
            type: integer
        X-RateLimit-Reset:
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: RATE_LIMITED
              message: Rate limit exceeded. Try again in 60 seconds.
              request_id: req_abc123
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: |
        API key for external access. Format: `tp_live_<32-hex-chars>`.
        Create keys in the TalkPilot Dashboard under Settings > API.

````