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

# Write artifact files

> Creates or overwrites one or more files in an artifact. Files that
already exist are replaced; new files are appended. Files not
mentioned in the request are left untouched.

This only updates source files — it does **not** compile or publish.
Call `POST /v3/designs/{editorId}/artifacts/{artifactId}/publish` when
you're done with all file changes to compile and set the artifact
active.




## OpenAPI

````yaml openapi-v3.yml patch /v3/designs/{editorId}/artifacts/{artifactId}/files
openapi: 3.0.3
info:
  title: Magic Patterns API (v3)
  version: 3.0.0
  description: |
    The Magic Patterns API v3 provides programmatic access to design generation,
    iteration, and code-level editing. v3 mirrors the surface of the Magic
    Patterns MCP server — a single key authenticates both transports.

    v3 bills against your normal Magic Patterns credit balance. There is no
    separate API subscription. Free tier users can call v3 up to their credit
    limit, identical to web and MCP usage.

    For the legacy v2 single-shot creation endpoint (separate $99/mo plan),
    see the v2 reference.
servers:
  - url: https://api.magicpatterns.com/api
security:
  - ApiKeyAuth: []
tags:
  - name: Health
  - name: Design Systems
  - name: Designs
  - name: Artifacts
paths:
  /v3/designs/{editorId}/artifacts/{artifactId}/files:
    patch:
      tags:
        - Artifacts
      summary: Write artifact files
      description: |
        Creates or overwrites one or more files in an artifact. Files that
        already exist are replaced; new files are appended. Files not
        mentioned in the request are left untouched.

        This only updates source files — it does **not** compile or publish.
        Call `POST /v3/designs/{editorId}/artifacts/{artifactId}/publish` when
        you're done with all file changes to compile and set the artifact
        active.
      operationId: writeArtifactFilesV3
      parameters:
        - $ref: '#/components/parameters/EditorId'
        - $ref: '#/components/parameters/ArtifactId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - files
              properties:
                files:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    required:
                      - fileName
                      - code
                    properties:
                      fileName:
                        type: string
                        example: App.tsx
                      code:
                        type: string
                        description: >-
                          Full file contents (replaces any existing content for
                          that file).
      responses:
        '200':
          description: >-
            Updated. Response lists all file names in the artifact after the
            write.
          content:
            application/json:
              schema:
                type: object
                properties:
                  files:
                    type: array
                    items:
                      type: string
                    example:
                      - App.tsx
                      - index.tsx
                      - index.css
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    EditorId:
      name: editorId
      in: path
      required: true
      description: The design's editor ID.
      schema:
        type: string
        example: abc123
    ArtifactId:
      name: artifactId
      in: path
      required: true
      description: The artifact ID.
      schema:
        type: string
  responses:
    BadRequest:
      description: Invalid or missing required input.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: The caller does not have access to this resource.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: The requested design or artifact does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalError:
      description: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  schemas:
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
          example: You do not have access to this resource.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-mp-api-key
      description: >
        Magic Patterns API key. The same key authenticates v3 REST and the

        MCP server. Create one at
        https://www.magicpatterns.com/settings/api-keys.

````