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

# Get file contents

> Returns the raw source content of a file at a given repository path and optional git ref.



## OpenAPI

````yaml /api-reference/sourcebot-public.openapi.json get /api/source
openapi: 3.0.3
info:
  title: Sourcebot Public API
  version: v5.0.4
  description: >-
    OpenAPI description for the public Sourcebot REST endpoints used for search,
    repository listing, and file browsing. Authentication is instance-dependent:
    API keys are the standard integration mechanism, OAuth bearer tokens are
    EE-only, and some instances may allow anonymous access.
servers: []
security:
  - bearerToken: []
  - apiKeyHeader: []
  - {}
tags:
  - name: Search & Navigation
    description: Code search and symbol navigation endpoints.
  - name: Repositories
    description: Repository listing and metadata endpoints.
  - name: Git
    description: Git history, diff, and file content endpoints.
  - name: System
    description: System health and version endpoints.
  - name: Enterprise (EE)
    description: Enterprise endpoints for user management and audit logging.
paths:
  /api/source:
    get:
      tags:
        - Git
      summary: Get file contents
      description: >-
        Returns the raw source content of a file at a given repository path and
        optional git ref.
      operationId: getFileSource
      parameters:
        - schema:
            type: string
          required: true
          name: path
          in: query
        - schema:
            type: string
          required: true
          name: repo
          in: query
        - schema:
            type: string
          required: false
          name: ref
          in: query
      responses:
        '200':
          description: File source and metadata.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicFileSourceResponse'
        '400':
          description: Invalid query parameters or git ref.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
        '404':
          description: Repository or file not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
        '500':
          description: Unexpected file retrieval failure.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
components:
  schemas:
    PublicFileSourceResponse:
      type: object
      properties:
        source:
          type: string
        language:
          type: string
        path:
          type: string
        repo:
          type: string
        repoCodeHostType:
          type: string
          enum:
            - github
            - gitlab
            - gitea
            - gerrit
            - bitbucketServer
            - bitbucketCloud
            - genericGitHost
            - azuredevops
        repoDisplayName:
          type: string
        repoExternalWebUrl:
          type: string
        webUrl:
          type: string
        externalWebUrl:
          type: string
      required:
        - source
        - language
        - path
        - repo
        - repoCodeHostType
        - webUrl
    PublicApiServiceError:
      type: object
      properties:
        statusCode:
          type: number
        errorCode:
          type: string
        message:
          type: string
      required:
        - statusCode
        - errorCode
        - message
      description: Structured error response returned by Sourcebot public API endpoints.
  securitySchemes:
    bearerToken:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your API key.
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-Sourcebot-Api-Key
      description: >-
        Header of the form `X-Sourcebot-Api-Key: <token>`, where `<token>` is
        your API key.

````