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

# Copy Resources

> Copy a subgraph of resources within the current project.

Selects all resources reachable from the given root IDs via dependency
edges, then creates a copy of each. Copies are created in DRAFT state
with a COPY event dispatched to the provider for actual duplication.

Dependency rewiring (enabled by default) ensures that dependencies
between copied resources point to their copies instead of originals.
Dependencies on resources outside the copied subgraph remain unchanged.

Same-project copy is the only supported mode. Every root id must
already encode the URL project, and every traversed node must live
inside the same project; cross-project copy is rejected at the
engine layer and is not a planned feature.

Returns:
    CopyResponse with per-resource results and summary counts.

Raises:
    InvalidResourceIdentityError: If any root resource_id is
        malformed or belongs to a different project than the URL.
    ProjectMismatchError: If the engine discovers a traversed
        resource that escapes the URL project.



## OpenAPI

````yaml https://api.pragmatiks.io/openapi.json post /projects/{project_id}/resources/copy
openapi: 3.1.0
info:
  title: Pragma API
  version: 0.1.0
servers: []
security: []
paths:
  /projects/{project_id}/resources/copy:
    post:
      tags:
        - resources
      summary: Copy Resources
      description: |-
        Copy a subgraph of resources within the current project.

        Selects all resources reachable from the given root IDs via dependency
        edges, then creates a copy of each. Copies are created in DRAFT state
        with a COPY event dispatched to the provider for actual duplication.

        Dependency rewiring (enabled by default) ensures that dependencies
        between copied resources point to their copies instead of originals.
        Dependencies on resources outside the copied subgraph remain unchanged.

        Same-project copy is the only supported mode. Every root id must
        already encode the URL project, and every traversed node must live
        inside the same project; cross-project copy is rejected at the
        engine layer and is not a planned feature.

        Returns:
            CopyResponse with per-resource results and summary counts.

        Raises:
            InvalidResourceIdentityError: If any root resource_id is
                malformed or belongs to a different project than the URL.
            ProjectMismatchError: If the engine discovers a traversed
                resource that escapes the URL project.
      operationId: resources-copy_resources
      parameters:
        - name: project_id
          in: path
          required: true
          schema:
            type: string
            title: Project Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CopyRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CopyResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CopyRequest:
      properties:
        resource_ids:
          items:
            type: string
          type: array
          minItems: 1
          title: Resource Ids
        tags:
          items:
            type: string
          type: array
          title: Tags
          default: []
        rewire_dependencies:
          type: boolean
          title: Rewire Dependencies
          default: true
        depth:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Depth
        strategy:
          $ref: '#/components/schemas/CopyStrategy'
          default: stateless
      type: object
      required:
        - resource_ids
      title: CopyRequest
      description: |-
        Request body for the subgraph copy operation.

        Attributes:
            resource_ids: SurrealDB resource IDs to copy (roots of the subgraph).
            tags: Tags to apply to all copied resources.
            rewire_dependencies: If True, rewrite dependencies between copied
                resources to point to their copies instead of the originals.
            depth: Maximum traversal depth from roots. None means unlimited.
            strategy: Default copy strategy for resources that do not specify one.
    CopyResponse:
      properties:
        copied:
          items:
            $ref: '#/components/schemas/CopyResourceResult'
          type: array
          title: Copied
        total:
          type: integer
          title: Total
        succeeded:
          type: integer
          title: Succeeded
        failed:
          type: integer
          title: Failed
      type: object
      required:
        - copied
        - total
        - succeeded
        - failed
      title: CopyResponse
      description: |-
        Response body for the subgraph copy operation.

        Attributes:
            copied: List of per-resource copy results.
            total: Total resources in the selected subgraph.
            succeeded: Number of resources successfully copied.
            failed: Number of resources that failed to copy.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CopyStrategy:
      type: string
      enum:
        - stateless
        - stateful
      title: CopyStrategy
      description: |-
        Strategy for how a resource should be copied.

        Attributes:
            STATELESS: Config-only copy. The resource is duplicated by creating a new
                instance with the same (or modified) configuration. No data migration.
            STATEFUL: Data-bearing copy. The resource needs to clone underlying data
                (e.g., database contents, vector indices) and may produce patches for
                ongoing synchronization.
    CopyResourceResult:
      properties:
        source_id:
          type: string
          title: Source Id
        copied_resource:
          anyOf:
            - $ref: '#/components/schemas/Resource-Output'
            - type: 'null'
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
      type: object
      required:
        - source_id
      title: CopyResourceResult
      description: |-
        Result for a single resource in a copy operation.

        Attributes:
            source_id: External ID of the original resource.
            copied_resource: The newly created copy resource (None if copy failed).
            error: Error message if copying this resource failed.
    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
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    Resource-Output:
      properties:
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        provider:
          type: string
          title: Provider
        resource:
          type: string
          title: Resource
        name:
          type: string
          title: Name
        project_id:
          type: string
          title: Project Id
        config:
          additionalProperties: true
          type: object
          title: Config
          default: {}
        resolved_config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Resolved Config
        dependencies:
          items:
            $ref: '#/components/schemas/ResourceReference'
          type: array
          title: Dependencies
          default: []
        owner_references:
          items:
            $ref: '#/components/schemas/OwnerReference'
          type: array
          title: Owner References
          default: []
        outputs:
          additionalProperties: true
          type: object
          title: Outputs
          default: {}
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
        lifecycle_state:
          $ref: '#/components/schemas/LifecycleState'
          default: draft
        health:
          $ref: '#/components/schemas/HealthStatus'
          default: healthy
        health_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Health Message
        pending_event_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Pending Event Id
        pending_event_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Pending Event Type
        provisioned:
          type: boolean
          title: Provisioned
          default: false
        reconcile_count:
          type: integer
          title: Reconcile Count
          default: 0
        version:
          type: integer
          title: Version
          default: 0
        tags:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Tags
        provider_version:
          anyOf:
            - type: string
            - type: 'null'
          title: Provider Version
        managed_by:
          anyOf:
            - $ref: '#/components/schemas/ManagedBy'
            - type: 'null'
        id:
          type: string
          title: Id
          description: 'External resource ID for API responses: provider/resource/name.'
          readOnly: true
      type: object
      required:
        - provider
        - resource
        - name
        - project_id
        - id
      title: Resource
      description: >-
        Domain model for resources with provider/resource identity and 5-state
        lifecycle.


        Identity fields (frozen - immutable after creation):
            provider: Provider that manages this resource type.
            resource: Resource type name.
            name: Unique resource instance name.

        Configuration fields (mutable):
            config: Original user-submitted resource configuration. Contains raw field
                references and dependency markers as submitted by the user.
            resolved_config: Resolved configuration with field references and dependency
                markers expanded. Contains __field_ref__ markers with resolved_value and
                dependency markers with ref data. Set when transitioning to PENDING state.
                None when resource is in DRAFT state or not yet resolved.
            dependencies: References to resources this resource depends on.
            owner_references: References to resources that own this resource for
                lifecycle coordination and cascading deletes.

        Output fields (provider-managed):
            outputs: Resource outputs from provider processing.
            error: Error message when resource is in FAILED state.

        Lifecycle fields (system-managed):
            lifecycle_state: Current state (DRAFT/PENDING/PROCESSING/READY/FAILED).
            pending_event_id: Event ID currently being processed (set on PROCESSING,
                cleared on READY/FAILED). Used for response idempotency validation.
            provisioned: Whether the resource was successfully created at least once.
                Used to distinguish failed creates (retry CREATE) from failed updates
                (retry UPDATE).

        Versioning fields (system-managed):
            provider_version: Semver of the provider version that last processed this
                resource. Set automatically when the resource transitions to PENDING.
                None for platform resources or pre-versioning backfill.

        Ownership fields (system-managed):
            managed_by: Ownership discriminator. ``user`` for resources the
                caller owns and controls, ``platform`` for platform-managed
                resources (platform agents, tier resources, platform-default
                LLM provider) that reject user writes. ``None`` is the legacy
                unmanaged default for backfilled records.

        Categorization fields (mutable):
            tags: Optional list of tags for categorization and filtering.

        Inherited from PragmaModel:
            created_at: Creation timestamp (frozen).
            updated_at: Last update timestamp (mutable).
    ResourceReference:
      properties:
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        project_id:
          type: string
          title: Project Id
        provider:
          type: string
          title: Provider
        resource:
          type: string
          title: Resource
        name:
          type: string
          title: Name
      type: object
      required:
        - project_id
        - provider
        - resource
        - name
      title: ResourceReference
      description: |-
        Reference to another resource for dependency tracking.

        Used to express dependencies between resources. At commit time,
        the API validates that all referenced resources exist and are READY.

        Attributes:
            project_id: Project that owns the referenced resource.
            provider: Provider that manages the referenced resource.
            resource: Resource type name.
            name: Resource instance name.
    OwnerReference:
      properties:
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        project_id:
          type: string
          title: Project Id
        provider:
          type: string
          title: Provider
        resource:
          type: string
          title: Resource
        name:
          type: string
          title: Name
      type: object
      required:
        - project_id
        - provider
        - resource
        - name
      title: OwnerReference
      description: >-
        Reference to a resource that owns this resource for lifecycle
        coordination.


        Used for cascading deletes and ownership tracking. When an owner
        resource

        is deleted, owned resources can be automatically cleaned up.


        A resource can have multiple owners (rare but valid for shared
        resources).


        Attributes:
            project_id: Project that owns the referenced resource.
            provider: Provider that manages the owner resource.
            resource: Resource type name.
            name: Resource instance name.
    LifecycleState:
      type: string
      enum:
        - draft
        - waiting
        - pending
        - processing
        - ready
        - failed
        - deleting
      title: LifecycleState
      description: Lifecycle states for resources.
    HealthStatus:
      type: string
      enum:
        - healthy
        - degraded
    ManagedBy:
      type: string
      enum:
        - user
        - platform

````