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

# Stages a patch against a development deployment

> Persists a patch durably without applying it; call the sync endpoint to apply staged patches to the running deployment. The target must be a development deployment (its archive created with `is_development` set to `true`); patching any other deployment is rejected.



## OpenAPI

````yaml post /v1/models/{model_id}/deployments/{deployment_id}/patches
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/models/{model_id}/deployments/{deployment_id}/patches:
    parameters:
      - $ref: '#/components/parameters/model_id'
      - $ref: '#/components/parameters/deployment_id'
    post:
      summary: Stages a patch against a development deployment
      description: >-
        Persists a patch durably without applying it; call the sync endpoint to
        apply staged patches to the running deployment. The target must be a
        development deployment (its archive created with `is_development` set to
        `true`); patching any other deployment is rejected.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDeploymentPatchRequestV1'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateDeploymentPatchResponseV1'
      x-codeSamples:
        - lang: bash
          source: >-
            curl --request POST \

            --url
            https://api.baseten.co/v1/models/{model_id}/deployments/{deployment_id}/patches
            \

            --header "Authorization: Bearer $BASETEN_API_KEY" \

            --data '{
              "prev_patch_hash": null,
              "next_patch_point": {
                "content_hashes": null,
                "config": null
              },
              "patch_ops": null
            }'
        - lang: python
          source: >-
            import requests

            import os

            API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")

            url =
            "https://api.baseten.co/v1/models/{model_id}/deployments/{deployment_id}/patches"


            headers = {"Authorization": f"Bearer {API_KEY}"}


            response = requests.request(
                "POST",
                url,
                headers=headers,
                json={'prev_patch_hash': None, 'next_patch_point': {'content_hashes': None, 'config': None}, 'patch_ops': None}
            )


            print(response.text)
components:
  parameters:
    model_id:
      schema:
        type: string
      name: model_id
      in: path
      required: true
    deployment_id:
      schema:
        type: string
      name: deployment_id
      in: path
      required: true
  schemas:
    CreateDeploymentPatchRequestV1:
      description: >-
        A patch to stage against the development deployment.


        Staging is durable on its own: the patch is persisted independently of
        the

        later sync, so a failed sync does not lose it.
      properties:
        prev_patch_hash:
          description: >-
            Content hash of the patch point this patch is applied on - the link
            the staged patch must build on. A stale value (the base moved
            underneath the client) is rejected with a conflict.
          title: Prev Patch Hash
          type: string
        next_patch_point:
          $ref: '#/components/schemas/DeploymentPatchPointV1'
          description: >-
            The source state after this patch. The server derives its content
            hash from `content_hashes`.
        patch_ops:
          description: >-
            The ordered ops that make up this patch. At least one op is
            required; a patch that changes nothing is not a valid request. There
            is no op for a directory: a directory comes into existence when the
            first file under it is added, and is removed when its last file is
            removed, so directory creation and deletion happen implicitly
            through the file ops. Adding or removing an otherwise empty
            directory therefore produces no ops even though it changes the
            source hash; do not send a patch request for such a change.
          items:
            discriminator:
              mapping:
                config:
                  $ref: '#/components/schemas/DeploymentPatchOpConfigV1'
                environment_variable:
                  $ref: '#/components/schemas/DeploymentPatchOpEnvVarV1'
                external_data:
                  $ref: '#/components/schemas/DeploymentPatchOpExternalDataV1'
                model_code:
                  $ref: '#/components/schemas/DeploymentPatchOpModelCodeV1'
                package:
                  $ref: '#/components/schemas/DeploymentPatchOpPackageV1'
                python_requirement:
                  $ref: '#/components/schemas/DeploymentPatchOpPythonRequirementV1'
              propertyName: type
            oneOf:
              - $ref: '#/components/schemas/DeploymentPatchOpModelCodeV1'
              - $ref: '#/components/schemas/DeploymentPatchOpPackageV1'
              - $ref: '#/components/schemas/DeploymentPatchOpConfigV1'
              - $ref: '#/components/schemas/DeploymentPatchOpPythonRequirementV1'
              - $ref: '#/components/schemas/DeploymentPatchOpEnvVarV1'
              - $ref: '#/components/schemas/DeploymentPatchOpExternalDataV1'
          minItems: 1
          title: Patch Ops
          type: array
      required:
        - prev_patch_hash
        - next_patch_point
        - patch_ops
      title: CreateDeploymentPatchRequestV1
      type: object
    CreateDeploymentPatchResponseV1:
      description: The created patch, represented by the patch point it produced.
      properties:
        patch_point:
          $ref: '#/components/schemas/DeploymentPatchPointWithHashV1'
          description: >-
            The resulting patch point the staged patch produced; matches the
            pending point a subsequent state read returns.
      required:
        - patch_point
      title: CreateDeploymentPatchResponseV1
      type: object
    DeploymentPatchPointV1:
      description: >-
        A patch point: the source state the next patch is computed against.


        The content hash that identifies a point is derived from this state (see

        `DeploymentPatchPointWithHashV1.hash`), so a request only sends the
        state and

        the server stamps the hash. A previous point's hash plus the current
        local

        source is enough to compute the next patch, so the watch client reads
        the

        point it is patching off of.
      properties:
        content_hashes:
          additionalProperties:
            anyOf:
              - type: string
              - type: 'null'
          description: >-
            Map of every non-ignored source path, relative and forward-slash, to
            its content hash: files map to the hex blake3 digest of their bytes,
            directories map to null. This is the full signature of the source
            tree and what the content hash is derived from.
          title: Content Hashes
          type: object
        config:
          description: The verbatim config.yaml text for this source state.
          title: Config
          type: string
        requirements:
          description: >-
            Requirements resolved from the config's requirements file, when it
            points at one. Empty when requirements are declared inline in the
            config.
          items:
            type: string
          title: Requirements
          type: array
      required:
        - content_hashes
        - config
      title: DeploymentPatchPointV1
      type: object
    DeploymentPatchOpConfigV1:
      description: >-
        Replace the config when config.yaml changes.


        Config has no action: it is always a full replacement of the parsed
        config.

        Derived changes (environment variables, external data, requirements) are

        emitted as their own ops alongside this one.
      properties:
        type:
          const: config
          default: config
          title: Type
          type: string
        config:
          additionalProperties: true
          description: The full parsed config as a JSON object.
          title: Config
          type: object
        path:
          default: config.yaml
          description: Config file path within the source.
          title: Path
          type: string
      required:
        - config
      title: DeploymentPatchOpConfigV1
      type: object
    DeploymentPatchOpEnvVarV1:
      description: Add, update, or remove a single environment variable.
      properties:
        type:
          const: environment_variable
          default: environment_variable
          title: Type
          type: string
        action:
          $ref: '#/components/schemas/DeploymentPatchActionV1'
          description: How this op changes the variable.
        name:
          description: The environment variable name.
          title: Name
          type: string
        value:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: The environment variable value. Required for add and update.
          title: Value
      required:
        - action
        - name
      title: DeploymentPatchOpEnvVarV1
      type: object
    DeploymentPatchOpExternalDataV1:
      description: >-
        Add, update, or remove a single external data item.


        External data is referenced by config, not stored in the source. The
        backend

        only adds or removes it, where adding re-downloads (overwriting any
        existing

        file), so `update` is accepted and treated identically to `add`.
      properties:
        type:
          const: external_data
          default: external_data
          title: Type
          type: string
        action:
          $ref: '#/components/schemas/DeploymentPatchActionV1'
          description: >-
            How this op changes the item. `UPDATE` is treated identically to
            `ADD`.
        item:
          additionalProperties:
            type: string
          description: The single external data item descriptor.
          title: Item
          type: object
      required:
        - action
        - item
      title: DeploymentPatchOpExternalDataV1
      type: object
    DeploymentPatchOpModelCodeV1:
      description: Add, update, or remove a file under the model code directory.
      properties:
        type:
          const: model_code
          default: model_code
          title: Type
          type: string
        action:
          $ref: '#/components/schemas/DeploymentPatchActionV1'
          description: How this op changes the file.
        path:
          description: File path relative to the model code directory.
          title: Path
          type: string
        content:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: UTF-8 file content. Null for removals and binary files.
          title: Content
        content_bytes:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Base64-encoded content for binary files.
          title: Content Bytes
        hot_reload:
          default: false
          description: >-
            Whether the running server can pick up this change without a
            restart.
          title: Hot Reload
          type: boolean
      required:
        - action
        - path
      title: DeploymentPatchOpModelCodeV1
      type: object
    DeploymentPatchOpPackageV1:
      description: Add, update, or remove a file under the bundled packages directory.
      properties:
        type:
          const: package
          default: package
          title: Type
          type: string
        action:
          $ref: '#/components/schemas/DeploymentPatchActionV1'
          description: How this op changes the file.
        path:
          description: File path relative to the bundled packages directory.
          title: Path
          type: string
        content:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: UTF-8 file content. Null for removals and binary files.
          title: Content
        content_bytes:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Base64-encoded content for binary files.
          title: Content Bytes
      required:
        - action
        - path
      title: DeploymentPatchOpPackageV1
      type: object
    DeploymentPatchOpPythonRequirementV1:
      description: Add, update, or remove a single Python requirement.
      properties:
        type:
          const: python_requirement
          default: python_requirement
          title: Type
          type: string
        action:
          $ref: '#/components/schemas/DeploymentPatchActionV1'
          description: How this op changes the requirement.
        requirement:
          description: >-
            The requirement to apply. For removals this is the package name;
            otherwise the full requirements.txt-style line.
          title: Requirement
          type: string
      required:
        - action
        - requirement
      title: DeploymentPatchOpPythonRequirementV1
      type: object
    DeploymentPatchPointWithHashV1:
      description: >-
        A patch point plus its server-assigned content hash, returned in
        responses.


        Requests omit the hash (the server derives it from the source state);
        responses

        include it so the watch client can echo it back as the next patch's

        `prev_patch_hash` without having to recompute the fold itself.
      properties:
        content_hashes:
          additionalProperties:
            anyOf:
              - type: string
              - type: 'null'
          description: >-
            Map of every non-ignored source path, relative and forward-slash, to
            its content hash: files map to the hex blake3 digest of their bytes,
            directories map to null. This is the full signature of the source
            tree and what the content hash is derived from.
          title: Content Hashes
          type: object
        config:
          description: The verbatim config.yaml text for this source state.
          title: Config
          type: string
        requirements:
          description: >-
            Requirements resolved from the config's requirements file, when it
            points at one. Empty when requirements are declared inline in the
            config.
          items:
            type: string
          title: Requirements
          type: array
        hash:
          description: >-
            Content hash identifying this exact source state, and the link
            patches build on. It is derived deterministically from
            `content_hashes`, so a request need not send it - the server derives
            it. It is derived by sorting the `content_hashes` keys as paths,
            splitting each key on '/' into its path components and ordering the
            keys by comparing those component lists element by element, each
            component compared by Unicode code point (equivalently UTF-8 byte
            order). Treating '/' as a path separator this way, rather than as
            the ordinary character U+002F, means a key that is an ancestor path
            sorts before a sibling whose name extends the first differing
            component (so e.g. 'a/b' sorts before 'a.b'). A blake3 hasher is
            then built, and for each key in that order updated with the blake3
            digest (32 raw bytes) of the key encoded as UTF-8, then, when the
            entry is a file (non-null value), with that file's digest as 32 raw
            bytes. The stream uses raw digest bytes, but the values in
            `content_hashes` are those digests hex-encoded (64 hex chars), so
            decode each value from hex first. Directory entries (null value)
            contribute only their key digest. The result is the hasher's own hex
            digest.
          title: Hash
          type: string
      required:
        - content_hashes
        - config
        - hash
      title: DeploymentPatchPointWithHashV1
      type: object
    DeploymentPatchActionV1:
      description: How a patch op changes its target.
      enum:
        - ADD
        - UPDATE
        - REMOVE
      title: DeploymentPatchActionV1
      type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````