> ## 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 Read

> Read a file from the agent's workspace filesystem

Read a file from the per-agent workspace filesystem. Optional line ranges let you page through large files without loading them entirely.

## Path Parameters

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

## Request Body

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

<ParamField body="start_line" type="integer">
  1-based line number to start reading from. Optional; reads from the beginning when omitted.
</ParamField>

<ParamField body="end_line" type="integer">
  1-based line number to stop reading at (inclusive). Optional; reads to the end when omitted.
</ParamField>

<ParamField body="encoding" type="string" default="utf-8">
  Text encoding used to decode the file contents.
</ParamField>

## Response

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

<ResponseField name="content" type="string">
  File contents within the requested range.
</ResponseField>

<ResponseField name="path" type="string">
  The file path that was read.
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/file_read" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "path": "config.yaml",
    "start_line": 1,
    "end_line": 50,
    "encoding": "utf-8"
  }'
```

## Notes

* Paths must be relative to the workspace root. Absolute paths are rejected.
* For binary files, set `encoding` appropriately or use [Workspace: File Share](/api-reference/v1/agents/workspace/file-share) to retrieve the file via a public URL.

## See Also

* [Workspace: File Write](/api-reference/v1/agents/workspace/file-write)
* [Workspace: File Edit](/api-reference/v1/agents/workspace/file-edit)
* [Workspace: Grep](/api-reference/v1/agents/workspace/grep)


## OpenAPI

````yaml POST /v1/agents/{agent_id}/workspace/file_read
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_read:
    post:
      tags:
        - API v1
        - Agents
        - Agents Workspace
      summary: 'Workspace: File Read'
      description: >-
        Read a file from the agent's workspace filesystem. Supports partial
        reads via line ranges.
      operationId: Workspace__File_Read_v1_agents__agent_id__workspace_file_read_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/FileReadRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileReadResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    FileReadRequest:
      properties:
        path:
          type: string
          title: Path
          description: Relative path to the file to read from the workspace filesystem.
          examples:
            - config.yaml
        start_line:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Start Line
          description: >-
            1-indexed starting line number for partial reads. Omit to read from
            the beginning.
          examples:
            - 1
        end_line:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: End Line
          description: >-
            1-indexed ending line number (inclusive) for partial reads. Omit to
            read to the end.
          examples:
            - 50
        encoding:
          type: string
          title: Encoding
          description: >-
            File encoding to use when reading. Falls back to detected encoding
            if decoding fails.
          default: utf-8
          examples:
            - utf-8
      type: object
      required:
        - path
      title: FileReadRequest
    FileReadResponse:
      properties:
        content:
          type: string
          title: Content
          description: File content (full or partial based on line range)
          default: ''
        lines_count:
          type: integer
          title: Lines Count
          description: Total number of lines in the returned content
          default: 0
        encoding_detected:
          type: string
          title: Encoding Detected
          description: The encoding used to decode the file
          default: utf-8
      type: object
      title: FileReadResponse
    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

````