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

# Read Package File

> Read specific file sections from package source code using SHA256 hash

Read exact file sections from package source code using SHA256 hash. Use this to get complete context around code snippets found in package searches. No indexing required - fetches packages on-demand from registries.

## Endpoint

`POST /v1/search/packages/read-file`

## Request Body

<ParamField body="registry" type="string" required>
  Package registry: `pypi`, `npm`, `terraform`, `crates_io`, `golang`, `helm`, `ansible`, `maven`, `nuget`, `rubygems`.
</ParamField>

<ParamField body="package_name" type="string" required>
  Package name.
</ParamField>

<ParamField body="filename_sha256" type="string" required>
  SHA256 hash of filename (from search results).
</ParamField>

<ParamField body="start_line" type="integer" required min="1">
  Starting line (1-based).
</ParamField>

<ParamField body="end_line" type="integer" required min="1">
  Ending line (max 200 lines from start\_line).
</ParamField>

<ParamField body="version" type="string" optional>
  Optional package version.
</ParamField>

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.wistx.ai/v1/search/packages/read-file \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
      "registry": "pypi",
      "package_name": "boto3",
      "filename_sha256": "abc123def456...",
      "start_line": 100,
      "end_line": 150,
      "version": "1.28.0"
    }'
  ```

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

  api_key = "YOUR_API_KEY"
  response = requests.post(
      "https://api.wistx.ai/v1/search/packages/read-file",
      headers={
          "Authorization": f"Bearer {api_key}",
          "Content-Type": "application/json"
      },
      json={
          "registry": "pypi",
          "package_name": "boto3",
          "filename_sha256": "abc123def456...",
          "start_line": 100,
          "end_line": 150,
          "version": "1.28.0"
      }
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const apiKey = "YOUR_API_KEY";
  const response = await fetch("https://api.wistx.ai/v1/search/packages/read-file", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${apiKey}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      registry: "pypi",
      package_name: "boto3",
      filename_sha256: "abc123def456...",
      start_line: 100,
      end_line: 150,
      version: "1.28.0"
    })
  });
  const data = await response.json();
  console.log(data);
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "net/http"
  )

  func main() {
      apiKey := "YOUR_API_KEY"
      payload := map[string]interface{}{
          "registry": "pypi",
          "package_name": "boto3",
          "filename_sha256": "abc123def456...",
          "start_line": 100,
          "end_line": 150,
          "version": "1.28.0",
      }
      jsonData, _ := json.Marshal(payload)
      req, _ := http.NewRequest("POST", "https://api.wistx.ai/v1/search/packages/read-file", bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer "+apiKey)
      req.Header.Set("Content-Type", "application/json")
      client := &http.Client{}
      resp, _ := client.Do(req)
      defer resp.Body.Close()
  }
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.wistx.ai/v1/search/packages/read-file')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new(uri.path)
  request['Authorization'] = "Bearer YOUR_API_KEY"
  request['Content-Type'] = 'application/json'
  request.body = {
    registry: "pypi",
    package_name: "boto3",
    filename_sha256: "abc123def456...",
    start_line: 100,
    end_line: 150,
    version: "1.28.0"
  }.to_json
  response = http.request(request)
  puts response.body
  ```

  ```php PHP theme={null}
  <?php
  $apiKey = "YOUR_API_KEY";
  $data = [
      "registry" => "pypi",
      "package_name" => "boto3",
      "filename_sha256" => "abc123def456...",
      "start_line" => 100,
      "end_line" => 150,
      "version" => "1.28.0"
  ];
  $ch = curl_init("https://api.wistx.ai/v1/search/packages/read-file");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer " . $apiKey,
      "Content-Type: application/json"
  ]);
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response;
  ?>
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;
  import com.fasterxml.jackson.databind.ObjectMapper;

  String apiKey = "YOUR_API_KEY";
  Map<String, Object> payload = Map.of(
      "registry", "pypi",
      "package_name", "boto3",
      "filename_sha256", "abc123def456...",
      "start_line", 100,
      "end_line", 150,
      "version", "1.28.0"
  );
  ObjectMapper mapper = new ObjectMapper();
  String json = mapper.writeValueAsString(payload);
  HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.wistx.ai/v1/search/packages/read-file"))
      .header("Authorization", "Bearer " + apiKey)
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(json))
      .build();
  HttpClient client = HttpClient.newHttpClient();
  HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
  System.out.println(response.body());
  ```
</CodeGroup>

## Response Example

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "data": {
      "package_name": "boto3",
      "registry": "pypi",
      "file_path": "boto3/s3/transfer.py",
      "filename_sha256": "abc123def456...",
      "start_line": 100,
      "end_line": 150,
      "total_lines": 500,
      "content": "def upload_file(...):\n    # Upload file implementation\n    ...",
      "line_count": 50
    },
    "metadata": {
      "request_id": "req_abc123",
      "timestamp": 1704067200.0,
      "query_time_ms": 234
    }
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": {
      "code": "VALIDATION_ERROR",
      "message": "Invalid request parameters",
      "details": "end_line must be >= start_line"
    },
    "metadata": {
      "request_id": "req_abc123",
      "timestamp": 1704067200.0
    }
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": {
      "code": "VALIDATION_ERROR",
      "message": "Invalid request parameters",
      "details": "Maximum 200 lines can be read at once"
    },
    "metadata": {
      "request_id": "req_abc123",
      "timestamp": 1704067200.0
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Invalid or missing API key",
      "details": null
    },
    "metadata": {
      "request_id": "req_abc123",
      "timestamp": 1704067200.0
    }
  }
  ```

  ```json 500 Internal Server Error theme={null}
  {
    "error": {
      "code": "INTERNAL_ERROR",
      "message": "An unexpected error occurred",
      "details": "File with hash abc123def456... not found in package boto3"
    },
    "metadata": {
      "request_id": "req_abc123",
      "timestamp": 1704067200.0
    }
  }
  ```
</ResponseExample>

## Rate Limits

| Plan | Queries/Month |
| - | - |
| Professional | 2,000 |
| Team | 10,000 |
| Enterprise | Unlimited |


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