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

# Set service source

> **Token scope:** `account` · `org` · `project` — read-only tokens refused (not a GET).

Connect a repository to this compute service (admin+; replaces any previous source) — the tracked branch is built now and deployed into the service; every later push to it redeploys (unless autoDeploy is false, or the repo is public).



## OpenAPI

````yaml /openapi/project.json put /projects/{projectId}/services/{serviceId}/source
openapi: 3.1.0
info:
  title: InstaCloud API — Project level
  version: 0.1.0
  description: >-
    Endpoints under `/projects/{projectId}`: branches, services, deploys,
    secrets, databases, storage, cron, observability, governance. Callable with
    any token whose binding covers the project.


    Generated from the platform's own OpenAPI document
    (https://api.instacloud.com/openapi.json); see the [API
    overview](/reference/api/overview) for authentication and token scopes.
servers:
  - url: https://api.instacloud.com
    description: InstaCloud
security:
  - bearerAuth: []
tags:
  - name: Projects
    description: Projects inside an organization.
  - name: Branches
    description: >-
      Branch environments of a project: isolated database, storage and compute
      per branch.
  - name: Services
    description: 'Services on a branch: compute, postgres, storage and managed databases.'
  - name: Deploy
    description: Deploy an image or a source to a compute service.
  - name: Compute
    description: Build output of a compute service.
  - name: Secrets
    description: User secrets, service credentials and how they bind into compute env.
  - name: Database
    description: Postgres databases, extensions, credentials and ad-hoc SQL.
  - name: Storage
    description: Objects in a storage service.
  - name: Backups
    description: Database backups and restores.
  - name: Cron
    description: Scheduled HTTP calls against a service or an external URL.
  - name: Observability
    description: Logs, metrics, deploy events and database insight.
  - name: Governance
    description: Per-project agent policy and the approval queue.
  - name: Audit
    description: The project's event timeline, including agent-ingested events.
  - name: Domains
    description: >-
      Domains bought through InstaCloud, bring-your-own zones and their DNS
      records.
  - name: Billing
    description: Usage, cycles, invoices and credits.
  - name: Templates
    description: Deploy a template into a project.
paths:
  /projects/{projectId}/services/{serviceId}/source:
    put:
      tags:
        - Services
      summary: Set service source
      description: >-
        **Token scope:** `account` · `org` · `project` — read-only tokens
        refused (not a GET).


        Connect a repository to this compute service (admin+; replaces any
        previous source) — the tracked branch is built now and deployed into the
        service; every later push to it redeploys (unless autoDeploy is false,
        or the repo is public).
      operationId: setServiceSource
      parameters:
        - schema:
            format: uuid
            type: string
          in: path
          name: projectId
          required: true
        - schema:
            format: uuid
            type: string
          in: path
          name: serviceId
          required: true
      requestBody:
        content:
          application/json:
            schema:
              required:
                - owner
                - repo
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - github
                owner:
                  type: string
                repo:
                  type: string
                installationId:
                  description: GitHub App installation id; required unless public
                  type: integer
                repoId:
                  description: GitHub repository id; required unless public
                  type: integer
                public:
                  description: >-
                    a public repo, connected without an App installation:
                    one-shot deploys, auto_deploy is always false
                  type: boolean
                branch:
                  description: 'the repo branch to track; default: the repo’s default branch'
                  type: string
                rootDir:
                  description: >-
                    subdirectory to build from (monorepo); relative, no leading
                    / or ..; null/omitted = repo root. It also decides which
                    pushes deploy this service: the build context is this
                    directory, so a push that changed nothing under it is
                    skipped
                  anyOf:
                    - type: string
                    - type: 'null'
                autoDeploy:
                  description: >-
                    rebuild on every push to `branch` (default true; must be
                    false or omitted for a public repo)
                  type: boolean
                buildCommand:
                  anyOf:
                    - type: string
                    - type: 'null'
                startCommand:
                  anyOf:
                    - type: string
                    - type: 'null'
                watchPaths:
                  description: >-
                    An include list of gitignore patterns, matched against paths
                    RELATIVE TO THE REPOSITORY ROOT rather than to `rootDir` —
                    e.g. ["apps/web/**", "packages/ui/**"]. A push deploys this
                    service only when it changed a matching path; omit or null
                    to fall back to the root-directory rule (a service with
                    `rootDir` deploys when a push changed something under it,
                    one building from the repo root deploys on every push). `!`
                    narrows the list under git's own rule that a path cannot be
                    re-included once an earlier pattern took its directory, so
                    ["apps/web/**", "!**/*.md"] drops apps/web/README.md but not
                    apps/web/docs/guide.md. Inert on a public repo, which cannot
                    auto-deploy at all
                  anyOf:
                    - type: array
                      items:
                        type: string
                    - type: 'null'
                port:
                  description: the port the app listens on; written to the service
                  anyOf:
                    - minimum: 1
                      maximum: 65535
                      type: integer
                    - type: 'null'
        required: true
      responses:
        '200':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  source:
                    $ref: '#/components/schemas/ServiceSource'
                  build:
                    type: object
                    properties:
                      buildId:
                        format: uuid
                        type: string
                      queued:
                        description: false when this commit already has a build (dedup)
                        type: boolean
                      serviceId:
                        format: uuid
                        type: string
                    required:
                      - buildId
                      - queued
                      - serviceId
                required:
                  - source
                  - build
        '202':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  approvalId:
                    type: string
                  action:
                    type: string
                  actions:
                    type: array
                    items:
                      type: string
                  message:
                    type: string
                  url:
                    type: string
                required:
                  - status
                  - approvalId
                  - action
                  - actions
                  - message
                  - url
        '400':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
        '404':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ServiceSource:
      description: >-
        Where a compute service’s running image comes from: an image somebody
        deployed (type=image, the absence of a connected source) or a connected
        repository (type=github).
      type: object
      properties:
        type:
          type: string
          enum:
            - image
            - github
        image:
          description: >-
            type=image — the image the service runs; null when nothing has been
            deployed yet
          type:
            - string
            - 'null'
        id:
          format: uuid
          type: string
        owner:
          type: string
        repo:
          type: string
        branch:
          description: >-
            the repo branch this service tracks; defaults to the repo’s default
            branch
          type: string
        root_dir:
          description: >-
            subdirectory to build from (monorepo); null = repo root. Also
            decides which pushes deploy this service: the build context is this
            directory, so a push that changed nothing under it is skipped
          type:
            - string
            - 'null'
        watch_paths:
          description: >-
            include list of gitignore patterns, matched against paths relative
            to the repository root (not to root_dir); a push deploys this
            service only when it changed a matching path. null/absent falls back
            to the root-directory rule: a service with root_dir deploys when a
            push changed something under it, one building from the repo root
            deploys on every push
          type:
            - array
            - 'null'
          items:
            type: string
        auto_deploy:
          description: >-
            a push to `branch` rebuilds and redeploys; always false for a public
            repo (no App, no webhooks)
          type: boolean
        public:
          description: connected as a public repo, without a GitHub App installation
          type: boolean
        installation_id:
          format: uuid
          type:
            - string
            - 'null'
        repo_id:
          description: GitHub repository id (bigint as string)
          type:
            - string
            - 'null'
        build_command:
          description: >-
            custom build command for source builds without a Dockerfile; null
            uses automatic detection
          type:
            - string
            - 'null'
        start_command:
          type:
            - string
            - 'null'
        created_at:
          format: date-time
          type: string
        updated_at:
          format: date-time
          type: string
        last_build:
          anyOf:
            - allOf:
                - $ref: '#/components/schemas/ServiceBuild'
            - type: 'null'
          description: the newest build of this service (null before the first)
      required:
        - type
    Error:
      type: object
      properties:
        error:
          type: string
      required:
        - error
    ServiceBuild:
      description: >-
        One build → image → deploy attempt of a service source (one per commit
        per source).
      type: object
      properties:
        id:
          format: uuid
          type: string
        source_id:
          format: uuid
          description: >-
            the service source that queued it; null once that source was
            disconnected
          type:
            - string
            - 'null'
        repo_binding_id:
          format: uuid
          description: >-
            DEPRECATED — set only on builds queued before sources existed; null
            for every new build
          type:
            - string
            - 'null'
        project_id:
          format: uuid
          type: string
        service_id:
          format: uuid
          type:
            - string
            - 'null'
        branch_id:
          format: uuid
          type:
            - string
            - 'null'
        commit_sha:
          type: string
        status:
          type: string
          enum:
            - queued
            - fetching
            - building
            - deploying
            - live
            - failed
        image_ref:
          type:
            - string
            - 'null'
        error:
          type:
            - string
            - 'null'
        created_at:
          format: date-time
          type: string
        updated_at:
          format: date-time
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Session access JWT or an API token (`insta_<prefix>_<secret>`).

````