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

# Read a repository file

> Reads one file by its exact repository-relative path, returning line-numbered content. This is the fallback reader: when a previous search already returned an artifact `identifier` for the file, prefer `fetch_artifacts`. Bound large files with `start_line`/`end_line`. When the path does not resolve, the response includes candidate paths with the same file name so the call can be repaired.



## OpenAPI

````yaml /openapi-tool-api-v3.json post /api/tools/read_file
openapi: 3.1.1
info:
  title: CodeAlive Tool API
  description: >-
    Tool-only OpenAPI 3.1 contract for MCP and agent integrations. Every
    operation is read-only and returns a Tool API envelope.
  contact:
    name: CodeAlive Team
    url: https://codealive.ai
    email: support@codealive.ai
  license:
    name: Terms of Service
    url: https://app.codealive.ai/terms
  version: 3.0.0
servers:
  - url: https://app.codealive.ai
security:
  - ApiKeyScheme: []
tags:
  - name: ToolApi
    description: CodeAlive Tool API v3
paths:
  /api/tools/read_file:
    post:
      tags:
        - ToolApi
      summary: Read a repository file
      description: >-
        Reads one file by its exact repository-relative path, returning
        line-numbered content. This is the fallback reader: when a previous
        search already returned an artifact `identifier` for the file, prefer
        `fetch_artifacts`. Bound large files with `start_line`/`end_line`. When
        the path does not resolve, the response includes candidate paths with
        the same file name so the call can be repaired.
      operationId: ToolApiReadFile
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReadFileToolRequest'
            example:
              data_source: CodeAlive-AI/agent-framework
              path: README.md
          text/json:
            schema:
              $ref: '#/components/schemas/ReadFileToolRequest'
          application/*+json:
            schema:
              $ref: '#/components/schemas/ReadFileToolRequest'
      responses:
        '200':
          description: >-
            Success envelope. obj has found, files[] with line-numbered content
            (numberedContent, startLine, endLine), same-name candidates when the
            path did not resolve, and a hint; rendered is the JSON-serialized
            form of obj. Repairable failures (missing or invalid arguments,
            ambiguous or unknown data sources) also return HTTP 200 with
            obj.error = { code, message, retry, try } and a rendered
            <tool_error> block; repair the arguments and retry.
          content:
            application/json:
              schema:
                oneOf:
                  - required:
                      - obj
                      - rendered
                    type: object
                    properties:
                      obj:
                        $ref: '#/components/schemas/AgentReadFileToolResponse'
                      rendered:
                        type: string
                        description: Agent-facing result text.
                    additionalProperties: false
                    description: >-
                      Default success projection returned when output_format is
                      omitted.
                  - required:
                      - obj
                    type: object
                    properties:
                      obj:
                        $ref: '#/components/schemas/AgentReadFileToolResponse'
                    additionalProperties: false
                    description: >-
                      Structured success projection returned when output_format
                      is json.
                  - required:
                      - rendered
                    type: object
                    properties:
                      rendered:
                        type: string
                        description: Agent-facing result text.
                    additionalProperties: false
                    description: >-
                      Agent-facing success projection returned when
                      output_format is agentic.
                  - required:
                      - obj
                      - rendered
                    type: object
                    properties:
                      obj:
                        $ref: '#/components/schemas/ToolApiRepairableResult'
                      rendered:
                        type: string
                        description: Agent-facing result text.
                    additionalProperties: false
                    description: >-
                      Repairable failure. Always includes both projections and
                      uses HTTP 200.
              examples:
                default:
                  summary: Default success response
                  description: >-
                    Returned when output_format is omitted; includes both
                    projections.
                  value:
                    obj:
                      found: true
                      files:
                        - identifier: CodeAlive-AI/agent-framework::README.md
                          path: README.md
                          dataSource:
                            type: Repository
                            name: agent-framework
                          fullName: CodeAlive-AI/agent-framework
                          startLine: 1
                          endLine: 2
                          contentByteSize: 96
                          numberedContent: |-
                            1: # Agent Framework
                            2: Multi-agent orchestration framework.
                      candidates: []
                      sameNameCandidates: []
                      sameNameTotalCount: 0
                      hint: >-
                        Content is line-numbered; request start_line/end_line
                        ranges for large files.
                    rendered: >-
                      {"found":true,"files":[{"identifier":"CodeAlive-AI/agent-framework::README.md","path":"README.md","startLine":1,"endLine":2,"numberedContent":"1:
                      # Agent Framework\n2: Multi-agent orchestration
                      framework."}],"hint":"Content is line-numbered; request
                      start_line/end_line ranges for large files."}
                json_only:
                  summary: JSON success response
                  description: Returned when output_format is json.
                  value:
                    obj:
                      found: true
                      files:
                        - identifier: CodeAlive-AI/agent-framework::README.md
                          path: README.md
                          dataSource:
                            type: Repository
                            name: agent-framework
                          fullName: CodeAlive-AI/agent-framework
                          startLine: 1
                          endLine: 2
                          contentByteSize: 96
                          numberedContent: |-
                            1: # Agent Framework
                            2: Multi-agent orchestration framework.
                      candidates: []
                      sameNameCandidates: []
                      sameNameTotalCount: 0
                      hint: >-
                        Content is line-numbered; request start_line/end_line
                        ranges for large files.
                agentic_only:
                  summary: Agent-facing success response
                  description: Returned when output_format is agentic.
                  value:
                    rendered: >-
                      {"found":true,"files":[{"identifier":"CodeAlive-AI/agent-framework::README.md","path":"README.md","startLine":1,"endLine":2,"numberedContent":"1:
                      # Agent Framework\n2: Multi-agent orchestration
                      framework."}],"hint":"Content is line-numbered; request
                      start_line/end_line ranges for large files."}
                repairable_error:
                  summary: Repairable tool error
                  description: >-
                    Returned with HTTP 200 when arguments can be corrected and
                    retried.
                  value:
                    obj:
                      error:
                        code: unknown_argument
                        message: >-
                          Unknown JSON argument(s) are not accepted in Tool API
                          v3: search_mode.
                        retry: >-
                          yes - repair the tool arguments and call the tool
                          again
                        try: >-
                          Use only the canonical arguments documented for this
                          tool.
                    rendered: |
                      <tool_error>
                        <code>unknown_argument</code>
                        <message>Unknown JSON argument(s) are not accepted in Tool API v3: search_mode.</message>
                        <retry>yes - repair the tool arguments and call the tool again</retry>
                        <try>Use only the canonical arguments documented for this tool.</try>
                      </tool_error>
            text/json:
              schema:
                $ref: '#/components/schemas/ToolApiEnvelope'
        '400':
          description: >-
            Bad request, including malformed JSON, unknown output_format, or
            invalid transport-level input.
        '401':
          description: Authentication failed or API key is missing.
        '403':
          description: >-
            The caller is not authorized for the requested data source or plan
            feature.
        '429':
          description: Rate limit, quota, or plan limit exceeded.
        '500':
          description: Unexpected server failure.
components:
  schemas:
    ReadFileToolRequest:
      required:
        - path
      type: object
      properties:
        output_format:
          enum:
            - json
            - agentic
          type:
            - 'null'
            - string
          description: >-
            Optional success projection. Omit to return both obj and rendered;
            use json for obj only; use agentic for rendered text only.
            Repairable errors always return both obj.error and rendered.
        data_source:
          type:
            - 'null'
            - string
          description: >-
            One repository name or id returned by get_data_sources. Required
            when more than one repository is visible.
        path:
          type:
            - 'null'
            - string
          description: >-
            Repository-relative file path returned by get_file_tree,
            semantic_search, or grep_search.
        start_line:
          type:
            - 'null'
            - integer
          description: Optional 1-based start line.
          format: int32
        end_line:
          type:
            - 'null'
            - integer
          description: Optional 1-based end line.
          format: int32
      additionalProperties: false
    AgentReadFileToolResponse:
      required:
        - hint
      type: object
      properties:
        found:
          type: boolean
          description: Whether the exact requested path resolved.
        files:
          type:
            - 'null'
            - array
          items:
            $ref: '#/components/schemas/AgentReadFileContent'
          description: Resolved file content and line bounds.
        candidates:
          type:
            - 'null'
            - array
          items:
            $ref: '#/components/schemas/AgentReadFileCandidate'
          description: Closest path candidates when exact lookup fails.
        sameNameCandidates:
          type:
            - 'null'
            - array
          items:
            $ref: '#/components/schemas/AgentReadFileCandidate'
          description: Files sharing the requested file name.
        sameNameTotalCount:
          type: integer
          description: Total same-name candidates before truncation.
          format: int32
        hint:
          type:
            - 'null'
            - string
          description: Suggested repair or follow-up tool call.
        error:
          $ref: '#/components/schemas/AgentToolError'
          description: Recoverable read error, when applicable.
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ToolApiWarning'
          description: >-
            Compatibility warnings, such as accepted deprecated argument
            aliases.
      additionalProperties: false
    ToolApiRepairableResult:
      required:
        - error
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ToolApiRepairableError'
          description: Structured error details used to repair the request and retry.
        warnings:
          type:
            - 'null'
            - array
          items:
            $ref: '#/components/schemas/ToolApiWarning'
          description: Compatibility warnings emitted before the request failed.
      additionalProperties: false
      description: >-
        Repairable failure returned with HTTP 200 so an agent can correct the
        request and retry.
    ToolApiEnvelope:
      type: object
      properties:
        obj:
          description: >-
            Arbitrary JSON result for the tool. Present for omitted/json success
            projections and every repairable error.
        rendered:
          type:
            - 'null'
            - string
          description: >-
            Agent-facing result text. Present for omitted/agentic success
            projections and every repairable error.
      additionalProperties: false
    AgentReadFileContent:
      type: object
      properties:
        identifier:
          type:
            - 'null'
            - string
          description: Stable file artifact identifier.
        path:
          type:
            - 'null'
            - string
          description: Repository-relative file path.
        dataSource:
          $ref: '#/components/schemas/AgentToolDataSourceRef'
          description: Resolved repository reference.
        fullName:
          type:
            - 'null'
            - string
          description: Owner-qualified repository name.
        startLine:
          type: integer
          description: 1-based first returned line.
          format: int32
        endLine:
          type: integer
          description: 1-based last returned line.
          format: int32
        contentByteSize:
          type:
            - 'null'
            - integer
          description: Full file size in bytes when known.
          format: int64
        numberedContent:
          type:
            - 'null'
            - string
          description: Returned content prefixed with 1-based line numbers.
      additionalProperties: false
    AgentReadFileCandidate:
      type: object
      properties:
        identifier:
          type:
            - 'null'
            - string
          description: Stable candidate file identifier.
        path:
          type:
            - 'null'
            - string
          description: Repository-relative candidate path.
        dataSource:
          $ref: '#/components/schemas/AgentToolDataSourceRef'
          description: Candidate repository reference.
        fullName:
          type:
            - 'null'
            - string
          description: Owner-qualified repository name.
      additionalProperties: false
    AgentToolError:
      type: object
      properties:
        tool:
          type:
            - 'null'
            - string
          description: Tool whose request could not be completed.
        detail:
          type:
            - 'null'
            - string
          description: Human-readable explanation of the failure.
        retry:
          type:
            - 'null'
            - string
          description: Whether the caller should repair the request and retry.
        hint:
          type:
            - 'null'
            - string
          description: Concrete guidance for repairing the next request.
      additionalProperties: false
    ToolApiWarning:
      type: object
      properties:
        code:
          type:
            - 'null'
            - string
          description: Stable machine-readable warning code.
        message:
          type:
            - 'null'
            - string
          description: Human-readable compatibility warning.
        alias:
          type:
            - 'null'
            - string
          description: Deprecated argument alias that was accepted.
        canonical:
          type:
            - 'null'
            - string
          description: Canonical argument name to use instead of the alias.
      additionalProperties: false
    ToolApiRepairableError:
      type: object
      properties:
        code:
          type:
            - 'null'
            - string
          description: Stable machine-readable error code.
        message:
          type:
            - 'null'
            - string
          description: Human-readable explanation of the invalid request.
        retry:
          type:
            - 'null'
            - string
          description: Whether the caller should correct the request and retry.
        try:
          type:
            - 'null'
            - string
          description: Concrete guidance for repairing the next request.
      additionalProperties: false
    AgentToolDataSourceRef:
      type: object
      properties:
        type:
          type:
            - 'null'
            - string
          description: Repository or Workspace.
        name:
          type:
            - 'null'
            - string
          description: Data-source display name.
      additionalProperties: false
  securitySchemes:
    ApiKeyScheme:
      type: http
      description: >-
        API Key authentication using Bearer token. Example: "Authorization:
        Bearer {apiKey}"
      scheme: bearer
      bearerFormat: API Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.