---
title: "Read repository file"
method: POST
path: "/api/v2/code/read"
tags: ["Code"]
---

# Read repository file

`POST /api/v2/code/read`

## Request

- Base URL: `https://zeropath.com`
- URL: `https://zeropath.com/api/v2/code/read`
- Auth: API key in header `X-ZeroPath-API-Token-Id` and API key in header `X-ZeroPath-API-Token-Secret`

Read the text content of a single file from a repository. Supports optional line-range selection via `startLine`/`endLine` to avoid fetching entire large files. The response indicates whether the content was truncated by the line range or by a byte-size limit. Supports GitHub and GitLab repositories (not Bitbucket).

## Request body

- CodeReadRequest
  - `organizationId` string: Organization that owns the repository.
  - `repositoryId` string, required: Repository containing the file to read.
  - `path` string, required: Full file path relative to the repository root (e.g. "src/main.py", "packages/api/index.ts").
  - `ref` string: Branch, tag, or commit SHA to read from. Omit to read from the repository's default branch.
  - `startLine` integer: First line number to return (1-based, inclusive). Use with `endLine` to read a specific range instead of the whole file. Omit to start from line 1.
  - `endLine` integer: Last line number to return (1-based, inclusive). Use with `startLine` to read a specific range. Omit to read to the end of the file (subject to byte-size truncation).

## Response `200`

File content

- CodeReadResponse
  - `provider` 'github' | 'gitlab', required: Repository provider that served the request. Only providers with native code-inspection APIs are supported.
  - `repositoryId` string, required
  - `path` string, required
  - `ref` string, nullable, required
  - `startLine` integer, required
  - `endLine` integer, required
  - `totalLines` integer, required
  - `content` string, required
  - `byteLength` integer, required
  - `truncatedByLineRange` boolean, required
  - `truncatedByByteLimit` boolean, required
  - `url` string, nullable, required

## Other responses

- `400`: Error Response
- `401`: Error Response
- `403`: Error Response
- `404`: Error Response

---

[API](https://skmtc.dev/zeropath/apis/zeropath-api.md) - [All operations](https://skmtc.dev/zeropath/apis/zeropath-api/llms.txt) - [OpenAPI document](https://skmtc.dev/zeropath/apis/zeropath-api/revisions/126e9c80ba0d?raw)
