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

# Overwrite File Content Completely

> Replace all content in an existing file

# Overwrite File Content Completely

Replaces the entire content of an existing file with new content. The file must exist first - this operation cannot create new files.

## Use Cases

* **Document revisions** - Replace entire documents with new versions
* **Configuration updates** - Update entire config files
* **Template replacement** - Replace template files with generated content
* **Data refresh** - Replace data files with updated datasets

## Example Usage

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.openfiles.ai/functions/v1/api/files/overwrite/config/settings.json', {
    method: 'PUT',
    headers: {
      'x-api-key': API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: JSON.stringify({
        "version": "2.0",
        "theme": "dark",
        "notifications": true
      }, null, 2)
    })
  })
  ```

  ```python Python theme={null}
  import requests
  import json

  new_config = {
      "version": "2.0",
      "theme": "dark", 
      "notifications": True
  }

  response = requests.put(
      'https://api.openfiles.ai/functions/v1/api/files/overwrite/config/settings.json',
      headers={'x-api-key': API_KEY},
      json={'content': json.dumps(new_config, indent=2)}
  )
  ```

  ```bash cURL theme={null}
  curl -X PUT 'https://api.openfiles.ai/functions/v1/api/files/overwrite/config/settings.json' \
    -H 'x-api-key: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "content": "{\n  \"version\": \"2.0\",\n  \"theme\": \"dark\",\n  \"notifications\": true\n}"
    }'
  ```
</CodeGroup>


## OpenAPI

````yaml put /files/overwrite/{path}
openapi: 3.0.0
info:
  title: OpenFiles SDK API
  description: >-
    AI-native file storage platform with create, read, write operations, version
    control, and semantic search.
  version: 2.0.0
  contact:
    name: OpenFiles Support
    url: https://openfiles.ai
servers:
  - url: https://api.openfiles.ai/functions/v1/api
    description: Production
  - url: http://localhost:54321/functions/v1/api
    description: Local Development
security: []
tags:
  - name: System
    description: System health and status operations
  - name: Files
    description: File storage operations with version control
paths:
  /files/overwrite/{path}:
    put:
      tags:
        - Files
      summary: Overwrite file content completely
      description: Replace entire file content with new content
      operationId: overwriteFile
      parameters:
        - name: path
          in: path
          required: true
          schema:
            type: string
          description: File path (S3-style, no leading slash)
          example: config/settings.json
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OverwriteFileRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileOperationResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    OverwriteFileRequest:
      type: object
      required:
        - content
      properties:
        content:
          type: string
          maxLength: 10485760
        isBase64:
          type: boolean
          default: false
    FileOperationResponse:
      type: object
      required:
        - success
        - data
        - operation
        - message
      properties:
        success:
          type: boolean
          example: true
        data:
          $ref: '#/components/schemas/FileMetadata'
        operation:
          type: string
          example: write_file
        message:
          type: string
          example: File created successfully, version 1
    FileMetadata:
      type: object
      properties:
        id:
          type: string
          format: uuid
        path:
          type: string
        version:
          type: integer
          minimum: 1
        mimeType:
          type: string
        size:
          type: integer
          minimum: 0
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
        operation:
          type: string
        details:
          type: object
          additionalProperties: true
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Authentication required or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for authentication. Get your API key from the console.

````