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

# Workspace: File Write

> Create or overwrite a file in the agent's workspace filesystem

Create or overwrite a file in the per-agent workspace filesystem. When `create_dirs` is `true`, any missing parent directories are created automatically.

## Path Parameters

<ParamField path="agent_id" type="string" required>
  Agent ID (UUID)
</ParamField>

## Request Body

<ParamField body="path" type="string" required>
  Destination file path relative to the workspace root.
</ParamField>

<ParamField body="content" type="string" required>
  Full file content. Existing files are overwritten.
</ParamField>

<ParamField body="create_dirs" type="boolean" default={true}>
  When `true`, missing parent directories are created automatically.
</ParamField>

## Response

<ResponseField name="status" type="string">
  Result status (e.g., `ok`).
</ResponseField>

<ResponseField name="path" type="string">
  Path of the file that was written.
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/file_write" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "path": "output/report.txt",
    "content": "Hello World\n",
    "create_dirs": true
  }'
```

## Notes

* `file_write` overwrites existing files. To modify an existing file in place, prefer [Workspace: File Edit](/api-reference/v1/agents/workspace/file-edit) or [Workspace: Multi Edit](/api-reference/v1/agents/workspace/multi-edit).
* Paths must be relative to the workspace root.

## See Also

* [Workspace: File Read](/api-reference/v1/agents/workspace/file-read)
* [Workspace: File Edit](/api-reference/v1/agents/workspace/file-edit)
* [Workspace: File Share](/api-reference/v1/agents/workspace/file-share)


## OpenAPI

````yaml POST /v1/agents/{agent_id}/workspace/file_write
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/agents/{agent_id}/workspace/file_write:
    post:
      tags:
        - API v1
        - Agents
        - Agents Workspace
      summary: 'Workspace: File Write'
      description: Write (create or overwrite) a file in the agent's workspace filesystem.
      operationId: Workspace__File_Write_v1_agents__agent_id__workspace_file_write_post
      parameters:
        - name: agent_id
          in: path
          required: true
          schema:
            type: string
            title: Agent Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FileWriteRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileWriteResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    FileWriteRequest:
      properties:
        path:
          type: string
          title: Path
          description: >-
            Relative path where the file should be written. Creates or
            overwrites the file.
          examples:
            - output/report.txt
        content:
          type: string
          title: Content
          description: Complete content to write to the file.
          examples:
            - |
              Hello World
        create_dirs:
          type: boolean
          title: Create Dirs
          description: >-
            If true, creates parent directories automatically if they don't
            exist.
          default: true
      type: object
      required:
        - path
        - content
      title: FileWriteRequest
    FileWriteResponse:
      properties:
        path:
          type: string
          title: Path
          description: The path where the file was written
        bytes_written:
          type: integer
          title: Bytes Written
          description: Number of bytes written to the file
          default: 0
          examples:
            - 12
        created:
          type: boolean
          title: Created
          description: True if this was a new file, False if overwritten
          default: false
      type: object
      required:
        - path
      title: FileWriteResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````