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

# Add a Tool Contract Revision

> Requires tools:update. Adds one immutable revision to a saved tool that was created through the earlier tool endpoints, so it can be used inside a workflow. Send the revision number you last read as expected_revision (null when the tool has none yet); if another writer has added a revision since, nothing is written. Name, description and private endpoint configuration come from the saved tool and are refused if sent. Transfer tools always come back restricted to a live call on a phone, whatever the request asked for. Previously published workflows keep the exact revision they pinned.


Requires `tools:update`. Adds one immutable contract revision to a tool that was created through the earlier tool endpoints, so a workflow can use it. Only tools that call your own endpoint, or transfer a call, can take one — anything else returns `422 WORKFLOW_TOOL_IMPORT_REQUIRED`.

```bash theme={null}
curl -X POST https://api.goyappr.com/tools/TOOL_ID/workflow-revisions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-company-id: COMPANY_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "expected_revision": 3,
    "contract": {
      "input_schema": { "type": "object", "properties": { "order_id": { "type": "string" } }, "required": ["order_id"] },
      "output_schema": { "type": "object", "properties": { "status": { "type": "string" } } },
      "allowed_phases": ["during"],
      "allowed_channels": ["phone", "web"],
      "timeout_ms": 20000
    }
  }'
```

| Field | Required | Notes |
| - | - | - |
| `expected_revision` | yes | The highest `revision` you last read, or `null` when the tool has none yet. If another writer added a revision in the meantime, nothing is written and you get `409 WORKFLOW_CONFLICT`. |
| `contract.input_schema` | yes | Must be an object. |
| `contract.output_schema` | yes | Must be an object. |
| `contract.allowed_phases` | no | Any of `before`, `during`, `after`. Defaults to all three. |
| `contract.allowed_channels` | no | `phone`, `web`, or both. Defaults to both. |
| `contract.timeout_ms` | no | Defaults to 30000. |
| `contract.effect` | no | Defaults to `write`. |
| `contract.replay_safe` | no | Defaults to `false`. |
| `contract.include_call_context` | no | Defaults to `true`. Send `false` to stop this tool's requests carrying `call`. Anything other than `true` or `false` is `400 WORKFLOW_REQUEST_INVALID`, and sending `true` records nothing — the revision comes back without the field, exactly as it did before the field existed. |

No other property is accepted — an unexpected key is `400 WORKFLOW_REQUEST_INVALID`, with the key in `issues[0].path` (`/name`); so is a missing `contract` (`/contract`) or a bad `expected_revision` (`/expected_revision`). Name, description and the private endpoint configuration come from the saved tool and cannot be set here.

Transfer tools always come back restricted to a live call on a phone, and marked as ending the call, whatever the request asked for. Revisions are immutable and additive: workflows that already pinned an earlier revision keep it until they are published again.

## What your endpoint receives

A request Yappr makes to this tool's endpoint carries the call it is serving, as one `call`
member alongside your declared inputs:

```json theme={null}
{
  "order_id": "A-1042",
  "call": {
    "version": "1",
    "phase": "during",
    "company_id": "6c0f…",
    "agent_id": "efb4…",
    "agent_name": "Reception",
    "call_id": "9a71…",
    "call_direction": "inbound",
    "caller_number": "+972500000001",
    "callee_number": "+972500000002",
    "call_metadata": { "source": "ads" },
    "call_variables": { "first_name": "Dana" },
    "channel": "phone",
    "started_at": "2026-09-16T08:00:00Z"
  }
}
```

One definition, one version. The member is sent on every request to your own endpoint — a
before-call request, a tool the agent uses mid-call, a follow-up after the call ends, and a
[tool test](https://docs.goyappr.com/api-reference/tools/test.md) alike. A connected-app action and a transfer do not
receive the whole object; they read the same values through `{{call.field}}` in what you
configured, so there is still one definition to learn.

Turn it off for one tool with `"include_call_context": false` in the contract. Your mapped
inputs are unaffected: a fixed input that quotes `{{call.caller_number}}` still arrives filled
in, because that is a value you asked for rather than the whole call.

**Read `phase` first.** The package is graded by what that moment can know, and a member the
phase cannot know is absent rather than null — so a missing `call_id` means there is no call
yet, while `"caller_number": ""` means the call had no number to give (a browser call, or the
preview gap above).

| Phase | What it adds |
| - | - |
| `before` | The workspace, the agent, the direction, both numbers, the request's `call_metadata` and `call_variables`, and the `channel`. No `call_id`: the call does not exist yet, so nothing that lives on the call row — including `phone_number_id`, `lead_id` and `status` — is present either. |
| `during` | `call_id`, `started_at`, `status` (the call's live state — e.g. `"ringing"`, `"in_progress"` — not the signal it has stopped), and `phone_number_id` / `lead_id` when the call has them. |
| `after` | `ended_at`, `duration_seconds`, `ended_by`, `close_reason`, and each result as it becomes ready: `transcript`, `analysis`, `recording_url`, `lead`, `disposition`, `billing`. |

The nine members Yappr's webhook tools have always sent — `company_id`, `agent_id`,
`agent_name`, `call_id`, `call_direction`, `caller_number`, `callee_number`, `call_metadata`
and `call_variables` — keep their names and their empty-string and empty-object convention
inside `call`, so an endpoint written against that payload keeps parsing. A declared input of
your own named `call` wins over the package.

A tool test sends the same shape with `"test": true` inside `call`, so your endpoint can tell
a rehearsal from a call. A real call never carries that member. A test serves no call and no
agent, so its `call_id` (from the `during` phase on) and `agent_id` are `null`, not `""`.

The full field list is the `CallPackage` schema in the OpenAPI document.


## OpenAPI

````yaml POST /tools/{id}/workflow-revisions
openapi: 3.1.0
info:
  title: Yappr API
  description: >
    Create and manage AI voice agents, purchase phone numbers, configure tools,
    and initiate calls — all via REST.
  version: 1.0.0
  contact:
    url: https://goyappr.com
servers:
  - url: https://api.goyappr.com
    description: Production
security:
  - apiKey: []
paths:
  /tools/{id}/workflow-revisions:
    parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: header
        name: x-company-id
        schema:
          type: string
          format: uuid
        description: >-
          Explicit active workspace. Optional; when sent it must be the API
          key's own workspace — any other value is refused with 403
          WORKSPACE_MISMATCH.
    post:
      tags:
        - Tools
      summary: Add a contract revision to a tool
      description: >
        Requires tools:update. Adds one immutable revision to a saved tool that
        was created through the earlier tool endpoints, so it can be used inside
        a workflow. Send the revision number you last read as expected_revision
        (null when the tool has none yet); if another writer has added a
        revision since, nothing is written. Name, description and private
        endpoint configuration come from the saved tool and are refused if sent.
        Transfer tools always come back restricted to a live call on a phone,
        whatever the request asked for. Previously published workflows keep the
        exact revision they pinned.
      operationId: createWorkflowToolRevision
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkflowToolContractRevisionCreate'
      responses:
        '201':
          description: The new revision.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowToolContractRevision'
        '400':
          description: >-
            WORKFLOW_REQUEST_INVALID — the body has an unexpected property, a
            missing or non-object input_schema/output_schema, an
            include_call_context that is not true or false, or an
            expected_revision that is neither null nor a positive whole number.
            For an unexpected property, a missing or non-object contract, or a
            bad expected_revision, issues[] names the field by path (/<field>,
            /contract, /expected_revision).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '401':
          description: >-
            MISSING_KEY, INVALID_KEY or EXPIRED_KEY - the key was not accepted.
            A valid key without the scope this operation needs is 403
            INSUFFICIENT_SCOPE, naming the scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >
            WORKSPACE_MISMATCH — `x-company-id` named a workspace other than the
            one this API key belongs to.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            WORKFLOW_NOT_FOUND — no such tool in this workspace.
            WORKFLOW_TOOL_ARCHIVED — it is archived, and takes no revision until
            it is restored with POST /tools/{id}/restore, which the message
            names.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '409':
          description: >-
            WORKFLOW_CONFLICT — expected_revision is not the tool's current
            revision. Re-read the list and send the highest revision you see.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '422':
          description: >-
            WORKFLOW_TOOL_IMPORT_REQUIRED — this tool's type cannot take a
            contract revision. Only tools that call your own endpoint, or
            transfer a call, can.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '503':
          description: WORKFLOW_STORAGE_UNAVAILABLE — temporary; retry the same request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
components:
  schemas:
    WorkflowToolContractRevisionCreate:
      type: object
      additionalProperties: false
      required:
        - expected_revision
        - contract
      description: >
        Exactly these two properties are accepted; any other property is
        rejected. Identity, description and private endpoint configuration are
        read from the saved tool and cannot be supplied here.
      properties:
        expected_revision:
          type:
            - integer
            - 'null'
          minimum: 1
          description: >-
            The highest revision you last read for this tool, or null when the
            tool has no revision yet. A mismatch is a conflict and nothing is
            written.
        contract:
          type: object
          additionalProperties: false
          required:
            - input_schema
            - output_schema
          properties:
            input_schema:
              type: object
              additionalProperties: true
            output_schema:
              type: object
              additionalProperties: true
            allowed_phases:
              type: array
              items:
                type: string
                enum:
                  - before
                  - during
                  - after
            allowed_channels:
              type: array
              items:
                enum:
                  - phone
                  - web
                type: string
            timeout_ms:
              type: integer
            effect:
              type: string
            replay_safe:
              type: boolean
            include_call_context:
              type: boolean
              default: true
              description: >
                Send false to stop this tool's requests carrying the call under
                `call`. Anything other than true or false is rejected; sending
                true is the same as not sending it, and the revision records
                nothing.
    WorkflowToolContractRevision:
      type: object
      description: >
        One immutable contract revision of a saved tool. Private endpoint
        configuration (URL, header values, transfer destination) is never
        included: it stays on the tool itself and is supplied by Yappr at call
        time.
      required:
        - id
        - tool_id
        - revision
        - name
        - kind
        - input_schema
        - output_schema
      properties:
        id:
          type: string
          format: uuid
        tool_id:
          type: string
          format: uuid
        revision:
          type: integer
          minimum: 1
          description: >-
            Increments by one per revision of this tool. Use the highest value
            as expected_revision for the next write.
        created_at:
          type: string
          format: date-time
          description: When this revision was made. On every row of the list.
        name:
          type: string
          description: Copied from the saved tool. It cannot be set through this endpoint.
        description:
          type: string
        kind:
          type: string
          enum:
            - http
            - transfer
          description: >-
            Derived from the saved tool's own type; it cannot be set through
            this endpoint.
        input_schema:
          type: object
          additionalProperties: true
        output_schema:
          type: object
          additionalProperties: true
        allowed_phases:
          type: array
          items:
            type: string
            enum:
              - before
              - during
              - after
          description: >-
            Defaults to all three. Transfer tools are always ["during"],
            whatever you send.
        allowed_channels:
          type: array
          items:
            enum:
              - phone
              - web
            type: string
          description: >-
            Defaults to both. Transfer tools are always ["phone"], whatever you
            send.
        timeout_ms:
          type: integer
          default: 30000
        effect:
          type: string
          description: >-
            Defaults to "write". Transfer tools are always "terminal", whatever
            you send.
        replay_safe:
          type: boolean
          default: false
          description: Transfer tools are always false, whatever you send.
        include_call_context:
          type: boolean
          default: true
          description: >
            Whether every request this tool makes carries the call under `call`
            (see CallPackage). Returned only when it is false, because true is
            what every tool does unless you say otherwise. Turn it off for an
            endpoint that wants nothing but the inputs you mapped; the inputs
            themselves still read the call through {{call.field}} either way.
    WorkflowError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          required:
            - code
          properties:
            error:
              type: string
            code:
              type: string
            warnings:
              type: array
              description: >
                On WORKFLOW_VALIDATION_FAILED from Check or publish, the
                advisories beside the issues, in the shape of
                WorkflowValidation's warnings - strict_off_guidance when
                strict_mode is off, and every advisory about a binding or an
                input. The compiler's own graph advisories
                (during_output_advisory, sequence_branch_advisory,
                before_reference_missing_fallback, override_needs_strict,
                after_ending_coverage, after_any_end_waits,
                before_budget_inbound) arrive once the document compiles.
              items:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  path:
                    type: string
                    maxLength: 1000
                  node_id:
                    type: string
                    maxLength: 64
                  label:
                    type: string
                    maxLength: 200
                    description: The step's label. Present only with node_id.
                  tool_name:
                    type: string
                    maxLength: 200
                  field:
                    type: string
                    maxLength: 200
            issues:
              type: array
              maxItems: 100
              items:
                type: object
                required:
                  - code
                  - path
                  - message
                properties:
                  code:
                    type: string
                    maxLength: 100
                  path:
                    type: string
                    maxLength: 1000
                  message:
                    type: string
                    maxLength: 2000
                  node_id:
                    type: string
                    maxLength: 64
                    description: >-
                      The step the issue belongs to - a conversation step, a
                      before-call step, a follow-up or a step inside a sequence,
                      by its `id`. An issue about a binding names the first step
                      that runs or offers it; absent only when no single step is
                      concerned (a binding no step uses, a schema).
                  label:
                    type: string
                    maxLength: 200
                    description: >-
                      That step's label, as the workflow document spells it - on
                      every code. Present only with `node_id`.
                  tool_name:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about a binding, the name of the tool it runs.
                      `label` is never the tool's name.
                  field:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about one input of a binding
                      (`/bindings/{n}/inputs/{field}`), that input's name.
    Error:
      type: object
      required:
        - error
        - code
      description: >
        Every error response - the secret-key API and the browser data plane
        alike - carries a

        human-readable `error` and a stable machine `code`, and a refusal that
        names what is

        wrong with the request carries `issues[]` too. Branch on `code`, never
        on the `error`

        text. A refusal that names nothing more specific carries the code its
        status means:

        `BAD_REQUEST` (400), `UNAUTHORIZED` (401, the browser data plane; the
        secret-key API

        answers `MISSING_KEY`, `INVALID_KEY` or `EXPIRED_KEY`), `BILLING_ERROR`
        (402),

        `FORBIDDEN` (403), `NOT_FOUND` (404), `METHOD_NOT_ALLOWED` (405),
        `CONFLICT` (409),

        `GONE` (410), `PAYLOAD_TOO_LARGE` (413), `UNSUPPORTED_MEDIA_TYPE` (415),

        `UNPROCESSABLE_REQUEST` (422), `RATE_LIMIT` (429), `INTERNAL_ERROR`
        (500),

        `UPSTREAM_ERROR` (502), `SERVICE_UNAVAILABLE` (503), `UPSTREAM_TIMEOUT`
        (504). Some

        refusals add members of their own beside these (a call request's
        `status`, a workflow's

        `current_version`); the operation says which.
      properties:
        error:
          type: string
          description: The refusal, in one sentence for a person. Its wording may change.
        code:
          type: string
          description: The stable code to branch on.
        issues:
          type: array
          description: >
            Each thing at fault, on a 400 or 422 that names them: every query
            parameter or body field, not just the first. `path` is the
            parameter's name or the field's location.
          items:
            type: object
            required:
              - code
              - message
            properties:
              code:
                type: string
                description: >-
                  query_param_unknown, query_param_repeated, query_param_blank,
                  query_param_invalid, field_unknown, field_required,
                  field_invalid, or the route's own word.
              path:
                type: string
              message:
                type: string
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Your Yappr API key (e.g. `ypr_live_...`). Generate one in the dashboard
        under **Settings → API Keys**. No key is `401 MISSING_KEY`; a key that
        is not one of ours, or is revoked, is `401 INVALID_KEY`; an expired one
        is `401 EXPIRED_KEY`. A valid key without the scope an operation needs
        is `403 INSUFFICIENT_SCOPE` on every operation, and the message names
        the scope. Every response, a 401 included, carries X-RateLimit-Limit,
        X-RateLimit-Remaining and X-RateLimit-Reset: the budget is 60 requests a
        minute per API key. Every 429, whatever its code, carries Retry-After
        (whole seconds, never zero): the per-key budget's `RATE_LIMIT` asks for
        what is left of the minute, a route's daily cap (`RATE_LIMITED`) for the
        time until that cap resets. All four headers are listed in
        Access-Control-Expose-Headers, so a browser can read them. A path the
        API does not serve (an unknown sub-path, an id left empty) is `404
        ROUTE_NOT_FOUND`, and a method a served path does not take is `405
        METHOD_NOT_ALLOWED` with an `Allow` header; both are answered before any
        scope check, and nothing is read or changed. A trailing slash is ignored
        where it cannot be an id left empty (`POST /calls/` is `POST /calls`)
        and refused where it can (`GET /calls/`). A doubled slash inside a path
        is merged into one before the request reaches the API (`GET //calls` is
        `GET /calls`).

````

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